[clang] 69d740e - [clang][Interp] Fix creating functions with explicit instance parameters

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Mon May 6 02:38:30 PDT 2024


Author: Timm Bäder
Date: 2024-05-06T11:38:06+02:00
New Revision: 69d740e5d64257524914aabd6dfead7565185d4f

URL: https://github.com/llvm/llvm-project/commit/69d740e5d64257524914aabd6dfead7565185d4f
DIFF: https://github.com/llvm/llvm-project/commit/69d740e5d64257524914aabd6dfead7565185d4f.diff

LOG: [clang][Interp] Fix creating functions with explicit instance parameters

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeEmitter.cpp
    clang/test/AST/Interp/cxx23.cpp
    clang/test/SemaCXX/cxx2b-deducing-this-constexpr.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeEmitter.cpp b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
index d912c101449d80..918cd66c9a9767 100644
--- a/clang/lib/AST/Interp/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/Interp/ByteCodeEmitter.cpp
@@ -82,11 +82,13 @@ Function *ByteCodeEmitter::compileFunc(const FunctionDecl *FuncDecl) {
   // InterpStack when calling the function.
   bool HasThisPointer = false;
   if (const auto *MD = dyn_cast<CXXMethodDecl>(FuncDecl)) {
-    if (MD->isImplicitObjectMemberFunction() && !IsLambdaStaticInvoker) {
-      HasThisPointer = true;
-      ParamTypes.push_back(PT_Ptr);
-      ParamOffsets.push_back(ParamOffset);
-      ParamOffset += align(primSize(PT_Ptr));
+    if (!IsLambdaStaticInvoker) {
+      HasThisPointer = MD->isInstance();
+      if (MD->isImplicitObjectMemberFunction()) {
+        ParamTypes.push_back(PT_Ptr);
+        ParamOffsets.push_back(ParamOffset);
+        ParamOffset += align(primSize(PT_Ptr));
+      }
     }
 
     // Set up lambda capture to closure record field mapping.

diff  --git a/clang/test/AST/Interp/cxx23.cpp b/clang/test/AST/Interp/cxx23.cpp
index d1ec93e99803e5..55807f0e0f115a 100644
--- a/clang/test/AST/Interp/cxx23.cpp
+++ b/clang/test/AST/Interp/cxx23.cpp
@@ -170,3 +170,10 @@ namespace LabelGoto {
   static_assert(foo() == 1, ""); // all-error {{not an integral constant expression}} \
                                  // all-note {{in call to}}
 }
+
+namespace ExplicitLambdaThis {
+  constexpr auto f = [x = 3]<typename Self>(this Self self) { // all20-error {{explicit object parameters are incompatible with C++ standards before C++2b}}
+      return x;
+  };
+  static_assert(f());
+}

diff  --git a/clang/test/SemaCXX/cxx2b-deducing-this-constexpr.cpp b/clang/test/SemaCXX/cxx2b-deducing-this-constexpr.cpp
index 9dbea17dd2cae3..191fb013e0316f 100644
--- a/clang/test/SemaCXX/cxx2b-deducing-this-constexpr.cpp
+++ b/clang/test/SemaCXX/cxx2b-deducing-this-constexpr.cpp
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -fsyntax-only -std=c++2b %s -verify
+// RUN: %clang_cc1 -fsyntax-only -std=c++2b %s -verify -fexperimental-new-constant-interpreter
 // expected-no-diagnostics
 
 template <typename Base>


        


More information about the cfe-commits mailing list