https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/183279
... if we don't have a block scope available. This can happen in `EvalEmitter` scenarios and can cause local variable blocks to be prematurely converted to dead blocks. Attach `ScopeKind::Block` variable to the root scope instead. >From e912fa9d77d14449021329d1b26124e96f029adb 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 +++++++ .../AST/ByteCode/codegen-constexpr-unknown.cpp | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) 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..e3f145a3dd0d0 100644 --- a/clang/test/AST/ByteCode/codegen-constexpr-unknown.cpp +++ b/clang/test/AST/ByteCode/codegen-constexpr-unknown.cpp @@ -70,3 +70,21 @@ X test24() { // CHECK: define dso_local void @_Z6test24v // CHECK-NOT: lpad // CHECK-NOT: eh.resume + +/// 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, align 4 +// CHECK-NEXT: store i32 0, ptr %p, align 4 +// CHECK-NEXT: ret void _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
