aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2010-11-30 23:07:14 +0000
committerFariborz Jahanian <fjahanian@apple.com>2010-11-30 23:07:14 +0000
commitfaa5bfcaaf6fc5a21ae112919d368f2636c58768 (patch)
tree1841292232f107a7a888b00eb746b438bdb1df10 /lib/CodeGen
parent26e10bea3d2e9d2979194890e51b98ecea165a96 (diff)
Declaring local static in global block
literal declaration caused crash in CodeGen. This patch fixes it. pr8707 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120486 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CGDecl.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp
index 1a129e7536..7aeacafce4 100644
--- a/lib/CodeGen/CGDecl.cpp
+++ b/lib/CodeGen/CGDecl.cpp
@@ -145,14 +145,24 @@ static std::string GetStaticDeclName(CodeGenFunction &CGF, const VarDecl &D,
}
std::string ContextName;
- if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CGF.CurFuncDecl)) {
+ if (!CGF.CurFuncDecl) {
+ // Better be in a block declared in global scope.
+ const NamedDecl *ND = cast<NamedDecl>(&D);
+ const DeclContext *DC = ND->getDeclContext();
+ if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) {
+ MangleBuffer Name;
+ CGM.getMangledName(GlobalDecl(), Name, BD);
+ ContextName = Name.getString();
+ }
+ else
+ assert(0 && "Unknown context for block static var decl");
+ } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(CGF.CurFuncDecl)) {
llvm::StringRef Name = CGM.getMangledName(FD);
ContextName = Name.str();
} else if (isa<ObjCMethodDecl>(CGF.CurFuncDecl))
ContextName = CGF.CurFn->getName();
else
- // FIXME: What about in a block??
- assert(0 && "Unknown context for block var decl");
+ assert(0 && "Unknown context for static var decl");
return ContextName + Separator + D.getNameAsString();
}