[clang] 338c35a - [clang][Interp] Fix calling variadic call operators

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 24 08:06:40 PDT 2024


Author: Timm Bäder
Date: 2024-07-24T17:06:24+02:00
New Revision: 338c35aabfbede9ba10a4f48a13e63f37d6f8c7c

URL: https://github.com/llvm/llvm-project/commit/338c35aabfbede9ba10a4f48a13e63f37d6f8c7c
DIFF: https://github.com/llvm/llvm-project/commit/338c35aabfbede9ba10a4f48a13e63f37d6f8c7c.diff

LOG: [clang][Interp] Fix calling variadic call operators

Added: 
    

Modified: 
    clang/lib/AST/Interp/Interp.cpp
    clang/test/AST/Interp/cxx20.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index bf29b85041d82..3694253ae9782 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -233,7 +233,8 @@ void cleanupAfterFunctionCall(InterpState &S, CodePtr OpPC) {
       assert(false && "Can't get arguments from that expression type");
 
     assert(NumArgs >= CurFunc->getNumWrittenParams());
-    NumVarArgs = NumArgs - CurFunc->getNumWrittenParams();
+    NumVarArgs = NumArgs - (CurFunc->getNumWrittenParams() +
+                            isa<CXXOperatorCallExpr>(CallSite));
     for (unsigned I = 0; I != NumVarArgs; ++I) {
       const Expr *A = Args[NumArgs - 1 - I];
       popArg(S, A);

diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 2faacbbf70fd7..da80454b7a820 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -827,3 +827,17 @@ namespace CheckingNullPtrForInitialization {
     return x;
   }
 }
+
+namespace VariadicCallOperator {
+  class F {
+  public:
+    constexpr void operator()(int a, int b, ...) {}
+  };
+  constexpr int foo() {
+    F f;
+
+    f(1,2, 3);
+    return 1;
+  }
+  constexpr int A = foo();
+}


        


More information about the cfe-commits mailing list