diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2010-11-30 23:07:14 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2010-11-30 23:07:14 +0000 |
commit | 3a4ea9a76ccb85c343427118fa1c457bd105b3ee (patch) | |
tree | f09e28b92760c35ef2bc53067dc6166507ae110d /clang/lib/CodeGen/CGDecl.cpp | |
parent | c0f3379ae06f37f090ab55e31e8a876dd69cd1ba (diff) | |
download | bcm5719-llvm-3a4ea9a76ccb85c343427118fa1c457bd105b3ee.tar.gz bcm5719-llvm-3a4ea9a76ccb85c343427118fa1c457bd105b3ee.zip |
Declaring local static in global block
literal declaration caused crash in CodeGen.
This patch fixes it. pr8707
llvm-svn: 120486
Diffstat (limited to 'clang/lib/CodeGen/CGDecl.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGDecl.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 1a129e75368..7aeacafce44 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/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(); } |