[clang] f15d799 - [clang][Interp] Fix variadic operator calls

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 1 07:38:32 PST 2024


Author: Timm Bäder
Date: 2024-03-01T15:46:00+01:00
New Revision: f15d799f16092918b948536775475dfd8675c7d9

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

LOG: [clang][Interp] Fix variadic operator calls

Operator calls pass their instance member explicitly, so remove
it from NumParams when calling a variadic function

Added: 
    

Modified: 
    clang/lib/AST/Interp/ByteCodeExprGen.cpp
    clang/test/AST/Interp/functions.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 0185214fb455de..388da0e324c732 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -2842,7 +2842,8 @@ bool ByteCodeExprGen<Emitter>::VisitCallExpr(const CallExpr *E) {
         return false;
     } else if (Func->isVariadic()) {
       uint32_t VarArgSize = 0;
-      unsigned NumParams = Func->getNumWrittenParams();
+      unsigned NumParams =
+          Func->getNumWrittenParams() + isa<CXXOperatorCallExpr>(E);
       for (unsigned I = NumParams, N = E->getNumArgs(); I != N; ++I)
         VarArgSize += align(primSize(classify(E->getArg(I)).value_or(PT_Ptr)));
       if (!this->emitCallVar(Func, VarArgSize, E))

diff  --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp
index 9daf8722050f07..38f761f563bef7 100644
--- a/clang/test/AST/Interp/functions.cpp
+++ b/clang/test/AST/Interp/functions.cpp
@@ -555,3 +555,13 @@ namespace Local {
     return t;
   }
 }
+
+namespace VariadicOperator {
+  struct Callable {
+    float& operator()(...);
+  };
+
+  void test_callable(Callable c) {
+    float &fr = c(10);
+  }
+}


        


More information about the cfe-commits mailing list