From 0090140bef3e2c22de03f42c515f6de061103801 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Mon, 3 Feb 2014 18:54:51 +0000 Subject: [PATCH] [ms-cxxabi] Fix cast when structor replacement is an alias git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200711 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 12 +++++++---- test/CodeGenCXX/destructors.cpp | 7 +++++++ .../microsoft-abi-structors-alias.cpp | 21 +++++++++++++++++-- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 2ee232284f..c73e931c9d 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -187,10 +187,14 @@ void CodeGenModule::applyReplacements() { llvm::Function *OldF = cast(Entry); llvm::Function *NewF = dyn_cast(Replacement); if (!NewF) { - llvm::ConstantExpr *CE = cast(Replacement); - assert(CE->getOpcode() == llvm::Instruction::BitCast || - CE->getOpcode() == llvm::Instruction::GetElementPtr); - NewF = dyn_cast(CE->getOperand(0)); + if (llvm::GlobalAlias *Alias = dyn_cast(Replacement)) { + NewF = dyn_cast(Alias->getAliasedGlobal()); + } else { + llvm::ConstantExpr *CE = cast(Replacement); + assert(CE->getOpcode() == llvm::Instruction::BitCast || + CE->getOpcode() == llvm::Instruction::GetElementPtr); + NewF = dyn_cast(CE->getOperand(0)); + } } // Replace old with new, but keep the old order. diff --git a/test/CodeGenCXX/destructors.cpp b/test/CodeGenCXX/destructors.cpp index f0e5a124ee..9bd2754b91 100644 --- a/test/CodeGenCXX/destructors.cpp +++ b/test/CodeGenCXX/destructors.cpp @@ -6,6 +6,13 @@ // CHECK-DAG: @_ZN5test11OD2Ev = alias {{.*}} @_ZN5test11AD2Ev // CHECK-DAG: @_ZN5test11SD2Ev = alias bitcast {{.*}} @_ZN5test11AD2Ev +// WIN32-DAG: @_ZN5test01AD1Ev = alias {{.*}} @_ZN5test01AD2Ev +// WIN32-DAG: @_ZN5test11MD2Ev = alias {{.*}} @_ZN5test11AD2Ev +// WIN32-DAG: @_ZN5test11ND2Ev = alias {{.*}} @_ZN5test11AD2Ev +// WIN32-DAG: @_ZN5test11OD2Ev = alias {{.*}} @_ZN5test11AD2Ev +// WIN32-DAG: @_ZN5test11SD2Ev = alias bitcast {{.*}} @_ZN5test11AD2Ev + + struct A { int a; diff --git a/test/CodeGenCXX/microsoft-abi-structors-alias.cpp b/test/CodeGenCXX/microsoft-abi-structors-alias.cpp index 9301163d54..f977556aa5 100644 --- a/test/CodeGenCXX/microsoft-abi-structors-alias.cpp +++ b/test/CodeGenCXX/microsoft-abi-structors-alias.cpp @@ -1,9 +1,26 @@ -// RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-win32 -fno-rtti -mconstructor-aliases | FileCheck %s +// RUN: %clang_cc1 -emit-llvm %s -o - -triple=i386-pc-win32 -fno-rtti -mconstructor-aliases -O1 -disable-llvm-optzns | FileCheck %s namespace test1 { template class A { ~A() {} }; template class A; -// CHECK: define weak_odr x86_thiscallcc void @"\01??1?$A@D@test1@@AAE@XZ" +// CHECK-DAG: define weak_odr x86_thiscallcc void @"\01??1?$A@D@test1@@AAE@XZ" +} + +namespace test2 { +struct A { + virtual ~A(); +}; +struct B : A { + B(); + virtual ~B(); +}; + +A::~A() {} +B::~B() {} +void foo() { + B b; +} +// CHECK-DAG: @"\01??1B@test2@@UAE@XZ" = alias bitcast (void (%"struct.test2::A"*)* @"\01??1A@test2@@UAE@XZ" to void (%"struct.test2::B"*)*) } -- 2.40.0