[clang] [clang][bytecode][NFC] Check InitializingBlocks in _within_lifetime (PR #155378)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 26 02:01:36 PDT 2025
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/155378
This kind of check is exactly why InterpState::InitializingBlocks exists.
>From 58fd33edddc61e7b394740694fde9ec577b71cb1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Tue, 26 Aug 2025 11:00:05 +0200
Subject: [PATCH] [clang][bytecode][NFC] Check InitializingBlocks in
_within_lifetime
This kind of check is exactly why InterpState::InitializingBlocks
exists.
---
clang/lib/AST/ByteCode/InterpBuiltin.cpp | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index e245f24e614e5..cec3c9b33d453 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -2505,12 +2505,8 @@ static bool interp__builtin_is_within_lifetime(InterpState &S, CodePtr OpPC,
}
// Check if we're currently running an initializer.
- for (InterpFrame *Frame = S.Current; Frame; Frame = Frame->Caller) {
- if (const Function *F = Frame->getFunction();
- F && F->isConstructor() && Frame->getThis().block() == Ptr.block()) {
- return Error(2);
- }
- }
+ if (llvm::is_contained(S.InitializingBlocks, Ptr.block()))
+ return Error(2);
if (S.EvaluatingDecl && Ptr.getDeclDesc()->asVarDecl() == S.EvaluatingDecl)
return Error(2);
More information about the cfe-commits
mailing list