[llvm] r194705 - Error if we see an alias to a declaration.

Rafael Espindola rafael.espindola at gmail.com
Thu Nov 14 05:58:07 PST 2013


Author: rafael
Date: Thu Nov 14 07:58:06 2013
New Revision: 194705

URL: http://llvm.org/viewvc/llvm-project?rev=194705&view=rev
Log:
Error if we see an alias to a declaration.

In ELF and COFF an alias is just another offset in a section. There is no way
to represent an alias to something in another file.

In MachO, the spec has the N_INDR type which should allow for exactly that, but
is not currently implemented. Given that it is specified but not implemented,
we error in codegen to avoid miscompiling but don't reject aliases to
declarations in the verifier to leave the option open of implementing it.

In the past we have used alias to declarations as a way of implementing
weakref, which is why it exists in some old tests which this patch updates.

Added:
    llvm/trunk/test/CodeGen/X86/alias-error.ll
Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/test/CodeGen/ARM/aliases.ll
    llvm/trunk/test/CodeGen/Generic/2009-03-17-LSR-APInt.ll
    llvm/trunk/test/CodeGen/PowerPC/mcm-9.ll
    llvm/trunk/test/CodeGen/X86/2007-09-06-ExtWeakAliasee.ll
    llvm/trunk/test/CodeGen/X86/2008-03-14-SpillerCrash.ll
    llvm/trunk/test/CodeGen/X86/aliases.ll
    llvm/trunk/test/CodeGen/X86/x86-64-pic-10.ll
    llvm/trunk/test/CodeGen/XCore/aliases.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=194705&r1=194704&r2=194705&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Thu Nov 14 07:58:06 2013
@@ -949,6 +949,11 @@ bool AsmPrinter::doFinalization(Module &
       MCSymbol *Name = getSymbol(I);
 
       const GlobalValue *GV = I->getAliasedGlobal();
+      if (GV->isDeclaration()) {
+        report_fatal_error(Name->getName() +
+                           ": Target doesn't support aliases to declarations");
+      }
+
       MCSymbol *Target = getSymbol(GV);
 
       if (I->hasExternalLinkage() || !MAI->getWeakRefDirective())

Modified: llvm/trunk/test/CodeGen/ARM/aliases.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/ARM/aliases.ll?rev=194705&r1=194704&r2=194705&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/ARM/aliases.ll (original)
+++ llvm/trunk/test/CodeGen/ARM/aliases.ll Thu Nov 14 07:58:06 2013
@@ -16,13 +16,15 @@
 ; CHECK: .globl	A
 ; CHECK: A = bar
 
- at bar = external global i32
+ at bar = global i32 42
 @foo1 = alias i32* @bar
 @foo2 = alias i32* @bar
 
 %FunTy = type i32()
 
-declare i32 @foo_f()
+define i32 @foo_f() {
+  ret i32 0
+}
 @bar_f = alias weak %FunTy* @foo_f
 
 @bar_i = alias internal i32* @bar

Modified: llvm/trunk/test/CodeGen/Generic/2009-03-17-LSR-APInt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Generic/2009-03-17-LSR-APInt.ll?rev=194705&r1=194704&r2=194705&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Generic/2009-03-17-LSR-APInt.ll (original)
+++ llvm/trunk/test/CodeGen/Generic/2009-03-17-LSR-APInt.ll Thu Nov 14 07:58:06 2013
@@ -63,30 +63,58 @@ bb47:		; preds = %bb46, %bb44
 	br label %bb44
 }
 
-declare i32 @pthread_once(i32*, void ()*)
+define i32 @pthread_once(i32*, void ()*) {
+  ret i32 0
+}
 
-declare i8* @pthread_getspecific(i32)
+define i8* @pthread_getspecific(i32) {
+  ret i8* null
+}
 
-declare i32 @pthread_setspecific(i32, i8*)
+define i32 @pthread_setspecific(i32, i8*) {
+  ret i32 0
+}
 
-declare i32 @pthread_create(i64*, %struct.pthread_attr_t*, i8* (i8*)*, i8*)
+define i32 @pthread_create(i64*, %struct.pthread_attr_t*, i8* (i8*)*, i8*) {
+  ret i32 0
+}
 
-declare i32 @pthread_cancel(i64)
+define i32 @pthread_cancel(i64) {
+  ret i32 0
+}
 
-declare i32 @pthread_mutex_lock(%struct.pthread_mutex_t*)
+define i32 @pthread_mutex_lock(%struct.pthread_mutex_t*) {
+  ret i32 0
+}
 
-declare i32 @pthread_mutex_trylock(%struct.pthread_mutex_t*)
+define i32 @pthread_mutex_trylock(%struct.pthread_mutex_t*) {
+  ret i32 0
+}
 
-declare i32 @pthread_mutex_unlock(%struct.pthread_mutex_t*)
+define i32 @pthread_mutex_unlock(%struct.pthread_mutex_t*) {
+  ret i32 0
+}
 
-declare i32 @pthread_mutex_init(%struct.pthread_mutex_t*, %struct.Alignment*)
+define i32 @pthread_mutex_init(%struct.pthread_mutex_t*, %struct.Alignment*) {
+  ret i32 0
+}
 
-declare i32 @pthread_key_create(i32*, void (i8*)*)
+define i32 @pthread_key_create(i32*, void (i8*)*) {
+  ret i32 0
+}
 
-declare i32 @pthread_key_delete(i32)
+define i32 @pthread_key_delete(i32) {
+  ret i32 0
+}
 
-declare i32 @pthread_mutexattr_init(%struct.Alignment*)
+define i32 @pthread_mutexattr_init(%struct.Alignment*) {
+  ret i32 0
+}
 
-declare i32 @pthread_mutexattr_settype(%struct.Alignment*, i32)
+define i32 @pthread_mutexattr_settype(%struct.Alignment*, i32) {
+  ret i32 0
+}
 
-declare i32 @pthread_mutexattr_destroy(%struct.Alignment*)
+define i32 @pthread_mutexattr_destroy(%struct.Alignment*) {
+  ret i32 0
+}

Modified: llvm/trunk/test/CodeGen/PowerPC/mcm-9.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/mcm-9.ll?rev=194705&r1=194704&r2=194705&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/PowerPC/mcm-9.ll (original)
+++ llvm/trunk/test/CodeGen/PowerPC/mcm-9.ll Thu Nov 14 07:58:06 2013
@@ -7,8 +7,7 @@
 target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f128:128:128-v128:128:128-n32:64"
 target triple = "powerpc64-unknown-linux-gnu"
 
- at ei = external global i32
- at a = alias i32* @ei
+ at a = external global i32
 
 define signext i32 @test_external() nounwind {
 entry:

Modified: llvm/trunk/test/CodeGen/X86/2007-09-06-ExtWeakAliasee.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/2007-09-06-ExtWeakAliasee.ll?rev=194705&r1=194704&r2=194705&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/2007-09-06-ExtWeakAliasee.ll (original)
+++ llvm/trunk/test/CodeGen/X86/2007-09-06-ExtWeakAliasee.ll Thu Nov 14 07:58:06 2013
@@ -1,4 +1,6 @@
 ; RUN: llc < %s -march=x86 | grep weak | count 2
 @__gthrw_pthread_once = alias weak i32 (i32*, void ()*)* @pthread_once		; <i32 (i32*, void ()*)*> [#uses=0]
 
-declare extern_weak i32 @pthread_once(i32*, void ()*)
+define weak i32 @pthread_once(i32*, void ()*) {
+  ret i32 0
+}

Modified: llvm/trunk/test/CodeGen/X86/2008-03-14-SpillerCrash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/2008-03-14-SpillerCrash.ll?rev=194705&r1=194704&r2=194705&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/2008-03-14-SpillerCrash.ll (original)
+++ llvm/trunk/test/CodeGen/X86/2008-03-14-SpillerCrash.ll Thu Nov 14 07:58:06 2013
@@ -45,4 +45,6 @@ bb383:		; preds = %bb374.us, %bb311.spli
 	ret i64 0
 }
 
-declare i64 @__wcstoll_l(i32*, i32**, i32, %struct.__locale_struct*) nounwind 
+define i64 @__wcstoll_l(i32*, i32**, i32, %struct.__locale_struct*) nounwind {
+  ret i64 0
+}

Added: llvm/trunk/test/CodeGen/X86/alias-error.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/alias-error.ll?rev=194705&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/alias-error.ll (added)
+++ llvm/trunk/test/CodeGen/X86/alias-error.ll Thu Nov 14 07:58:06 2013
@@ -0,0 +1,5 @@
+; RUN: not llc < %s -mtriple=i686-pc-linux-gnu %s 2>&1 | FileCheck %s
+
+ at a = external global i32
+ at b = alias i32* @a
+; CHECK: b: Target doesn't support aliases to declarations

Modified: llvm/trunk/test/CodeGen/X86/aliases.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/aliases.ll?rev=194705&r1=194704&r2=194705&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/aliases.ll (original)
+++ llvm/trunk/test/CodeGen/X86/aliases.ll Thu Nov 14 07:58:06 2013
@@ -1,6 +1,6 @@
 ; RUN: llc < %s -mtriple=i686-pc-linux-gnu -asm-verbose=false | FileCheck %s
 
- at bar = external global i32
+ at bar = global i32 42
 
 ; CHECK-DAG: .globl	foo1
 @foo1 = alias i32* @bar
@@ -10,7 +10,9 @@
 
 %FunTy = type i32()
 
-declare i32 @foo_f()
+define i32 @foo_f() {
+  ret i32 0
+}
 ; CHECK-DAG: .weak	bar_f
 @bar_f = alias weak %FunTy* @foo_f
 

Modified: llvm/trunk/test/CodeGen/X86/x86-64-pic-10.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/x86-64-pic-10.ll?rev=194705&r1=194704&r2=194705&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/x86-64-pic-10.ll (original)
+++ llvm/trunk/test/CodeGen/X86/x86-64-pic-10.ll Thu Nov 14 07:58:06 2013
@@ -9,4 +9,6 @@ entry:
         ret void
 }
 
-declare extern_weak i32 @f()
+define weak i32 @f() {
+  ret i32 42
+}

Modified: llvm/trunk/test/CodeGen/XCore/aliases.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/XCore/aliases.ll?rev=194705&r1=194704&r2=194705&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/XCore/aliases.ll (original)
+++ llvm/trunk/test/CodeGen/XCore/aliases.ll Thu Nov 14 07:58:06 2013
@@ -1,7 +1,9 @@
 ; RUN: llc < %s -march=xcore | FileCheck %s
-declare void @a_val() nounwind
- at b_val = external constant i32, section ".cp.rodata"
- at c_val = external global i32
+define void @a_val() nounwind {
+  ret void
+}
+ at b_val = constant i32 42, section ".cp.rodata"
+ at c_val = global i32 42
 
 @a = alias void ()* @a_val
 @b = alias i32* @b_val





More information about the llvm-commits mailing list