diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2008-05-27 04:58:01 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2008-05-27 04:58:01 +0000 |
commit | 078c963a310048f84d1d74d7ed09fd610238d87a (patch) | |
tree | 68c195e01ecc9cad6d65efe607eb01adc007c07c /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 698e72ec2ce2e0d006b467855f3532f2d09235c3 (diff) | |
download | bcm5719-llvm-078c963a310048f84d1d74d7ed09fd610238d87a.tar.gz bcm5719-llvm-078c963a310048f84d1d74d7ed09fd610238d87a.zip |
Add a more reliable check for whether a static declaration has already
been used. In preparation for the fix to PR2360, but also a minor bug
in its own right.
llvm-svn: 51583
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 329599c1166..f14a0858d30 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -341,19 +341,6 @@ void CodeGenModule::EmitFunction(const FunctionDecl *FD) { CodeGenFunction(*this).GenerateCode(FD); return; } - - // We need to check the Module here to see if GetAddrOfFunctionDecl() has - // already added this function to the Module because the address of the - // function's prototype was taken. If this is the case, call - // GetAddrOfFunctionDecl to insert the static FunctionDecl into the used - // GlobalDeclsMap, so that EmitStatics will generate code for it later. - // - // Example: - // static int foo(); - // int bar() { return foo(); } - // static int foo() { return 5; } - if (getModule().getFunction(FD->getName())) - GetAddrOfFunctionDecl(FD, true); StaticDecls.push_back(FD); } @@ -366,11 +353,19 @@ void CodeGenModule::EmitStatics() { do { Changed = false; for (unsigned i = 0, e = StaticDecls.size(); i != e; ++i) { - // Check the map of used decls for our static. If not found, continue. const Decl *D = StaticDecls[i]; - if (!GlobalDeclMap.count(D)) - continue; - + + // Check if we have used a decl with the same name + // FIXME: The AST should have some sort of aggregate decls or + // global symbol map. + if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) { + if (!getModule().getFunction(FD->getName())) + continue; + } else { + if (!getModule().getNamedGlobal(cast<VarDecl>(D)->getName())) + continue; + } + // If this is a function decl, generate code for the static function if it // has a body. Otherwise, we must have a var decl for a static global // variable. |