[clang] aa00f13 - [clang][bytecode] Iterate scope only once in Destroy() (#219874)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 30 23:55:59 PDT 2026
Author: Timm Baeder
Date: 2026-08-31T08:55:54+02:00
New Revision: aa00f13b094c51a0aa4ad0ff5390e5227c0b4919
URL: https://github.com/llvm/llvm-project/commit/aa00f13b094c51a0aa4ad0ff5390e5227c0b4919
DIFF: https://github.com/llvm/llvm-project/commit/aa00f13b094c51a0aa4ad0ff5390e5227c0b4919.diff
LOG: [clang][bytecode] Iterate scope only once in Destroy() (#219874)
Call deallocate() here directly instead of iterating the scope again in
`InterpFrame::destroy()`.
Added:
Modified:
clang/lib/AST/ByteCode/Interp.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp
index 716f3320299a3..8be502e851504 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -3045,19 +3045,25 @@ bool InvalidCast(InterpState &S, CodePtr OpPC, CastKind Kind, bool Fatal) {
return false;
}
+// Destroy one scope: deallocate all local variables of the scope and diagnose
+// out-of-lifetime destroys.
bool Destroy(InterpState &S, CodePtr OpPC, uint32_t I) {
assert(S.Current->getFunction());
- // FIXME: We iterate the scope once here and then again in the destroy() call
- // below.
for (auto &Local : S.Current->getFunction()->getScope(I).locals_reverse()) {
- if (!S.Current->getLocalBlock(Local.Offset)->isInitialized())
+ Block *LocalBlock = S.Current->getLocalBlock(Local.Offset);
+
+ if (!LocalBlock->isInitialized())
continue;
- const Pointer &Ptr = S.Current->getLocalPointer(Local.Offset);
- if (Ptr.getLifetime() == Lifetime::Ended)
+
+ if (LocalBlock->getBlockDesc<InlineDescriptor>().LifeState ==
+ Lifetime::Ended) {
+ const Pointer Ptr = S.Current->getLocalPointer(Local.Offset);
return diagnoseOutOfLifetimeDestroy(S, OpPC, Ptr);
+ }
+
+ S.deallocate(LocalBlock);
}
- S.Current->destroy(I);
return true;
}
More information about the cfe-commits
mailing list