From bab1697d36d91d64bd3887330dd80715dc8b8fe6 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Wed, 6 Aug 2014 03:12:47 +0000 Subject: [PATCH] MS ABI: Mangle lambdas which are given the same mangling number It is possible for lambdas to get the same mangling number because they may exist in different mangling contexts. To handle this correctly, mangle the context into the name as well. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214947 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/MicrosoftMangle.cpp | 5 +---- test/CodeGenCXX/mangle-ms-cxx11.cpp | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp index ed22d27849..bc07e3c2dc 100644 --- a/lib/AST/MicrosoftMangle.cpp +++ b/lib/AST/MicrosoftMangle.cpp @@ -802,10 +802,7 @@ void MicrosoftCXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, void MicrosoftCXXNameMangler::mangleNestedName(const NamedDecl *ND) { // ::= [] // ::= [] - if (isLambda(ND)) - return; - - const DeclContext *DC = ND->getDeclContext(); + const DeclContext *DC = getEffectiveDeclContext(ND); while (!DC->isTranslationUnit()) { if (isa(ND) || isa(ND)) { diff --git a/test/CodeGenCXX/mangle-ms-cxx11.cpp b/test/CodeGenCXX/mangle-ms-cxx11.cpp index 490edd831b..1b892864c6 100644 --- a/test/CodeGenCXX/mangle-ms-cxx11.cpp +++ b/test/CodeGenCXX/mangle-ms-cxx11.cpp @@ -98,7 +98,7 @@ namespace PR18022 { struct { } a; decltype(a) fun(decltype(a) x, decltype(a)) { return x; } -// CHECK-DAG: ?fun@PR18022@@YA?AU@1@U21@0@Z +// CHECK-DAG: @"\01?fun@PR18022@@YA?AU@1@U21@0@Z" } @@ -106,17 +106,32 @@ inline int define_lambda() { static auto lambda = [] { static int local; ++local; return local; }; // First, we have the static local variable of type "" inside of // "define_lambda". -// CHECK-DAG: ?lambda@?1??define_lambda@@YAHXZ@4V@@A +// CHECK-DAG: @"\01?lambda@?1??define_lambda@@YAHXZ@4V@?1@YAHXZ@A" // Next, we have the "operator()" for "" which is inside of // "define_lambda". -// CHECK-DAG: ??R@?define_lambda@@YAHXZ@QBEHXZ +// CHECK-DAG: @"\01??R@?define_lambda@@YAHXZ@QBEHXZ" // Finally, we have the local which is inside of "" which is inside of // "define_lambda". Hooray. -// CHECK-DAG: ?local@?2???R@?define_lambda@@YAHXZ@QBEHXZ@4HA +// CHECK-DAG: @"\01?local@?2???R@?define_lambda@@YAHXZ@QBEHXZ@4HA" return lambda(); } +template +void use_lambda_arg(T) {} + +inline void call_with_lambda_arg1() { + use_lambda_arg([]{}); + // CHECK-DAG: @"\01??$use_lambda_arg@V@?call_with_lambda_arg1@@YAXXZ@@@YAXV@?call_with_lambda_arg1@@YAXXZ@@Z" +} + +inline void call_with_lambda_arg2() { + use_lambda_arg([]{}); + // CHECK-DAG: @"\01??$use_lambda_arg@V@?call_with_lambda_arg2@@YAXXZ@@@YAXV@?call_with_lambda_arg2@@YAXXZ@@Z" +} + int call_lambda() { + call_with_lambda_arg1(); + call_with_lambda_arg2(); return define_lambda(); } -- 2.40.0