https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/203747

We do this for regular calls, so do it for variable calls as well. Also remove 
two comments that don't have any meaning today anymore.

>From bb91c6c1706c5e35368d3ac13fa2f9a4a2f0d89b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Sun, 14 Jun 2026 07:56:44 +0200
Subject: [PATCH] [clang][bytecode] Overide constant context state in CallVar

We do this for regular calls, so do it for variable calls as well. Also
remove two comments that don't have any meaning today anymore.
---
 clang/lib/AST/ByteCode/Interp.cpp         |  7 +-----
 clang/test/AST/ByteCode/codegen-cxx2a.cpp | 26 +++++++++++++++++++++++
 2 files changed, 27 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/AST/ByteCode/codegen-cxx2a.cpp

diff --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index 0a4a84edd62a4..754046be06d05 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1774,9 +1774,7 @@ bool CallVar(InterpState &S, CodePtr OpPC, const Function 
*Func,
   InterpFrame *FrameBefore = S.Current;
   S.Current = NewFrame;
 
-  // Note that we cannot assert(CallResult.hasValue()) here since
-  // Ret() above only sets the APValue if the curent frame doesn't
-  // have a caller set.
+  InterpStateCCOverride CCOverride(S, Func->isImmediate());
   if (Interpret(S)) {
     assert(S.Current == FrameBefore);
     return true;
@@ -1868,9 +1866,6 @@ bool Call(InterpState &S, CodePtr OpPC, const Function 
*Func,
   S.Current = NewFrame;
 
   InterpStateCCOverride CCOverride(S, Func->isImmediate());
-  // Note that we cannot assert(CallResult.hasValue()) here since
-  // Ret() above only sets the APValue if the curent frame doesn't
-  // have a caller set.
   bool Success = Interpret(S);
   // Remove initializing  block again.
   if (Func->isConstructor() || Func->isDestructor())
diff --git a/clang/test/AST/ByteCode/codegen-cxx2a.cpp 
b/clang/test/AST/ByteCode/codegen-cxx2a.cpp
new file mode 100644
index 0000000000000..d75a758e19308
--- /dev/null
+++ b/clang/test/AST/ByteCode/codegen-cxx2a.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -emit-llvm %s -std=c++2a -triple x86_64-unknown-linux-gnu 
-fexperimental-new-constant-interpreter -o - | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm %s -std=c++2a -triple x86_64-unknown-linux-gnu   
                                      -o - | FileCheck %s
+
+
+struct Agg {
+  int a;
+  long b;
+};
+consteval Agg is_const(...) {
+  return {5, 19 * __builtin_is_constant_evaluated()};
+}
+// CHECK-LABEL: @_Z13test_is_constv(
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:    [[B:%.*]] = alloca i64, align 8
+// CHECK-NEXT:    [[REF_TMP:%.*]] = alloca [[STRUCT_AGG:%.*]], align 8
+// CHECK-NEXT:    [[TMP0:%.*]] = getelementptr inbounds nuw [[STRUCT_AGG]], 
ptr [[REF_TMP]], i32 0, i32 0
+// CHECK-NEXT:    store i32 5, ptr [[TMP0]], align 8
+// CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds nuw [[STRUCT_AGG]], 
ptr [[REF_TMP]], i32 0, i32 1
+// CHECK-NEXT:    store i64 19, ptr [[TMP1]], align 8
+// CHECK-NEXT:    store i64 19, ptr [[B]], align 8
+// CHECK-NEXT:    [[TMP2:%.*]] = load i64, ptr [[B]], align 8
+// CHECK-NEXT:    ret i64 [[TMP2]]
+long test_is_const() {
+  long b = is_const().b;
+  return b;
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to