r233023 - MS ABI: lambda call operators are instance methods and should use thiscall

Reid Kleckner reid at kleckner.net
Mon Mar 23 14:16:49 PDT 2015


Author: rnk
Date: Mon Mar 23 16:16:49 2015
New Revision: 233023

URL: http://llvm.org/viewvc/llvm-project?rev=233023&view=rev
Log:
MS ABI: lambda call operators are instance methods and should use thiscall

Fixes an issue reported by Daniel Berenyi on cfe-dev.

Modified:
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/CodeGenCXX/mangle-ms-cxx14.cpp
    cfe/trunk/test/SemaCXX/decl-microsoft-call-conv.cpp

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=233023&r1=233022&r2=233023&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Mar 23 16:16:49 2015
@@ -2483,6 +2483,10 @@ getCCForDeclaratorChunk(Sema &S, Declara
       // in a member pointer.
       IsCXXInstanceMethod =
           D.getTypeObject(I).Kind == DeclaratorChunk::MemberPointer;
+    } else if (D.getContext() == Declarator::LambdaExprContext) {
+      // This can only be a call operator for a lambda, which is an instance
+      // method.
+      IsCXXInstanceMethod = true;
     } else {
       // We're the innermost decl chunk, so must be a function declarator.
       assert(D.isFunctionDeclarator());

Modified: cfe/trunk/test/CodeGenCXX/mangle-ms-cxx14.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-cxx14.cpp?rev=233023&r1=233022&r2=233023&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-ms-cxx14.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms-cxx14.cpp Mon Mar 23 16:16:49 2015
@@ -35,10 +35,10 @@ auto TemplateFuncionWithLocalLambda(T) {
   return LocalLambdaWithLocalType();
 }
 
-// MSVC2013-DAG: "\01?ValueFromTemplateFuncionWithLocalLambda@@3ULocalType@?2???R<lambda_1>@??$TemplateFuncionWithLocalLambda at H@@YA?A?<auto>@@H at Z@QBA?A?3 at XZ@A"
-// MSVC2013-DAG: "\01?ValueFromTemplateFuncionWithLocalLambda@@3ULocalType@?2???R<lambda_1>@??$TemplateFuncionWithLocalLambda at H@@YA?A?<auto>@@H at Z@QBA?A?3 at XZ@A"
-// MSVC2015-DAG: "\01?ValueFromTemplateFuncionWithLocalLambda@@3ULocalType@?1???R<lambda_1>@??$TemplateFuncionWithLocalLambda at H@@YA?A?<auto>@@H at Z@QBA?A?3 at XZ@A"
-// MSVC2015-DAG: "\01?ValueFromTemplateFuncionWithLocalLambda@@3ULocalType@?1???R<lambda_1>@??$TemplateFuncionWithLocalLambda at H@@YA?A?<auto>@@H at Z@QBA?A?3 at XZ@A"
+// MSVC2013-DAG: "\01?ValueFromTemplateFuncionWithLocalLambda@@3ULocalType@?2???R<lambda_1>@??$TemplateFuncionWithLocalLambda at H@@YA?A?<auto>@@H at Z@QBE?A?3 at XZ@A"
+// MSVC2013-DAG: "\01?ValueFromTemplateFuncionWithLocalLambda@@3ULocalType@?2???R<lambda_1>@??$TemplateFuncionWithLocalLambda at H@@YA?A?<auto>@@H at Z@QBE?A?3 at XZ@A"
+// MSVC2015-DAG: "\01?ValueFromTemplateFuncionWithLocalLambda@@3ULocalType@?1???R<lambda_1>@??$TemplateFuncionWithLocalLambda at H@@YA?A?<auto>@@H at Z@QBE?A?3 at XZ@A"
+// MSVC2015-DAG: "\01?ValueFromTemplateFuncionWithLocalLambda@@3ULocalType@?1???R<lambda_1>@??$TemplateFuncionWithLocalLambda at H@@YA?A?<auto>@@H at Z@QBE?A?3 at XZ@A"
 // CHECK: "\01??$TemplateFuncionWithLocalLambda at H@@YA?A?<auto>@@H at Z"
-// CHECK: "\01??R<lambda_1>@??$TemplateFuncionWithLocalLambda at H@@YA?A?<auto>@@H at Z@QBA?A?1 at XZ"
+// CHECK: "\01??R<lambda_1>@??$TemplateFuncionWithLocalLambda at H@@YA?A?<auto>@@H at Z@QBE?A?1 at XZ"
 auto ValueFromTemplateFuncionWithLocalLambda = TemplateFuncionWithLocalLambda(0);

Modified: cfe/trunk/test/SemaCXX/decl-microsoft-call-conv.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/decl-microsoft-call-conv.cpp?rev=233023&r1=233022&r2=233023&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/decl-microsoft-call-conv.cpp (original)
+++ cfe/trunk/test/SemaCXX/decl-microsoft-call-conv.cpp Mon Mar 23 16:16:49 2015
@@ -1,6 +1,6 @@
-// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -verify %s
-// RUN: %clang_cc1 -triple i686-pc-mingw32 -verify %s
-// RUN: %clang_cc1 -triple i686-pc-mingw32 -fms-extensions -verify %s
+// RUN: %clang_cc1 -std=c++14 -triple i686-pc-win32 -fms-extensions -verify %s
+// RUN: %clang_cc1 -std=c++14 -triple i686-pc-mingw32 -verify %s
+// RUN: %clang_cc1 -std=c++14 -triple i686-pc-mingw32 -fms-extensions -verify %s
 
 typedef void void_fun_t();
 typedef void __cdecl cdecl_fun_t();
@@ -242,3 +242,19 @@ namespace test8 {
     s.f(p); // expected-note {{in instantiation of member function 'test8::S<void *>::f' requested here}}
   }
 }
+
+namespace test9 {
+  // Used to fail when we forgot to make lambda call operators use __thiscall.
+  template <typename F>
+  decltype(auto) deduce(F f) {
+    return &decltype(f)::operator();
+  }
+  template <typename C, typename R, typename A>
+  decltype(auto) signaturehelper(R (C::*f)(A) const) {
+    return R();
+  }
+  void f() {
+    auto l = [](int x) { return x * 2; };
+    decltype(signaturehelper(deduce(l))) p;
+  }
+}





More information about the cfe-commits mailing list