diff options
author | John McCall <rjmccall@apple.com> | 2010-05-27 01:45:30 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-05-27 01:45:30 +0000 |
commit | c76702cc80c1ef8a94d82b62ddcb4ed4f67d5b8c (patch) | |
tree | 8357bdfafd6d6bc42500301042dde5173e622972 | |
parent | 8a2c92cab213bd7e28ff669577e815cd70bafbe3 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104796 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CodeGenModule.cpp | 16 | ||||
-rw-r--r-- | test/CodeGenCXX/destructors.cpp | 65 |
2 files changed, 77 insertions, 4 deletions
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 1b89d62242..103024c323 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -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); } diff --git a/test/CodeGenCXX/destructors.cpp b/test/CodeGenCXX/destructors.cpp index d40b174012..5ab0346b0b 100644 --- a/test/CodeGenCXX/destructors.cpp +++ b/test/CodeGenCXX/destructors.cpp @@ -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 +} |