From 2ac58801873ab99dd5de48ad7557b76f1803100b Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 2 Dec 2020 11:36:11 -0800 Subject: [PATCH] Update MS ABI mangling for union constants based on new information from Jon Caves. --- clang/lib/AST/MicrosoftMangle.cpp | 13 ++++++------ clang/test/CodeGenCXX/mangle-class-nttp.cpp | 22 ++++++++++----------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp index b093b2514c19..1fba1392d0ed 100644 --- a/clang/lib/AST/MicrosoftMangle.cpp +++ b/clang/lib/AST/MicrosoftMangle.cpp @@ -1681,14 +1681,13 @@ void MicrosoftCXXNameMangler::mangleTemplateArgValue(QualType T, } case APValue::Union: - Out << '2'; + Out << '7'; mangleType(T, SourceRange(), QMM_Escape); - // FIXME: MSVC doesn't mangle the active member, only the type, leading to - // collisions if more than one member has the same type. - // FIXME: MSVC doesn't yet support unions with no active member, but - // there's an obvious mangling for that, so we use it. - if (const FieldDecl *FD = V.getUnionField()) - mangleTemplateArgValue(FD->getType(), V.getUnionValue()); + if (const FieldDecl *FD = V.getUnionField()) { + mangleUnqualifiedName(FD); + mangleTemplateArgValue(FD->getType(), V.getUnionValue(), + /*WithType*/false); + } Out << '@'; return; diff --git a/clang/test/CodeGenCXX/mangle-class-nttp.cpp b/clang/test/CodeGenCXX/mangle-class-nttp.cpp index 9bb83fcf3246..579afd0a01be 100644 --- a/clang/test/CodeGenCXX/mangle-class-nttp.cpp +++ b/clang/test/CodeGenCXX/mangle-class-nttp.cpp @@ -120,16 +120,16 @@ template void f() {} // CHECK: define weak_odr void @_Z1fIXL1EEEEvv( // FIXME: MSVC rejects this; check this is the mangling MSVC uses when they // start accepting. -// MSABI: define {{.*}} @"??$f@$2TE@@@@@YAXXZ" +// MSABI: define {{.*}} @"??$f@$7TE@@@@@YAXXZ" template void f(); // CHECK: define weak_odr void @_Z1fIXtl1EEEEvv( -// MSABI: define {{.*}} @"??$f@$2TE@@H0A@@@@YAXXZ" +// MSABI: define {{.*}} @"??$f@$7TE@@n@0A@@@@YAXXZ" template void f(); // CHECK: define weak_odr void @_Z1fIXtl1Edi1nLi42EEEEvv( -// MSABI: define {{.*}} @"??$f@$2TE@@H0CK@@@@YAXXZ" +// MSABI: define {{.*}} @"??$f@$7TE@@n@0CK@@@@YAXXZ" template void f(); // CHECK: define weak_odr void @_Z1fIXtl1Edi1fLf00000000EEEEvv( -// MSABI: define {{.*}} @"??$f@$2TE@@MAA@@@@YAXXZ" +// MSABI: define {{.*}} @"??$f@$7TE@@0AA@@@@YAXXZ" template void f(); // immintrin.h vector types. @@ -210,24 +210,22 @@ template

void f() {} template

void f() {} template

void f() {} // CHECK: define weak_odr void @_Z1fIXL2H1EEEvv -// MSABI: define {{.*}} @"??$f@$2TH1@@@@@YAXXZ" +// MSABI: define {{.*}} @"??$f@$7TH1@@@@@YAXXZ" template void f(); // CHECK: define weak_odr void @_Z1fIXL2H2EEEvv -// MSABI: define {{.*}} @"??$f@$2TH2@@@@@YAXXZ" +// MSABI: define {{.*}} @"??$f@$7TH2@@@@@YAXXZ" template void f(); // CHECK: define weak_odr void @_Z1fIXtl2H3EEEvv -// MSABI: define {{.*}} @"??$f@$2TH3@@H0A@@@@YAXXZ" +// MSABI: define {{.*}} @"??$f@$7TH3@@a@0A@@@@YAXXZ" template void f(); // CHECK: define weak_odr void @_Z1fIXtl2H3di1aLi1EEEEvv -// MSABI: define {{.*}} @"??$f@$2TH3@@H00@@@YAXXZ" +// MSABI: define {{.*}} @"??$f@$7TH3@@a@00@@@YAXXZ" template void f(); -// FIXME: Leads to mangling collision under MS ABI; same mangling as the {.a = 0} case. -#ifndef _WIN32 // CHECK: define weak_odr void @_Z1fIXtl2H3di1bLi0EEEEvv +// MSABI: define {{.*}} @"??$f@$7TH3@@b@0A@@@@YAXXZ" template void f(); -#endif // CHECK: define weak_odr void @_Z1fIXtl2H4EEEvv -// MSABI: define {{.*}} @"??$f@$2UH4@@2TH2@@@@@@YAXXZ" +// MSABI: define {{.*}} @"??$f@$2UH4@@7TH2@@@@@@YAXXZ" template void f(); // Floating-point.