[cfe-commits] r51583 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGen/static-forward-decl.c
Eli Friedman
eli.friedman at gmail.com
Mon May 26 21:58:01 PDT 2008
Author: efriedma
Date: Mon May 26 23:58:01 2008
New Revision: 51583
URL: http://llvm.org/viewvc/llvm-project?rev=51583&view=rev
Log:
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.
Added:
cfe/trunk/test/CodeGen/static-forward-decl.c
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=51583&r1=51582&r2=51583&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon May 26 23:58:01 2008
@@ -341,19 +341,6 @@
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 @@
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.
Added: cfe/trunk/test/CodeGen/static-forward-decl.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/static-forward-decl.c?rev=51583&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/static-forward-decl.c (added)
+++ cfe/trunk/test/CodeGen/static-forward-decl.c Mon May 26 23:58:01 2008
@@ -0,0 +1,5 @@
+// RUN: clang %s -emit-llvm -o - -triple=i686-apple-darwin9 | grep "global i32 10"
+
+static int i;
+int*j=&i;
+static int i = 10;
More information about the cfe-commits
mailing list