aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/AST/Decl.cpp47
-rw-r--r--lib/AST/DeclSerialization.cpp33
-rw-r--r--lib/AST/StmtDumper.cpp3
-rw-r--r--lib/Analysis/GRExprEngine.cpp2
-rw-r--r--lib/Analysis/UninitializedValues.cpp35
-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
-rw-r--r--lib/Sema/SemaDecl.cpp58
-rw-r--r--lib/Sema/SemaDeclCXX.cpp9
-rw-r--r--lib/Sema/SemaStmt.cpp17
16 files changed, 125 insertions, 151 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index ac1a593e6f..cee7ddad02 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -24,8 +24,7 @@ using namespace clang;
// temporary statistics gathering
static unsigned nFuncs = 0;
-static unsigned nBlockVars = 0;
-static unsigned nFileVars = 0;
+static unsigned nVars = 0;
static unsigned nParmVars = 0;
static unsigned nSUC = 0;
static unsigned nEnumConst = 0;
@@ -59,8 +58,7 @@ const char *Decl::getDeclKindName() const {
default: assert(0 && "Unknown decl kind!");
case Typedef: return "Typedef";
case Function: return "Function";
- case BlockVar: return "BlockVar";
- case FileVar: return "FileVar";
+ case Var: return "Var";
case ParmVar: return "ParmVar";
case EnumConstant: return "EnumConstant";
case ObjCInterface: return "ObjCInterface";
@@ -84,17 +82,14 @@ bool Decl::CollectingStats(bool Enable) {
void Decl::PrintStats() {
fprintf(stderr, "*** Decl Stats:\n");
fprintf(stderr, " %d decls total.\n",
- int(nFuncs+nBlockVars+nFileVars+nParmVars+nFieldDecls+nSUC+
+ int(nFuncs+nVars+nParmVars+nFieldDecls+nSUC+
nEnumDecls+nEnumConst+nTypedef+nInterfaceDecls+nClassDecls+
nMethodDecls+nProtocolDecls+nCategoryDecls+nIvarDecls));
fprintf(stderr, " %d function decls, %d each (%d bytes)\n",
nFuncs, (int)sizeof(FunctionDecl), int(nFuncs*sizeof(FunctionDecl)));
- fprintf(stderr, " %d block variable decls, %d each (%d bytes)\n",
- nBlockVars, (int)sizeof(BlockVarDecl),
- int(nBlockVars*sizeof(BlockVarDecl)));
- fprintf(stderr, " %d file variable decls, %d each (%d bytes)\n",
- nFileVars, (int)sizeof(FileVarDecl),
- int(nFileVars*sizeof(FileVarDecl)));
+ fprintf(stderr, " %d variable decls, %d each (%d bytes)\n",
+ nVars, (int)sizeof(VarDecl),
+ int(nVars*sizeof(VarDecl)));
fprintf(stderr, " %d parameter variable decls, %d each (%d bytes)\n",
nParmVars, (int)sizeof(ParmVarDecl),
int(nParmVars*sizeof(ParmVarDecl)));
@@ -152,8 +147,8 @@ void Decl::PrintStats() {
int(nObjCPropertyDecl*sizeof(ObjCPropertyDecl)));
fprintf(stderr, "Total bytes = %d\n",
- int(nFuncs*sizeof(FunctionDecl)+nBlockVars*sizeof(BlockVarDecl)+
- nFileVars*sizeof(FileVarDecl)+nParmVars*sizeof(ParmVarDecl)+
+ int(nFuncs*sizeof(FunctionDecl)+
+ nVars*sizeof(VarDecl)+nParmVars*sizeof(ParmVarDecl)+
nFieldDecls*sizeof(FieldDecl)+nSUC*sizeof(RecordDecl)+
nEnumDecls*sizeof(EnumDecl)+nEnumConst*sizeof(EnumConstantDecl)+
nTypedef*sizeof(TypedefDecl)+
@@ -177,8 +172,7 @@ void Decl::addDeclKind(Kind k) {
switch (k) {
case Typedef: nTypedef++; break;
case Function: nFuncs++; break;
- case BlockVar: nBlockVars++; break;
- case FileVar: nFileVars++; break;
+ case Var: nVars++; break;
case ParmVar: nParmVars++; break;
case EnumConstant: nEnumConst++; break;
case Field: nFieldDecls++; break;
@@ -204,23 +198,15 @@ void Decl::addDeclKind(Kind k) {
// Decl Allocation/Deallocation Method Implementations
//===----------------------------------------------------------------------===//
-BlockVarDecl *BlockVarDecl::Create(ASTContext &C, DeclContext *CD,
- SourceLocation L,
- IdentifierInfo *Id, QualType T,
- StorageClass S, ScopedDecl *PrevDecl) {
- void *Mem = C.getAllocator().Allocate<BlockVarDecl>();
- return new (Mem) BlockVarDecl(CD, L, Id, T, S, PrevDecl);
+VarDecl *VarDecl::Create(ASTContext &C, DeclContext *CD,
+ SourceLocation L,
+ IdentifierInfo *Id, QualType T,
+ StorageClass S, ScopedDecl *PrevDecl) {
+ void *Mem = C.getAllocator().Allocate<VarDecl>();
+ return new (Mem) VarDecl(Var, CD, L, Id, T, S, PrevDecl);
}
-FileVarDecl *FileVarDecl::Create(ASTContext &C, DeclContext *CD,
- SourceLocation L, IdentifierInfo *Id,
- QualType T, StorageClass S,
- ScopedDecl *PrevDecl) {
- void *Mem = C.getAllocator().Allocate<FileVarDecl>();
- return new (Mem) FileVarDecl(CD, L, Id, T, S, PrevDecl);
-}
-
ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *CD,
SourceLocation L, IdentifierInfo *Id,
QualType T, StorageClass S,
@@ -347,8 +333,7 @@ void Decl::Destroy(ASTContext& C) const {
CASE(Enum);
CASE(EnumConstant);
CASE(Function);
- CASE(BlockVar);
- CASE(FileVar);
+ CASE(Var);
CASE(ParmVar);
CASE(ObjCInterface);
CASE(ObjCCompatibleAlias);
diff --git a/lib/AST/DeclSerialization.cpp b/lib/AST/DeclSerialization.cpp
index 6b0d7f881a..96df1b7fbf 100644
--- a/lib/AST/DeclSerialization.cpp
+++ b/lib/AST/DeclSerialization.cpp
@@ -41,8 +41,8 @@ Decl* Decl::Create(Deserializer& D, ASTContext& C) {
assert (false && "Not implemented.");
break;
- case BlockVar:
- return BlockVarDecl::CreateImpl(D, C);
+ case Var:
+ return VarDecl::CreateImpl(D, C);
case Enum:
return EnumDecl::CreateImpl(D, C);
@@ -53,9 +53,6 @@ Decl* Decl::Create(Deserializer& D, ASTContext& C) {
case Field:
return FieldDecl::CreateImpl(D, C);
- case FileVar:
- return FileVarDecl::CreateImpl(D, C);
-
case ParmVar:
return ParmVarDecl::CreateImpl(D, C);
@@ -195,13 +192,13 @@ void VarDecl::ReadImpl(Deserializer& D, ASTContext& C) {
}
//===----------------------------------------------------------------------===//
-// BlockVarDecl Serialization.
+// VarDecl Serialization.
//===----------------------------------------------------------------------===//
-BlockVarDecl* BlockVarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
- void *Mem = C.getAllocator().Allocate<BlockVarDecl>();
- BlockVarDecl* decl =
- new (Mem) BlockVarDecl(0, SourceLocation(), NULL, QualType(), None, NULL);
+VarDecl* VarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
+ void *Mem = C.getAllocator().Allocate<VarDecl>();
+ VarDecl* decl =
+ new (Mem) VarDecl(Var, 0, SourceLocation(), NULL, QualType(), None, NULL);
decl->VarDecl::ReadImpl(D, C);
@@ -209,21 +206,7 @@ BlockVarDecl* BlockVarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
}
//===----------------------------------------------------------------------===//
-// FileVarDecl Serialization.
-//===----------------------------------------------------------------------===//
-
-FileVarDecl* FileVarDecl::CreateImpl(Deserializer& D, ASTContext& C) {
- void *Mem = C.getAllocator().Allocate<FileVarDecl>();
- FileVarDecl* decl =
- new (Mem) FileVarDecl(0, SourceLocation(), NULL, QualType(), None, NULL);
-
- decl->VarDecl::ReadImpl(D, C);
-
- return decl;
-}
-
-//===----------------------------------------------------------------------===//
-// ParmDecl Serialization.
+// ParmVarDecl Serialization.
//===----------------------------------------------------------------------===//
void ParmVarDecl::EmitImpl(llvm::Serializer& S) const {
diff --git a/lib/AST/StmtDumper.cpp b/lib/AST/StmtDumper.cpp
index dd7e2b320d..2d4adf8938 100644
--- a/lib/AST/StmtDumper.cpp
+++ b/lib/AST/StmtDumper.cpp
@@ -280,8 +280,7 @@ void StmtDumper::VisitDeclRefExpr(DeclRefExpr *Node) {
fprintf(F, " ");
switch (Node->getDecl()->getKind()) {
case Decl::Function: fprintf(F,"FunctionDecl"); break;
- case Decl::BlockVar: fprintf(F,"BlockVar"); break;
- case Decl::FileVar: fprintf(F,"FileVar"); break;
+ case Decl::Var: fprintf(F,"Var"); break;
case Decl::ParmVar: fprintf(F,"ParmVar"); break;
case Decl::EnumConstant: fprintf(F,"EnumConstant"); break;
case Decl::Typedef: fprintf(F,"Typedef"); break;
diff --git a/lib/Analysis/GRExprEngine.cpp b/lib/Analysis/GRExprEngine.cpp
index 3211da2918..e2cc530330 100644
--- a/lib/Analysis/GRExprEngine.cpp
+++ b/lib/Analysis/GRExprEngine.cpp
@@ -738,7 +738,7 @@ void GRExprEngine::VisitDeclStmt(DeclStmt* DS, GRExprEngine::NodeTy* Pred,
// In this context, Static => Local variable.
assert (!VD->getStorageClass() == VarDecl::Static ||
- !isa<FileVarDecl>(VD));
+ !VD->isFileVarDecl());
// If there is no initializer, set the value of the
// variable to "Undefined".
diff --git a/lib/Analysis/UninitializedValues.cpp b/lib/Analysis/UninitializedValues.cpp
index 2116e505d5..9958166c67 100644
--- a/lib/Analysis/UninitializedValues.cpp
+++ b/lib/Analysis/UninitializedValues.cpp
@@ -36,7 +36,7 @@ class VISIBILITY_HIDDEN RegisterDecls
public:
RegisterDecls(UninitializedValues::AnalysisDataTy& ad) : AD(ad) {}
- void VisitBlockVarDecl(BlockVarDecl* VD) { AD.Register(VD); }
+ void VisitBlockVarDecl(VarDecl* VD) { AD.Register(VD); }
CFG& getCFG() { return AD.getCFG(); }
};
@@ -80,14 +80,16 @@ public:
void VisitTerminator(Stmt* T) { }
- BlockVarDecl* FindBlockVarDecl(Stmt* S);
+ VarDecl* FindBlockVarDecl(Stmt* S);
};
static const bool Initialized = true;
static const bool Uninitialized = false;
bool TransferFuncs::VisitDeclRefExpr(DeclRefExpr* DR) {
- if (BlockVarDecl* VD = dyn_cast<BlockVarDecl>(DR->getDecl())) {
+ // FIXME: Ted, can this be simplified?
+ VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl());
+ if (VD && VD->isBlockVarDecl()) {
if (AD.Observer) AD.Observer->ObserveDeclRefExpr(V,AD,DR,VD);
// Pseudo-hack to prevent cascade of warnings. If an accessed variable
@@ -101,13 +103,15 @@ bool TransferFuncs::VisitDeclRefExpr(DeclRefExpr* DR) {
else return Initialized;
}
-BlockVarDecl* TransferFuncs::FindBlockVarDecl(Stmt *S) {
+VarDecl* TransferFuncs::FindBlockVarDecl(Stmt *S) {
for (;;)
if (ParenExpr* P = dyn_cast<ParenExpr>(S)) {
S = P->getSubExpr(); continue;
}
else if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(S)) {
- if (BlockVarDecl* VD = dyn_cast<BlockVarDecl>(DR->getDecl()))
+ // FIXME: Ted, can this be simplified?
+ VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl());
+ if (VD->isBlockVarDecl())
return VD;
else
return NULL;
@@ -116,7 +120,9 @@ BlockVarDecl* TransferFuncs::FindBlockVarDecl(Stmt *S) {
}
bool TransferFuncs::VisitBinaryOperator(BinaryOperator* B) {
- if (BlockVarDecl* VD = FindBlockVarDecl(B->getLHS()))
+ // FIXME: Ted, can this be simplified?
+ VarDecl* VD = FindBlockVarDecl(B->getLHS());
+ if (VD && VD->isBlockVarDecl())
if (B->isAssignmentOp()) {
if (B->getOpcode() == BinaryOperator::Assign)
return V(VD,AD) = Visit(B->getRHS());
@@ -128,8 +134,9 @@ bool TransferFuncs::VisitBinaryOperator(BinaryOperator* B) {
}
bool TransferFuncs::VisitDeclStmt(DeclStmt* S) {
- for (ScopedDecl* D = S->getDecl(); D != NULL; D = D->getNextDeclarator())
- if (BlockVarDecl* VD = dyn_cast<BlockVarDecl>(D)) {
+ for (ScopedDecl* D = S->getDecl(); D != NULL; D = D->getNextDeclarator()) {
+ VarDecl *VD = dyn_cast<VarDecl>(D);
+ if (VD && VD->isBlockVarDecl()) {
if (Stmt* I = VD->getInit())
V(VD,AD) = AD.FullUninitTaint ? V(cast<Expr>(I),AD) : Initialized;
else {
@@ -149,10 +156,10 @@ bool TransferFuncs::VisitDeclStmt(DeclStmt* S) {
V(VD,AD) = Uninitialized;
}
}
-
+ }
return Uninitialized; // Value is never consumed.
}
-
+
bool TransferFuncs::VisitCallExpr(CallExpr* C) {
VisitChildren(C);
return Initialized;
@@ -161,9 +168,9 @@ bool TransferFuncs::VisitCallExpr(CallExpr* C) {
bool TransferFuncs::VisitUnaryOperator(UnaryOperator* U) {
switch (U->getOpcode()) {
case UnaryOperator::AddrOf:
- if (BlockVarDecl* VD = FindBlockVarDecl(U->getSubExpr()))
+ VarDecl* VD = FindBlockVarDecl(U->getSubExpr());
+ if (VD && VD->isBlockVarDecl())
return V(VD,AD) = Initialized;
-
break;
case UnaryOperator::SizeOf:
@@ -240,7 +247,7 @@ class VISIBILITY_HIDDEN UninitializedValuesChecker
ASTContext &Ctx;
Diagnostic &Diags;
- llvm::SmallPtrSet<BlockVarDecl*,10> AlreadyWarned;
+ llvm::SmallPtrSet<VarDecl*,10> AlreadyWarned;
public:
UninitializedValuesChecker(ASTContext &ctx, Diagnostic &diags)
@@ -248,7 +255,7 @@ public:
virtual void ObserveDeclRefExpr(UninitializedValues::ValTy& V,
UninitializedValues::AnalysisDataTy& AD,
- DeclRefExpr* DR, BlockVarDecl* VD) {
+ DeclRefExpr* DR, VarDecl* VD) {
assert ( AD.isTracked(VD) && "Unknown VarDecl.");
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)){
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 328741ec0f..6d41fce555 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -372,26 +372,23 @@ VarDecl *Sema::MergeVarDecl(VarDecl *New, Decl *OldD) {
return New;
}
// We've verified the types match, now handle "tentative" definitions.
- FileVarDecl *OldFSDecl = dyn_cast<FileVarDecl>(Old);
- FileVarDecl *NewFSDecl = dyn_cast<FileVarDecl>(New);
-
- if (OldFSDecl && NewFSDecl) {
+ if (Old->isFileVarDecl() && New->isFileVarDecl()) {
// Handle C "tentative" external object definitions (C99 6.9.2).
bool OldIsTentative = false;
bool NewIsTentative = false;
- if (!OldFSDecl->getInit() &&
- (OldFSDecl->getStorageClass() == VarDecl::None ||
- OldFSDecl->getStorageClass() == VarDecl::Static))
+ if (!Old->getInit() &&
+ (Old->getStorageClass() == VarDecl::None ||
+ Old->getStorageClass() == VarDecl::Static))
OldIsTentative = true;
// FIXME: this check doesn't work (since the initializer hasn't been
// attached yet). This check should be moved to FinalizeDeclaratorGroup.
// Unfortunately, by the time we get to FinializeDeclaratorGroup, we've
// thrown out the old decl.
- if (!NewFSDecl->getInit() &&
- (NewFSDecl->getStorageClass() == VarDecl::None ||
- NewFSDecl->getStorageClass() == VarDecl::Static))
+ if (!New->getInit() &&
+ (New->getStorageClass() == VarDecl::None ||
+ New->getStorageClass() == VarDecl::Static))
; // change to NewIsTentative = true; once the code is moved.
if (NewIsTentative || OldIsTentative)
@@ -880,13 +877,11 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl) {
R.getAsString());
InvalidDecl = true;
}
- NewVD = FileVarDecl::Create(Context, CurContext, D.getIdentifierLoc(),
- II, R, SC,
- LastDeclarator);
+ NewVD = VarDecl::Create(Context, CurContext, D.getIdentifierLoc(),
+ II, R, SC, LastDeclarator);
} else {
- NewVD = BlockVarDecl::Create(Context, CurContext, D.getIdentifierLoc(),
- II, R, SC,
- LastDeclarator);
+ NewVD = VarDecl::Create(Context, CurContext, D.getIdentifierLoc(),
+ II, R, SC, LastDeclarator);
}
// Handle attributes prior to checking for duplicates in MergeVarDecl
HandleDeclAttributes(NewVD, D.getDeclSpec().getAttributes(),
@@ -952,23 +947,23 @@ void Sema::AddInitializerToDecl(DeclTy *dcl, ExprTy *init) {
// Get the decls type and save a reference for later, since
// CheckInitializerTypes may change it.
QualType DclT = VDecl->getType(), SavT = DclT;
- if (BlockVarDecl *BVD = dyn_cast<BlockVarDecl>(VDecl)) {
- VarDecl::StorageClass SC = BVD->getStorageClass();
+ if (VDecl->isBlockVarDecl()) {
+ VarDecl::StorageClass SC = VDecl->getStorageClass();
if (SC == VarDecl::Extern) { // C99 6.7.8p5
Diag(VDecl->getLocation(), diag::err_block_extern_cant_init);
- BVD->setInvalidDecl();
- } else if (!BVD->isInvalidDecl()) {
+ VDecl->setInvalidDecl();
+ } else if (!VDecl->isInvalidDecl()) {
if (CheckInitializerTypes(Init, DclT))
- BVD->setInvalidDecl();
+ VDecl->setInvalidDecl();
if (SC == VarDecl::Static) // C99 6.7.8p4.
CheckForConstantInitializer(Init, DclT);
}
- } else if (FileVarDecl *FVD = dyn_cast<FileVarDecl>(VDecl)) {
- if (FVD->getStorageClass() == VarDecl::Extern)
+ } else if (VDecl->isFileVarDecl()) {
+ if (VDecl->getStorageClass() == VarDecl::Extern)
Diag(VDecl->getLocation(), diag::warn_extern_init);
- if (!FVD->isInvalidDecl())
+ if (!VDecl->isInvalidDecl())
if (CheckInitializerTypes(Init, DclT))
- FVD->setInvalidDecl();
+ VDecl->setInvalidDecl();
// C99 6.7.8p4. All file scoped initializers need to be constant.
CheckForConstantInitializer(Init, DclT);
@@ -1012,13 +1007,12 @@ Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) {
VarDecl *IDecl = dyn_cast<VarDecl>(ID);
if (!IDecl)
continue;
- FileVarDecl *FVD = dyn_cast<FileVarDecl>(IDecl);
- BlockVarDecl *BVD = dyn_cast<BlockVarDecl>(IDecl);
QualType T = IDecl->getType();
// C99 6.7.5.2p2: If an identifier is declared to be an object with
// static storage duration, it shall not have a variable length array.
- if ((FVD || BVD) && IDecl->getStorageClass() == VarDecl::Static) {
+ if ((IDecl->isFileVarDecl() || IDecl->isBlockVarDecl()) &&
+ IDecl->getStorageClass() == VarDecl::Static) {
if (T->getAsVariableArrayType()) {
Diag(IDecl->getLocation(), diag::err_typecheck_illegal_vla);
IDecl->setInvalidDecl();
@@ -1026,7 +1020,8 @@ Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) {
}
// Block scope. C99 6.7p7: If an identifier for an object is declared with
// no linkage (C99 6.2.2p6), the type for the object shall be complete...
- if (BVD && IDecl->getStorageClass() != VarDecl::Extern) {
+ if (IDecl->isBlockVarDecl() &&
+ IDecl->getStorageClass() != VarDecl::Extern) {
if (T->isIncompleteType() && !IDecl->isInvalidDecl()) {
Diag(IDecl->getLocation(), diag::err_typecheck_decl_incomplete_type,
T.getAsString());
@@ -1038,8 +1033,9 @@ Sema::DeclTy *Sema::FinalizeDeclaratorGroup(Scope *S, DeclTy *group) {
// storage-class specifier or with the storage-class specifier "static",
// constitutes a tentative definition. Note: A tentative definition with
// external linkage is valid (C99 6.2.2p5).
- if (FVD && !FVD->getInit() && (FVD->getStorageClass() == VarDecl::Static ||
- FVD->getStorageClass() == VarDecl::None)) {
+ if (IDecl && !IDecl->getInit() &&
+ (IDecl->getStorageClass() == VarDecl::Static ||
+ IDecl->getStorageClass() == VarDecl::None)) {
if (T->isIncompleteArrayType()) {
// C99 6.9.2 (p2, p5): Implicit initialization causes an incomplete
// array to be completed. Don't issue a diagnostic.
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 7202d2f2f1..251fb5e72b 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -74,13 +74,14 @@ namespace {
return S->Diag(DRE->getSourceRange().getBegin(),
diag::err_param_default_argument_references_param,
Param->getName(), DefaultArg->getSourceRange());
- } else if (BlockVarDecl *BlockVar = dyn_cast<BlockVarDecl>(Decl)) {
+ } else if (VarDecl *VDecl = dyn_cast<VarDecl>(Decl)) {
// C++ [dcl.fct.default]p7
// Local variables shall not be used in default argument
// expressions.
- return S->Diag(DRE->getSourceRange().getBegin(),
- diag::err_param_default_argument_references_local,
- BlockVar->getName(), DefaultArg->getSourceRange());
+ if (VDecl->isBlockVarDecl())
+ return S->Diag(DRE->getSourceRange().getBegin(),
+ diag::err_param_default_argument_references_local,
+ VDecl->getName(), DefaultArg->getSourceRange());
}
// FIXME: when Clang has support for member functions, "this"
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 14b2fdf7d0..d8f213a973 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -521,10 +521,10 @@ Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
// C99 6.8.5p3: The declaration part of a 'for' statement shall only declare
// identifiers for objects having storage class 'auto' or 'register'.
for (ScopedDecl *D = DS->getDecl(); D; D = D->getNextDeclarator()) {
- BlockVarDecl *BVD = dyn_cast<BlockVarDecl>(D);
- if (BVD && !BVD->hasLocalStorage())
- BVD = 0;
- if (BVD == 0)
+ VarDecl *VD = dyn_cast<VarDecl>(D);
+ if (VD && VD->isBlockVarDecl() && !VD->hasLocalStorage())
+ VD = 0;
+ if (VD == 0)
Diag(dyn_cast<ScopedDecl>(D)->getLocation(),
diag::err_non_variable_decl_in_for);
// FIXME: mark decl erroneous!
@@ -556,13 +556,12 @@ Sema::ActOnObjCForCollectionStmt(SourceLocation ForLoc,
// C99 6.8.5p3: The declaration part of a 'for' statement shall only declare
// identifiers for objects having storage class 'auto' or 'register'.
ScopedDecl *D = DS->getDecl();
- BlockVarDecl *BVD = cast<BlockVarDecl>(D);
- if (!BVD->hasLocalStorage())
- return Diag(BVD->getLocation(), diag::err_non_variable_decl_in_for);
+ VarDecl *VD = cast<VarDecl>(D);
+ if (VD->isBlockVarDecl() && !VD->hasLocalStorage())
+ return Diag(VD->getLocation(), diag::err_non_variable_decl_in_for);
if (D->getNextDeclarator())
return Diag(D->getLocation(), diag::err_toomany_element_decls);
- }
- else
+ } else
FirstType = static_cast<Expr*>(first)->getType();
if (!isObjCObjectPointerType(FirstType))
Diag(ForLoc, diag::err_selector_element_type,