]> granicus.if.org Git - clang/commitdiff
When deciding whether a deferred declaration has already been emitted,
authorJohn McCall <rjmccall@apple.com>
Thu, 27 May 2010 01:45:30 +0000 (01:45 +0000)
committerJohn McCall <rjmccall@apple.com>
Thu, 27 May 2010 01:45:30 +0000 (01:45 +0000)
aliases count as definitions regardless of whether their target has been
emitted yet.  Fixes PR 7142.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104796 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/CodeGenCXX/destructors.cpp

index 1b89d6224208991fb1ddc8eac2a05fc385090779..103024c32392794420ab16667f4e15e4b14b6eae 100644 (file)
@@ -513,9 +513,14 @@ void CodeGenModule::EmitDeferred() {
     GlobalDecl D = DeferredDeclsToEmit.back();
     DeferredDeclsToEmit.pop_back();
 
-    // Look it up to see if it was defined with a stronger definition (e.g. an
-    // extern inline function with a strong function redefinition).  If so,
-    // just ignore the deferred decl.
+    // Check to see if we've already emitted this.  This is necessary
+    // for a couple of reasons: first, decls can end up in the
+    // deferred-decls queue multiple times, and second, decls can end
+    // up with definitions in unusual ways (e.g. by an extern inline
+    // function acquiring a strong function redefinition).  Just
+    // ignore these cases.
+    //
+    // TODO: That said, looking this up multiple times is very wasteful.
     MangleBuffer Name;
     getMangledName(Name, D);
     llvm::GlobalValue *CGRef = GetGlobalValue(Name);
@@ -524,6 +529,11 @@ void CodeGenModule::EmitDeferred() {
     if (!CGRef->isDeclaration())
       continue;
 
+    // GlobalAlias::isDeclaration() defers to the aliasee, but for our
+    // purposes an alias counts as a definition.
+    if (isa<llvm::GlobalAlias>(CGRef))
+      continue;
+
     // Otherwise, emit the definition and move on to the next one.
     EmitGlobalDefinition(D);
   }
index d40b174012ffc6371df4674180e795bc799afa39..5ab0346b0b686900d6ea774e528d7b5ebe94da0a 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -mconstructor-aliases | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -mconstructor-aliases -fexceptions | FileCheck %s
 
 // CHECK: @_ZN5test01AD1Ev = alias {{.*}} @_ZN5test01AD2Ev
 // CHECK: @_ZN5test11MD2Ev = alias {{.*}} @_ZN5test11AD2Ev
@@ -6,6 +6,10 @@
 // CHECK: @_ZN5test11OD2Ev = alias {{.*}} @_ZN5test11AD2Ev
 // CHECK: @_ZN5test11SD2Ev = alias bitcast {{.*}} @_ZN5test11AD2Ev
 
+// CHECK: @_ZN5test312_GLOBAL__N_11DD1Ev = alias internal {{.*}} @_ZN5test312_GLOBAL__N_11DD2Ev
+// CHECK: @_ZN5test312_GLOBAL__N_11DD2Ev = alias internal bitcast {{.*}} @_ZN5test312_GLOBAL__N_11CD2Ev
+// CHECK: @_ZN5test312_GLOBAL__N_11CD1Ev = alias internal {{.*}} @_ZN5test312_GLOBAL__N_11CD2Ev
+
 struct A {
   int a;
   
@@ -147,3 +151,62 @@ namespace test2 {
   // CHECK: define void @_ZN5test21BD2Ev
   // CHECK: call void @_ZN5test21AD2Ev
 }
+
+// PR7142
+namespace test3 {
+  struct A { virtual ~A(); };
+  struct B { virtual ~B(); };
+  namespace { // internal linkage => deferred
+    struct C : A, B {}; // ~B() in D requires a this-adjustment thunk
+    struct D : C {};    // D::~D() is an alias to C::~C()
+  }
+
+  void test() {
+    new D; // Force emission of D's vtable
+  }
+
+  // Checked at top of file:
+  // @_ZN5test312_GLOBAL__N_11CD1Ev = alias internal {{.*}} @_ZN5test312_GLOBAL__N_11CD2Ev
+
+  // CHECK: define internal void @_ZN5test312_GLOBAL__N_11CD2Ev(
+  // CHECK: call void @_ZN5test31BD2Ev(
+  // CHECK: call void @_ZN5test31AD2Ev(
+  // CHECK: ret void
+
+  // CHECK: define internal void @_ZN5test312_GLOBAL__N_11DD0Ev(
+  // CHECK: call void @_ZN5test312_GLOBAL__N_11DD1Ev(
+  // CHECK: call void @_ZdlPv(
+  // CHECK: ret void
+
+  // Checked at top of file:
+  // @_ZN5test312_GLOBAL__N_11DD1Ev = alias internal {{.*}} @_ZN5test312_GLOBAL__N_11DD2Ev
+  // @_ZN5test312_GLOBAL__N_11DD2Ev = alias internal bitcast {{.*}} @_ZN5test312_GLOBAL__N_11CD2Ev
+
+  // CHECK: define internal void @_ZThn8_N5test312_GLOBAL__N_11DD1Ev(
+  // CHECK: getelementptr inbounds i8* {{.*}}, i64 -8
+  // CHECK: call void @_ZN5test312_GLOBAL__N_11DD1Ev(
+  // CHECK: ret void
+
+  // CHECK: define internal void @_ZThn8_N5test312_GLOBAL__N_11DD0Ev(
+  // CHECK: getelementptr inbounds i8* {{.*}}, i64 -8
+  // CHECK: call void @_ZN5test312_GLOBAL__N_11DD0Ev(
+  // CHECK: ret void
+
+  // CHECK: declare void @_ZN5test31BD2Ev(
+  // CHECK: declare void @_ZN5test31AD2Ev(
+
+  // CHECK: define internal void @_ZN5test312_GLOBAL__N_11CD0Ev(
+  // CHECK: call void @_ZN5test312_GLOBAL__N_11CD1Ev(
+  // CHECK: call void @_ZdlPv(
+  // CHECK: ret void
+
+  // CHECK: define internal void @_ZThn8_N5test312_GLOBAL__N_11CD1Ev(
+  // CHECK: getelementptr inbounds i8* {{.*}}, i64 -8
+  // CHECK: call void @_ZN5test312_GLOBAL__N_11CD1Ev(
+  // CHECK: ret void
+
+  // CHECK: define internal void @_ZThn8_N5test312_GLOBAL__N_11CD0Ev(
+  // CHECK: getelementptr inbounds i8* {{.*}}, i64 -8
+  // CHECK: call void @_ZN5test312_GLOBAL__N_11CD0Ev(
+  // CHECK: ret void
+}