From: Rafael Espindola Date: Fri, 8 Nov 2013 22:59:46 +0000 (+0000) Subject: If a linkonce_odr dtor/ctor is identical to another one, just rauw. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0171c6b348815df326a063c7e78eb81b7347fa25;p=clang If a linkonce_odr dtor/ctor is identical to another one, just rauw. Unlike an alias a rauw is always safe, so we don't need to avoid this optimization when the replacement is not know to be available in every TU. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@194288 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGCXX.cpp b/lib/CodeGen/CGCXX.cpp index eeedaf1064..8c7a089460 100644 --- a/lib/CodeGen/CGCXX.cpp +++ b/lib/CodeGen/CGCXX.cpp @@ -139,6 +139,13 @@ bool CodeGenModule::TryEmitDefinitionAsAlias(GlobalDecl AliasDecl, if (Ref->getType() != AliasType) Aliasee = llvm::ConstantExpr::getBitCast(Ref, AliasType); + // Instead of creating as alias to a linkonce_odr, replace all of the uses + // of the aliassee. + if (Linkage == llvm::GlobalValue::LinkOnceODRLinkage) { + Replacements[MangledName] = Aliasee; + return false; + } + // Don't create an alias to a linker weak symbol unless we know we can do // that in every TU. This avoids producing different COMDATs in different // TUs. @@ -146,12 +153,6 @@ bool CodeGenModule::TryEmitDefinitionAsAlias(GlobalDecl AliasDecl, if (!InEveryTU) return true; - // Instead of creating as alias to a linkonce_odr, replace all of the uses - // of the aliassee. - if (Linkage == llvm::GlobalValue::LinkOnceODRLinkage) { - Replacements[MangledName] = Aliasee; - return false; - } assert(Linkage == TargetLinkage); } diff --git a/test/CodeGenCXX/ctor-dtor-alias.cpp b/test/CodeGenCXX/ctor-dtor-alias.cpp index ff9bd7c5c5..fdd378bab3 100644 --- a/test/CodeGenCXX/ctor-dtor-alias.cpp +++ b/test/CodeGenCXX/ctor-dtor-alias.cpp @@ -45,10 +45,11 @@ B x; namespace test4 { // Test that we don't produce aliases from B to A. We cannot because we cannot - // guarantee that they will be present in every TU. + // guarantee that they will be present in every TU. Instead, we just call + // A's destructor directly. - // CHECK-DAG: define linkonce_odr void @_ZN5test41BD2Ev( // CHECK-DAG: define linkonce_odr void @_ZN5test41AD2Ev( + // CHECK-DAG: call i32 @__cxa_atexit{{.*}}_ZN5test41AD2Ev struct A { virtual ~A() {} }; diff --git a/test/CodeGenCXX/destructors.cpp b/test/CodeGenCXX/destructors.cpp index 887b73fcc5..b98c5c7e62 100644 --- a/test/CodeGenCXX/destructors.cpp +++ b/test/CodeGenCXX/destructors.cpp @@ -45,7 +45,7 @@ namespace PR7526 { allocator::~allocator() throw() { foo(); } // CHECK-LABEL: define void @_ZN6PR75263fooEv() - // CHECK: call void @_ZN6PR752617allocator_derivedD2Ev + // CHECK: call void {{.*}} @_ZN6PR75269allocatorD2Ev void foo() { allocator_derived ad;