r194288 - If a linkonce_odr dtor/ctor is identical to another one, just rauw.
Rafael Espindola
rafael.espindola at gmail.com
Fri Nov 8 14:59:46 PST 2013
Author: rafael
Date: Fri Nov 8 16:59:46 2013
New Revision: 194288
URL: http://llvm.org/viewvc/llvm-project?rev=194288&view=rev
Log:
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.
Modified:
cfe/trunk/lib/CodeGen/CGCXX.cpp
cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp
cfe/trunk/test/CodeGenCXX/destructors.cpp
Modified: cfe/trunk/lib/CodeGen/CGCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCXX.cpp?rev=194288&r1=194287&r2=194288&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCXX.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCXX.cpp Fri Nov 8 16:59:46 2013
@@ -139,6 +139,13 @@ bool CodeGenModule::TryEmitDefinitionAsA
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::TryEmitDefinitionAsA
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);
}
Modified: cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp?rev=194288&r1=194287&r2=194288&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/ctor-dtor-alias.cpp Fri Nov 8 16:59:46 2013
@@ -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() {}
};
Modified: cfe/trunk/test/CodeGenCXX/destructors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/destructors.cpp?rev=194288&r1=194287&r2=194288&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/destructors.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/destructors.cpp Fri Nov 8 16:59:46 2013
@@ -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;
More information about the cfe-commits
mailing list