Timm =?utf-8?q?Bäder?= <[email protected]>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/[email protected]>


https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/183279

>From 5d769798c6bf215635717ce21ca698c44911cf73 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Wed, 25 Feb 2026 12:11:56 +0100
Subject: [PATCH 1/2] asdf

---
 clang/lib/AST/ByteCode/Compiler.h             |  7 ++++++
 .../ByteCode/codegen-constexpr-unknown.cpp    | 25 ++++++++++++++++---
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Compiler.h 
b/clang/lib/AST/ByteCode/Compiler.h
index 1bd15c3d79563..8f1f9dad4469e 100644
--- a/clang/lib/AST/ByteCode/Compiler.h
+++ b/clang/lib/AST/ByteCode/Compiler.h
@@ -490,10 +490,17 @@ template <class Emitter> class VariableScope {
   void addForScopeKind(const Scope::Local &Local, ScopeKind Kind) {
     VariableScope *P = this;
     while (P) {
+      // We found the right scope kind.
       if (P->Kind == Kind) {
         P->addLocal(Local);
         return;
       }
+      // If we reached the root scope and we're looking for a Block scope,
+      // attach it to the root instead of the current scope.
+      if (!P->Parent && Kind == ScopeKind::Block) {
+        P->addLocal(Local);
+        return;
+      }
       P = P->Parent;
       if (!P)
         break;
diff --git a/clang/test/AST/ByteCode/codegen-constexpr-unknown.cpp 
b/clang/test/AST/ByteCode/codegen-constexpr-unknown.cpp
index f62117d5f7bec..5f2339c306d71 100644
--- a/clang/test/AST/ByteCode/codegen-constexpr-unknown.cpp
+++ b/clang/test/AST/ByteCode/codegen-constexpr-unknown.cpp
@@ -1,5 +1,23 @@
-// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -fcxx-exceptions -o - %s    
                                     | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -fcxx-exceptions -o - %s 
-fexperimental-new-constant-interpreter | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -fcxx-exceptions -o - %s    
                                              | FileCheck %s 
--check-prefix=CHECK
+// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm -fcxx-exceptions -o - %s 
-fexperimental-new-constant-interpreter -DINTERP | FileCheck %s 
--check-prefix=CHECK,INTERP
+
+/// CodeGenFunction::ConstantFoldsToSimpleInteger() for the if condition
+/// needs to succeed and return true.
+extern void abort2();
+constexpr const int* to_address(const int *p) {
+  return p;
+}
+void rightscope() {
+  const int p = 0;
+  if (to_address(&p) == &p)
+    return;
+  abort2();
+}
+// CHECK:      define dso_local void @_Z10rightscopev()
+// CHECK-NEXT: entry:
+// CHECK-NEXT: %p = alloca i32
+// CHECK-NEXT: store i32 0, ptr %p
+// INTERP-NEXT: call noundef ptr @_Z10to_addressPKi(ptr noundef %p)
 
 
 /// In the if expression below, the read from s.i should fail.
@@ -39,7 +57,7 @@ int main() {
 /// Similarly, here we revisit the BindingDecl.
 struct F { int x; };
 int main2() {
-  const F const s{99};
+  const F s{99};
   const auto& [r1] = s;
   if (&r1 != &s.x)
     __builtin_abort();
@@ -70,3 +88,4 @@ X test24() {
 // CHECK: define dso_local void @_Z6test24v
 // CHECK-NOT: lpad
 // CHECK-NOT: eh.resume
+

>From 7d9acf1cfde14fb3147b0781049a35c0cc15aa4b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Thu, 26 Feb 2026 05:48:27 +0100
Subject: [PATCH 2/2] Clarify test comment

---
 clang/test/AST/ByteCode/codegen-constexpr-unknown.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/clang/test/AST/ByteCode/codegen-constexpr-unknown.cpp 
b/clang/test/AST/ByteCode/codegen-constexpr-unknown.cpp
index 5f2339c306d71..d5312c09d0bd8 100644
--- a/clang/test/AST/ByteCode/codegen-constexpr-unknown.cpp
+++ b/clang/test/AST/ByteCode/codegen-constexpr-unknown.cpp
@@ -3,9 +3,15 @@
 
 /// CodeGenFunction::ConstantFoldsToSimpleInteger() for the if condition
 /// needs to succeed and return true.
+/// When re-visiting p during that evaluation, we need to attach the local
+/// variable to the topmost scope, otherwise we will pick the call scope
+/// of to_address and de-allocate the local variable at the end of the
+/// to_address call.
+/// FIXME: This is not currently correct since we still mark p as
+/// constexpr-unknown and then reject it when comparing.
 extern void abort2();
-constexpr const int* to_address(const int *p) {
-  return p;
+constexpr const int* to_address(const int *a) {
+  return a;
 }
 void rightscope() {
   const int p = 0;

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

Reply via email to