[dragonegg] r194708 - Handle weakref the clang way.

Rafael Espindola rafael.espindola at gmail.com
Thu Nov 14 08:05:26 PST 2013


Author: rafael
Date: Thu Nov 14 10:05:26 2013
New Revision: 194708

URL: http://llvm.org/viewvc/llvm-project?rev=194708&view=rev
Log:
Handle weakref the clang way.

Instead of introducing an alias to undefined, simply replace the uses of the
weak reference. This makes dragonegg's output match clang in these tests
and fixes the bootstrap.

dragonegg will still produce an unnecessary test2_g symbol in

void test2_f(void) {}
static void test2_g(void) __attribute__((weakref("test2_f")));
void test2_h(void) {
  test2_g();
}

Modified:
    dragonegg/trunk/src/Backend.cpp
    dragonegg/trunk/test/validator/c/ExternFunctionWeakref.c
    dragonegg/trunk/test/validator/c/ExternVariableWeakref.c

Modified: dragonegg/trunk/src/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Backend.cpp?rev=194708&r1=194707&r2=194708&view=diff
==============================================================================
--- dragonegg/trunk/src/Backend.cpp (original)
+++ dragonegg/trunk/src/Backend.cpp Thu Nov 14 10:05:26 2013
@@ -952,6 +952,7 @@ static void emit_alias(tree decl, tree t
   }
 
   GlobalValue *Aliasee = 0;
+  bool IsWeakRef = false;
   if (isa<IDENTIFIER_NODE>(target)) {
     StringRef AliaseeName(IDENTIFIER_POINTER(target),
                           IDENTIFIER_LENGTH(target));
@@ -965,6 +966,7 @@ static void emit_alias(tree decl, tree t
         return;
       }
     } else {
+      IsWeakRef = true;
       // weakref to external symbol.
       if (GlobalVariable *GV = llvm::dyn_cast<GlobalVariable>(V))
         Aliasee = new GlobalVariable(
@@ -983,7 +985,7 @@ static void emit_alias(tree decl, tree t
 
   GlobalValue::LinkageTypes Linkage = GetLinkageForAlias(decl);
 
-  if (Linkage != GlobalValue::InternalLinkage) {
+  if (Linkage != GlobalValue::InternalLinkage && !IsWeakRef) {
     // Create the LLVM alias.
     GlobalAlias *GA =
         new GlobalAlias(Aliasee->getType(), Linkage, "", Aliasee, TheModule);

Modified: dragonegg/trunk/test/validator/c/ExternFunctionWeakref.c
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c/ExternFunctionWeakref.c?rev=194708&r1=194707&r2=194708&view=diff
==============================================================================
--- dragonegg/trunk/test/validator/c/ExternFunctionWeakref.c (original)
+++ dragonegg/trunk/test/validator/c/ExternFunctionWeakref.c Thu Nov 14 10:05:26 2013
@@ -3,5 +3,5 @@
 static void function_weakref(void) __attribute__ ((weakref("foo")));
 void *use_function = (void *)function_weakref;
 
-// CHECK: @function_weakref = alias weak void ()* @foo
+// CHECK: @use_function = unnamed_addr global void ()* @foo
 // CHECK: declare extern_weak void @foo()

Modified: dragonegg/trunk/test/validator/c/ExternVariableWeakref.c
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/test/validator/c/ExternVariableWeakref.c?rev=194708&r1=194707&r2=194708&view=diff
==============================================================================
--- dragonegg/trunk/test/validator/c/ExternVariableWeakref.c (original)
+++ dragonegg/trunk/test/validator/c/ExternVariableWeakref.c Thu Nov 14 10:05:26 2013
@@ -3,5 +3,5 @@
 static int variable_weakref __attribute__ ((weakref("bar")));
 int *use_variable = &variable_weakref;
 
+// CHECK: @use_variable = unnamed_addr global i32* @bar
 // CHECK: @bar = extern_weak global i32
-// CHECK: @variable_weakref = alias weak i32* @bar





More information about the llvm-commits mailing list