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

If they aren't const.

Fixes https://github.com/llvm/llvm-project/issues/164985

>From d551ffdafa589f3c50d8824b371990a97afd4b45 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Fri, 24 Oct 2025 17:08:56 +0200
Subject: [PATCH] [clang][bytecode] Fail on reads from constexpr-unknown
 pointers

If they aren't const.

Fixes https://github.com/llvm/llvm-project/issues/164985
---
 clang/lib/AST/ByteCode/Interp.cpp         |  2 ++
 clang/test/AST/ByteCode/codegen-cxx20.cpp | 15 +++++++++++++++
 2 files changed, 17 insertions(+)
 create mode 100644 clang/test/AST/ByteCode/codegen-cxx20.cpp

diff --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index a72282caf5e73..5d89f32d6bdc2 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -832,6 +832,8 @@ bool CheckLoad(InterpState &S, CodePtr OpPC, const Pointer 
&Ptr,
     return false;
   if (!CheckVolatile(S, OpPC, Ptr, AK))
     return false;
+  if (!Ptr.isConst() && !S.inConstantContext() && isConstexprUnknown(Ptr))
+    return false;
   return true;
 }
 
diff --git a/clang/test/AST/ByteCode/codegen-cxx20.cpp 
b/clang/test/AST/ByteCode/codegen-cxx20.cpp
new file mode 100644
index 0000000000000..c1ef629da1e88
--- /dev/null
+++ b/clang/test/AST/ByteCode/codegen-cxx20.cpp
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s -fcxx-exceptions    
                                     | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -o - %s -fcxx-exceptions 
-fexperimental-new-constant-interpreter | FileCheck %s
+
+
+/// The read from a used to succeed, causing the entire if statement to vanish.
+extern void e();
+int somefunc() {
+  auto foo = [a = false]() mutable {
+    if (a)
+      e();
+  };
+  foo();
+}
+
+// CHECK: call void @_Z1ev()

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

Reply via email to