[cfe-commits] r104796 - in /cfe/trunk: lib/CodeGen/CodeGenModule.cpp test/CodeGenCXX/destructors.cpp
John McCall
rjmccall at apple.com
Wed May 26 18:45:30 PDT 2010
Author: rjmccall
Date: Wed May 26 20:45:30 2010
New Revision: 104796
URL: http://llvm.org/viewvc/llvm-project?rev=104796&view=rev
Log:
When deciding whether a deferred declaration has already been emitted,
aliases count as definitions regardless of whether their target has been
emitted yet. Fixes PR 7142.
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGenCXX/destructors.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=104796&r1=104795&r2=104796&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed May 26 20:45:30 2010
@@ -513,9 +513,14 @@
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 @@
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);
}
Modified: cfe/trunk/test/CodeGenCXX/destructors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/destructors.cpp?rev=104796&r1=104795&r2=104796&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/destructors.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/destructors.cpp Wed May 26 20:45:30 2010
@@ -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 @@
// 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
+}
More information about the cfe-commits
mailing list