[llvm-commits] [dragonegg] r95302 - /dragonegg/trunk/llvm-backend.cpp

Duncan Sands baldrick at free.fr
Thu Feb 4 01:50:36 PST 2010


Author: baldrick
Date: Thu Feb  4 03:50:36 2010
New Revision: 95302

URL: http://llvm.org/viewvc/llvm-project?rev=95302&view=rev
Log:
Force the target of an alias to be output by calling "emit_global"
on it.  Otherwise we may only get a declaration for it, rather than
a definition (testcase: weak-11.c from the GCC testsuite).  The
magical incantation was swiped from llvm-convert.cpp, which also
needs to force output sometimes.

Modified:
    dragonegg/trunk/llvm-backend.cpp

Modified: dragonegg/trunk/llvm-backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/llvm-backend.cpp?rev=95302&r1=95301&r2=95302&view=diff

==============================================================================
--- dragonegg/trunk/llvm-backend.cpp (original)
+++ dragonegg/trunk/llvm-backend.cpp Thu Feb  4 03:50:36 2010
@@ -1654,33 +1654,46 @@
     while (IDENTIFIER_TRANSPARENT_ALIAS(target))
       target = TREE_CHAIN(target);
 
+  if (TREE_CODE(target) == IDENTIFIER_NODE) {
+    if (struct cgraph_node *fnode = cgraph_node_for_asm(target))
+      target = fnode->decl;
+    else if (struct varpool_node *vnode = varpool_node_for_asm(target))
+      target = vnode->decl;
+  }
+
   GlobalValue *Aliasee = 0;
   if (TREE_CODE(target) == IDENTIFIER_NODE) {
-    if (struct cgraph_node *fnode = cgraph_node_for_asm(target)) {
-      Aliasee = cast<GlobalValue>(DECL_LLVM(fnode->decl));
-    } else if (struct varpool_node *vnode = varpool_node_for_asm(target)) {
-      Aliasee = cast<GlobalValue>(DECL_LLVM(vnode->decl));
-    } else if (weakref) {
-      // weakref to external symbol.
-      if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
-        Aliasee = new GlobalVariable(*TheModule, GV->getType(),
-                                     GV->isConstant(),
-                                     GlobalVariable::ExternalWeakLinkage, NULL,
-                                     IDENTIFIER_POINTER(target));
-      else if (Function *F = dyn_cast<Function>(V))
-        Aliasee = Function::Create(F->getFunctionType(),
-                                   Function::ExternalWeakLinkage,
-                                   IDENTIFIER_POINTER(target),
-                                   TheModule);
-      else
-        assert(0 && "Unsuported global value");
-    } else {
+    if (!weakref) {
       error("%q+D aliased to undefined symbol %qs", decl,
             IDENTIFIER_POINTER(target));
       return;
     }
+
+    // weakref to external symbol.
+    if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V))
+      Aliasee = new GlobalVariable(*TheModule, GV->getType(),
+                                   GV->isConstant(),
+                                   GlobalVariable::ExternalWeakLinkage, NULL,
+                                   IDENTIFIER_POINTER(target));
+    else if (Function *F = dyn_cast<Function>(V))
+      Aliasee = Function::Create(F->getFunctionType(),
+                                 Function::ExternalWeakLinkage,
+                                 IDENTIFIER_POINTER(target),
+                                 TheModule);
+    else
+      assert(0 && "Unsuported global value");
   } else {
     Aliasee = cast<GlobalValue>(DECL_LLVM(target));
+
+    // If the target is an aggregate, emit it to LLVM now.
+    if (Aliasee->isDeclaration() && (TREE_CODE(target) == CONST_DECL ||
+                                     TREE_CODE(target) == VAR_DECL) &&
+        (DECL_INITIAL(target) || !TREE_PUBLIC(target)) &&
+        !DECL_EXTERNAL(target)) {
+      emit_global(target);
+      // Aliasee could have change if it changed type.
+      Aliasee = cast<GlobalValue>(DECL_LLVM(target));
+    }
   }
 
   GlobalValue::LinkageTypes Linkage = GlobalValue::ExternalLinkage;





More information about the llvm-commits mailing list