diff options
author | Timm Baeder <tbaeder@redhat.com> | 2025-07-08 17:17:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-08 17:17:15 +0200 |
commit | 5cefb9a367c80a69a6d80956bf8822ee0e5dd766 (patch) | |
tree | b53e145a07719b44454879795c4a384925dbe73a /clang/lib/AST/ByteCode/InterpBuiltin.cpp | |
parent | 65f94d75187bdab5c853e31fbf35267258f0be67 (diff) | |
download | llvm-5cefb9a367c80a69a6d80956bf8822ee0e5dd766.zip llvm-5cefb9a367c80a69a6d80956bf8822ee0e5dd766.tar.gz llvm-5cefb9a367c80a69a6d80956bf8822ee0e5dd766.tar.bz2 |
[clang][bytecode] Fix __builtin_is_within_lifetime in initializers (#147480)
Diffstat (limited to 'clang/lib/AST/ByteCode/InterpBuiltin.cpp')
-rw-r--r-- | clang/lib/AST/ByteCode/InterpBuiltin.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index db18ad2..1fe6d14 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -2208,7 +2208,7 @@ static bool interp__builtin_is_within_lifetime(InterpState &S, CodePtr OpPC, if (Ptr.isOnePastEnd()) return Error(1); - bool Result = true; + bool Result = Ptr.getLifetime() != Lifetime::Ended; if (!Ptr.isActive()) { Result = false; } else { @@ -2216,7 +2216,19 @@ static bool interp__builtin_is_within_lifetime(InterpState &S, CodePtr OpPC, return false; if (!CheckMutable(S, OpPC, Ptr)) return false; + if (!CheckDummy(S, OpPC, Ptr, AK_Read)) + return false; + } + + // 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 (S.EvaluatingDecl && Ptr.getDeclDesc()->asVarDecl() == S.EvaluatingDecl) + return Error(2); pushInteger(S, Result, Call->getType()); return true; |