From b6f500511bbc7571d0b17fcffa473d33100f84b4 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Fri, 8 Jan 2016 20:48:26 +0000 Subject: [PATCH] [MS ABI] Complete and base constructor GlobalDecls must have the same name Clang got itself into the situation where we mangled the same constructor twice with two different constructor types. After one of the constructors were utilized, the tag used for one of the types changed from class to struct because a class template became complete. This resulted in one of the constructor types varying from the other constructor. Instead, force "base" constructor types to "complete" if the ABI doesn't have constructor variants. This will ensure that GlobalDecls for both variants will get the same mangled name. This fixes PR26029. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257205 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 15 ++++++++++++++- test/CodeGenCXX/mangle-ms.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 536c55ae4e..97b166278f 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -615,7 +615,20 @@ void CodeGenModule::setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const { } StringRef CodeGenModule::getMangledName(GlobalDecl GD) { - StringRef &FoundStr = MangledDeclNames[GD.getCanonicalDecl()]; + GlobalDecl CanonicalGD = GD.getCanonicalDecl(); + + // Some ABIs don't have constructor variants. Make sure that base and + // complete constructors get mangled the same. + if (const auto *CD = dyn_cast(CanonicalGD.getDecl())) { + if (!getTarget().getCXXABI().hasConstructorVariants()) { + CXXCtorType OrigCtorType = GD.getCtorType(); + assert(OrigCtorType == Ctor_Base || OrigCtorType == Ctor_Complete); + if (OrigCtorType == Ctor_Base) + CanonicalGD = GlobalDecl(CD, Ctor_Complete); + } + } + + StringRef &FoundStr = MangledDeclNames[CanonicalGD]; if (!FoundStr.empty()) return FoundStr; diff --git a/test/CodeGenCXX/mangle-ms.cpp b/test/CodeGenCXX/mangle-ms.cpp index c2a311423a..c82fca49f6 100644 --- a/test/CodeGenCXX/mangle-ms.cpp +++ b/test/CodeGenCXX/mangle-ms.cpp @@ -454,3 +454,28 @@ namespace Complex { // CHECK-DAG: define void @"\01?f@Complex@@YAXU?$_Complex@H@__clang@@@Z"( void f(_Complex int) {} } + +namespace PR26029 { +template +struct L { + L() {} +}; +template +class H; +struct M : L > {}; + +template +struct H {}; + +template +void m_fn3() { + (H()); + M(); +} + +void runOnFunction() { + L > b; + m_fn3(); +} +// CHECK-DAG: call {{.*}} @"\01??0?$L@V?$H@PAH@PR26029@@@PR26029@@QAE@XZ" +} -- 2.50.1