aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2008-04-15 22:42:06 +0000
committerSteve Naroff <snaroff@apple.com>2008-04-15 22:42:06 +0000
commit248a753f6b670692523c99afaeb8fe98f7ae3ca7 (patch)
treef51ae4f62f1bdefaf28f672616ec7eaf4ff67f9a
parent4b0f81323b518429203051bbcd4864bbf4b000a9 (diff)
Remove FileVarDecl and BlockVarDecl. They are replaced by VarDecl::isBlockVarDecl() and VarDecl::isFileVarDecl().
This is a fairly mechanical/large change. As a result, I avoided making any changes/simplifications that weren't directly related. I did break two Analysis tests. I also have a couple FIXME's in UninitializedValues.cpp. Ted, can you take a look? If the bug isn't obvious, I am happy to dig in and fix it (since I broke it). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49748 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Driver/RewriteObjC.cpp10
-rw-r--r--include/clang/AST/Decl.h80
-rw-r--r--include/clang/AST/DeclBase.h9
-rw-r--r--include/clang/Analysis/Analyses/UninitializedValues.h2
-rw-r--r--include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h5
-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
21 files changed, 165 insertions, 217 deletions
diff --git a/Driver/RewriteObjC.cpp b/Driver/RewriteObjC.cpp
index a1c29faccc..724b16e49a 100644
--- a/Driver/RewriteObjC.cpp
+++ b/Driver/RewriteObjC.cpp
@@ -70,7 +70,7 @@ namespace {
FunctionDecl *SuperContructorFunctionDecl;
// ObjC string constant support.
- FileVarDecl *ConstantStringClassReference;
+ VarDecl *ConstantStringClassReference;
RecordDecl *NSStringRecord;
// ObjC foreach break/continue generation support.
@@ -367,7 +367,7 @@ void RewriteObjC::HandleTopLevelDecl(Decl *D) {
// Look for built-in declarations that we need to refer during the rewrite.
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
RewriteFunctionDecl(FD);
- } else if (FileVarDecl *FVD = dyn_cast<FileVarDecl>(D)) {
+ } else if (VarDecl *FVD = dyn_cast<VarDecl>(D)) {
// declared in <Foundation/NSString.h>
if (strcmp(FVD->getName(), "_NSConstantStringClassReference") == 0) {
ConstantStringClassReference = FVD;
@@ -1776,9 +1776,9 @@ Stmt *RewriteObjC::RewriteObjCStringLiteral(ObjCStringLiteral *Exp) {
// The minus 2 removes the begin/end double quotes.
Preamble += utostr(prettyBuf.str().size()-2) + "};\n";
- FileVarDecl *NewVD = FileVarDecl::Create(*Context, NULL, SourceLocation(),
- &Context->Idents.get(S.c_str()), strType,
- VarDecl::Static, NULL);
+ VarDecl *NewVD = VarDecl::Create(*Context, NULL, SourceLocation(),
+ &Context->Idents.get(S.c_str()), strType,
+ VarDecl::Static, NULL);
DeclRefExpr *DRE = new DeclRefExpr(NewVD, strType, SourceLocation());
Expr *Unop = new UnaryOperator(DRE, UnaryOperator::AddrOf,
Context->getPointerType(DRE->getType()),
diff --git a/include/clang/AST/Decl.h b/include/clang/AST/Decl.h
index 8ce0be561f..890eb88d65 100644
--- a/include/clang/AST/Decl.h
+++ b/include/clang/AST/Decl.h
@@ -146,6 +146,10 @@ protected:
StorageClass SC, ScopedDecl *PrevDecl)
: ValueDecl(DK, CD, L, Id, T, PrevDecl), Init(0) { SClass = SC; }
public:
+ static VarDecl *Create(ASTContext &C, DeclContext *CD,
+ SourceLocation L, IdentifierInfo *Id,
+ QualType T, StorageClass S, ScopedDecl *PrevDecl);
+
StorageClass getStorageClass() const { return (StorageClass)SClass; }
const Expr *getInit() const { return Init; }
@@ -156,7 +160,7 @@ public:
/// is a non-static local variable.
bool hasLocalStorage() const {
if (getStorageClass() == None)
- return getKind() != FileVar;
+ return !isFileVarDecl();
// Return true for: Auto, Register.
// Return false for: Extern, Static, PrivateExtern.
@@ -168,6 +172,29 @@ public:
/// have local storage. This includs all global variables as well
/// as static variables declared within a function.
bool hasGlobalStorage() const { return !hasLocalStorage(); }
+
+ /// isBlockVarDecl - Returns true for local variable declarations. Note that
+ /// this includes static variables inside of functions.
+ ///
+ /// void foo() { int x; static int y; extern int z; }
+ ///
+ bool isBlockVarDecl() const {
+ if (getKind() != Decl::Var)
+ return false;
+ if (DeclContext *DC = getDeclContext())
+ return DC->isFunctionOrMethod();
+ return false;
+ }
+
+ /// isFileVarDecl - Returns true for file scoped variable declaration.
+ bool isFileVarDecl() const {
+ if (getKind() != Decl::Var)
+ return false;
+ // FIXME: change when TranlationUnitDecl is added as a declaration context.
+ if (!getDeclContext())
+ return true;
+ return false;
+ }
// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) {
@@ -187,56 +214,9 @@ protected:
/// ReadImpl - Deserialize this VarDecl. Called by subclasses.
virtual void ReadImpl(llvm::Deserializer& D, ASTContext& C);
-};
-
-/// BlockVarDecl - Represent a local variable declaration. Note that this
-/// includes static variables inside of functions.
-///
-/// void foo() { int x; static int y; extern int z; }
-///
-class BlockVarDecl : public VarDecl {
- BlockVarDecl(DeclContext *CD, SourceLocation L,
- IdentifierInfo *Id, QualType T, StorageClass S,
- ScopedDecl *PrevDecl)
- : VarDecl(BlockVar, CD, L, Id, T, S, PrevDecl) {}
-public:
- static BlockVarDecl *Create(ASTContext &C, DeclContext *CD, SourceLocation L,
- IdentifierInfo *Id, QualType T, StorageClass S,
- ScopedDecl *PrevDecl);
- // Implement isa/cast/dyncast/etc.
- static bool classof(const Decl *D) { return D->getKind() == BlockVar; }
- static bool classof(const BlockVarDecl *D) { return true; }
-
-protected:
- /// CreateImpl - Deserialize a BlockVarDecl. Called by Decl::Create.
- static BlockVarDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
-
- friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
-};
-
-/// FileVarDecl - Represent a file scoped variable declaration. This
-/// will allow us to reason about external variable declarations and tentative
-/// definitions (C99 6.9.2p2) using our type system (without storing a
-/// pointer to the decl's scope, which is transient).
-class FileVarDecl : public VarDecl {
- FileVarDecl(DeclContext *CD, SourceLocation L,
- IdentifierInfo *Id, QualType T, StorageClass S,
- ScopedDecl *PrevDecl)
- : VarDecl(FileVar, CD, L, Id, T, S, PrevDecl) {}
-public:
- static FileVarDecl *Create(ASTContext &C, DeclContext *CD,
- SourceLocation L, IdentifierInfo *Id,
- QualType T, StorageClass S, ScopedDecl *PrevDecl);
- // Implement isa/cast/dyncast/etc.
- static bool classof(const Decl *D) { return D->getKind() == FileVar; }
- static bool classof(const FileVarDecl *D) { return true; }
-
-protected:
- /// CreateImpl - Deserialize a FileVarDecl. Called by Decl::Create.
- static FileVarDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
-
- friend Decl* Decl::Create(llvm::Deserializer& D, ASTContext& C);
+ /// CreateImpl - Deserialize a VarDecl. Called by Decl::Create.
+ static VarDecl* CreateImpl(llvm::Deserializer& D, ASTContext& C);
};
/// ParmVarDecl - Represent a parameter to a function.
diff --git a/include/clang/AST/DeclBase.h b/include/clang/AST/DeclBase.h
index a5c1cb29ec..3575faaaf5 100644
--- a/include/clang/AST/DeclBase.h
+++ b/include/clang/AST/DeclBase.h
@@ -55,9 +55,7 @@ public:
// ValueDecl
EnumConstant,
Function,
- // VarDecl
- BlockVar,
- FileVar,
+ Var,
ParmVar,
ObjCInterface,
ObjCCompatibleAlias,
@@ -76,7 +74,7 @@ public:
TagFirst = Enum , TagLast = Class,
RecordFirst = Struct , RecordLast = Class,
ValueFirst = EnumConstant , ValueLast = ParmVar,
- VarFirst = BlockVar , VarLast = ParmVar
+ VarFirst = Var , VarLast = ParmVar
};
/// IdentifierNamespace - According to C99 6.2.3, there are four namespaces,
@@ -151,8 +149,7 @@ public:
default: assert(0 && "Unknown decl kind!");
case Typedef:
case Function:
- case BlockVar:
- case FileVar:
+ case Var:
case ParmVar:
case EnumConstant:
case ObjCInterface:
diff --git a/include/clang/Analysis/Analyses/UninitializedValues.h b/include/clang/Analysis/Analyses/UninitializedValues.h
index b2e2dd052c..ea7bd14779 100644
--- a/include/clang/Analysis/Analyses/UninitializedValues.h
+++ b/include/clang/Analysis/Analyses/UninitializedValues.h
@@ -51,7 +51,7 @@ public:
struct ObserverTy {
virtual ~ObserverTy();
virtual void ObserveDeclRefExpr(ValTy& Val, AnalysisDataTy& AD,
- DeclRefExpr* DR, BlockVarDecl* VD) = 0;
+ DeclRefExpr* DR, VarDecl* VD) = 0;
};
};
diff --git a/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h b/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h
index 1ff9a9392b..fab14c38da 100644
--- a/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h
+++ b/include/clang/Analysis/Visitors/CFGRecStmtDeclVisitor.h
@@ -54,8 +54,7 @@ public:
void VisitScopedDecl(ScopedDecl* D) {
switch (D->getKind()) {
DISPATCH_CASE(Function,FunctionDecl)
- DISPATCH_CASE(BlockVar,BlockVarDecl) // FIXME:Refine. VisitVarDecl?
- DISPATCH_CASE(FileVar,FileVarDecl) // FIXME: (same)
+ DISPATCH_CASE(Var,VarDecl)
DISPATCH_CASE(ParmVar,ParmVarDecl) // FIXME: (same)
DISPATCH_CASE(EnumConstant,EnumConstantDecl)
DISPATCH_CASE(Typedef,TypedefDecl)
@@ -70,8 +69,6 @@ public:
DEFAULT_DISPATCH(VarDecl)
DEFAULT_DISPATCH(FunctionDecl)
- DEFAULT_DISPATCH_VARDECL(BlockVarDecl)
- DEFAULT_DISPATCH_VARDECL(FileVarDecl)
DEFAULT_DISPATCH_VARDECL(ParmVarDecl)
DEFAULT_DISPATCH(EnumConstantDecl)
DEFAULT_DISPATCH(TypedefDecl)
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 LangOp