aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CGDecl.cpp15
-rw-r--r--lib/CodeGen/CGExpr.cpp14
-rw-r--r--lib/CodeGen/CGExprConstant.cpp12
-rw-r--r--lib/CodeGen/CodeGenFunction.cpp2
-rw-r--r--lib/CodeGen/CodeGenFunction.h10
-rw-r--r--lib/CodeGen/CodeGenModule.cpp9
-rw-r--r--lib/CodeGen/CodeGenModule.h5
-rw-r--r--lib/CodeGen/ModuleBuilder.cpp5
8 files changed, 38 insertions, 34 deletions
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp
index 8255c12f01..e186bb69eb 100644
--- a/lib/CodeGen/CGDecl.cpp
+++ b/lib/CodeGen/CGDecl.cpp
@@ -23,8 +23,6 @@ using namespace CodeGen;
void CodeGenFunction::EmitDecl(const Decl &D) {
switch (D.getKind()) {
default: assert(0 && "Unknown decl kind!");
- case Decl::FileVar:
- assert(0 && "Should not see file-scope variables inside a function!");
case Decl::ParmVar:
assert(0 && "Parmdecls should not be in declstmts!");
case Decl::Typedef: // typedef int X;
@@ -36,8 +34,11 @@ void CodeGenFunction::EmitDecl(const Decl &D) {
// None of these decls require codegen support.
return;
- case Decl::BlockVar:
- return EmitBlockVarDecl(cast<BlockVarDecl>(D));
+ case Decl::Var:
+ if (cast<VarDecl>(D).isBlockVarDecl())
+ return EmitBlockVarDecl(cast<VarDecl>(D));
+ assert(0 && "Should not see file-scope variables inside a function!");
+
case Decl::EnumConstant:
return EmitEnumConstantDecl(cast<EnumConstantDecl>(D));
}
@@ -49,7 +50,7 @@ void CodeGenFunction::EmitEnumConstantDecl(const EnumConstantDecl &D) {
/// EmitBlockVarDecl - This method handles emission of any variable declaration
/// inside a function, including static vars etc.
-void CodeGenFunction::EmitBlockVarDecl(const BlockVarDecl &D) {
+void CodeGenFunction::EmitBlockVarDecl(const VarDecl &D) {
switch (D.getStorageClass()) {
case VarDecl::Static:
return EmitStaticBlockVarDecl(D);
@@ -65,7 +66,7 @@ void CodeGenFunction::EmitBlockVarDecl(const BlockVarDecl &D) {
}
}
-void CodeGenFunction::EmitStaticBlockVarDecl(const BlockVarDecl &D) {
+void CodeGenFunction::EmitStaticBlockVarDecl(const VarDecl &D) {
QualType Ty = D.getType();
assert(Ty->isConstantSizeType() && "VLAs can't be static");
@@ -99,7 +100,7 @@ void CodeGenFunction::EmitStaticBlockVarDecl(const BlockVarDecl &D) {
/// EmitLocalBlockVarDecl - Emit code and set up an entry in LocalDeclMap for a
/// variable declaration with auto, register, or no storage class specifier.
/// These turn into simple stack objects.
-void CodeGenFunction::EmitLocalBlockVarDecl(const BlockVarDecl &D) {
+void CodeGenFunction::EmitLocalBlockVarDecl(const VarDecl &D) {
QualType Ty = D.getType();
llvm::Value *DeclPtr;
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 8175730171..5714f3cde9 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -338,20 +338,20 @@ void CodeGenFunction::EmitStoreThroughOCUComponentLValue(RValue Src, LValue Dst,
LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) {
- const ValueDecl *D = E->getDecl();
- if (isa<BlockVarDecl>(D) || isa<ParmVarDecl>(D)) {
- const VarDecl *VD = cast<VarDecl>(D);
+ const VarDecl *VD = dyn_cast<VarDecl>(E->getDecl());
+
+ if (VD && (VD->isBlockVarDecl() || isa<ParmVarDecl>(VD))) {
if (VD->getStorageClass() == VarDecl::Extern)
return LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD, false));
else {
- llvm::Value *V = LocalDeclMap[D];
+ llvm::Value *V = LocalDeclMap[VD];
assert(V && "BlockVarDecl not entered in LocalDeclMap?");
return LValue::MakeAddr(V);
}
- } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
+ } else if (VD && VD->isFileVarDecl()) {
+ return LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD, false));
+ } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(E->getDecl())) {
return LValue::MakeAddr(CGM.GetAddrOfFunctionDecl(FD, false));
- } else if (const FileVarDecl *FVD = dyn_cast<FileVarDecl>(D)) {
- return LValue::MakeAddr(CGM.GetAddrOfGlobalVar(FVD, false));
}
assert(0 && "Unimp declref");
//an invalid LValue, but the assert will
diff --git a/lib/CodeGen/CGExprConstant.cpp b/lib/CodeGen/CGExprConstant.cpp
index 2ca71c3153..ace494c86a 100644
--- a/lib/CodeGen/CGExprConstant.cpp
+++ b/lib/CodeGen/CGExprConstant.cpp
@@ -541,11 +541,13 @@ public:
ValueDecl *Decl = cast<DeclRefExpr>(E)->getDecl();
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(Decl))
return CGM.GetAddrOfFunctionDecl(FD, false);
- if (const FileVarDecl* VD = dyn_cast<FileVarDecl>(Decl))
- return CGM.GetAddrOfGlobalVar(VD, false);
- if (const BlockVarDecl* BVD = dyn_cast<BlockVarDecl>(Decl)) {
- assert(CGF && "Can't access static local vars without CGF");
- return CGF->GetAddrOfStaticLocalVar(BVD);
+ if (const VarDecl* VD = dyn_cast<VarDecl>(Decl)) {
+ if (VD->isFileVarDecl())
+ return CGM.GetAddrOfGlobalVar(VD, false);
+ else if (VD->isBlockVarDecl()) {
+ assert(CGF && "Can't access static local vars without CGF");
+ return CGF->GetAddrOfStaticLocalVar(VD);
+ }
}
break;
}
diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp
index e1c8d38873..1b94c59561 100644
--- a/lib/CodeGen/CodeGenFunction.cpp
+++ b/lib/CodeGen/CodeGenFunction.cpp
@@ -42,7 +42,7 @@ llvm::BasicBlock *CodeGenFunction::getBasicBlockForLabel(const LabelStmt *S) {
}
llvm::Constant *
-CodeGenFunction::GetAddrOfStaticLocalVar(const BlockVarDecl *BVD) {
+CodeGenFunction::GetAddrOfStaticLocalVar(const VarDecl *BVD) {
return cast<llvm::Constant>(LocalDeclMap[BVD]);
}
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index df2c8b2331..f40a0fad00 100644
--- a/lib/CodeGen/CodeGenFunction.h
+++ b/lib/CodeGen/CodeGenFunction.h
@@ -70,7 +70,7 @@ namespace clang {
class ObjCIvarRefExpr;
class MemberExpr;
- class BlockVarDecl;
+ class VarDecl;
class EnumConstantDecl;
class ParmVarDecl;
class FieldDecl;
@@ -344,16 +344,16 @@ public:
const CGRecordLayout *getCGRecordLayout(CodeGenTypes &CGT, QualType RTy);
/// GetAddrOfStaticLocalVar - Return the address of a static local variable.
- llvm::Constant *GetAddrOfStaticLocalVar(const BlockVarDecl *BVD);
+ llvm::Constant *GetAddrOfStaticLocalVar(const VarDecl *BVD);
//===--------------------------------------------------------------------===//
// Declaration Emission
//===--------------------------------------------------------------------===//
void EmitDecl(const Decl &D);
void EmitEnumConstantDecl(const EnumConstantDecl &D);
- void EmitBlockVarDecl(const BlockVarDecl &D);
- void EmitLocalBlockVarDecl(const BlockVarDecl &D);
- void EmitStaticBlockVarDecl(const BlockVarDecl &D);
+ void EmitBlockVarDecl(const VarDecl &D);
+ void EmitLocalBlockVarDecl(const VarDecl &D);
+ void EmitStaticBlockVarDecl(const VarDecl &D);
void EmitParmDecl(const ParmVarDecl &D, llvm::Value *Arg);
//===--------------------------------------------------------------------===//
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 83f661f012..cb34fb5a73 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -288,7 +288,7 @@ llvm::Constant *CodeGenModule::EmitGlobalInit(const Expr *Expr) {
return EmitConstantExpr(Expr);
}
-void CodeGenModule::EmitGlobalVar(const FileVarDecl *D) {
+void CodeGenModule::EmitGlobalVar(const VarDecl *D) {
// If this is just a forward declaration of the variable, don't emit it now,
// allow it to be emitted lazily on its first use.
if (D->getStorageClass() == VarDecl::Extern && D->getInit() == 0)
@@ -352,9 +352,10 @@ void CodeGenModule::EmitGlobalVar(const FileVarDecl *D) {
/// EmitGlobalVarDeclarator - Emit all the global vars attached to the specified
/// declarator chain.
-void CodeGenModule::EmitGlobalVarDeclarator(const FileVarDecl *D) {
- for (; D; D = cast_or_null<FileVarDecl>(D->getNextDeclarator()))
- EmitGlobalVar(D);
+void CodeGenModule::EmitGlobalVarDeclarator(const VarDecl *D) {
+ for (; D; D = cast_or_null<VarDecl>(D->getNextDeclarator()))
+ if (D->isFileVarDecl())
+ EmitGlobalVar(D);
}
void CodeGenModule::UpdateCompletedType(const TagDecl *TD) {
diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h
index 553b366776..3fcb56e3c4 100644
--- a/lib/CodeGen/CodeGenModule.h
+++ b/lib/CodeGen/CodeGenModule.h
@@ -37,7 +37,6 @@ namespace clang {
class ValueDecl;
class VarDecl;
class TypeDecl;
- class FileVarDecl;
struct LangOptions;
class Diagnostic;
@@ -103,8 +102,8 @@ public:
void EmitObjCMethod(const ObjCMethodDecl *OMD);
void EmitFunction(const FunctionDecl *FD);
- void EmitGlobalVar(const FileVarDecl *D);
- void EmitGlobalVarDeclarator(const FileVarDecl *D);
+ void EmitGlobalVar(const VarDecl *D);
+ void EmitGlobalVarDeclarator(const VarDecl *D);
void UpdateCompletedType(const TagDecl *D);
llvm::Constant *EmitGlobalInit(const Expr *E);
llvm::Constant *EmitConstantExpr(const Expr *E, CodeGenFunction *CGF = 0);
diff --git a/lib/CodeGen/ModuleBuilder.cpp b/lib/CodeGen/ModuleBuilder.cpp
index 5710d8bf98..53ee2e4551 100644
--- a/lib/CodeGen/ModuleBuilder.cpp
+++ b/lib/CodeGen/ModuleBuilder.cpp
@@ -63,8 +63,9 @@ namespace {
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
Builder->EmitFunction(FD);
- } else if (FileVarDecl *FVD = dyn_cast<FileVarDecl>(D)) {
- Builder->EmitGlobalVarDeclarator(FVD);
+ } else if (VarDecl *VD = dyn_cast<VarDecl>(D)) {
+ if (VD->isFileVarDecl())
+ Builder->EmitGlobalVarDeclarator(VD);
} else if (isa<ObjCClassDecl>(D) || isa<ObjCCategoryDecl>(D)) {
// Forward declaration. Only used for type checking.
} else if (ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)){