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] 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 + _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
