[clang] 1ea5688 - [clang][Interp][NFC] Mark failed globals as uninitialized
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 5 04:10:59 PDT 2024
Author: Timm Bäder
Date: 2024-06-05T13:10:18+02:00
New Revision: 1ea568895aa106a61e84607edfd52c3ebf4b59bc
URL: https://github.com/llvm/llvm-project/commit/1ea568895aa106a61e84607edfd52c3ebf4b59bc
DIFF: https://github.com/llvm/llvm-project/commit/1ea568895aa106a61e84607edfd52c3ebf4b59bc.diff
LOG: [clang][Interp][NFC] Mark failed globals as uninitialized
This happens automatically if anything _before_ the Ret op fails,
but in this case we have to un-initialize it again.
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index 3eb7e7544df71..3671c41ae7039 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3080,12 +3080,22 @@ bool ByteCodeExprGen<Emitter>::visitDecl(const VarDecl *VD) {
}
}
- // Return the value
- if (VarT)
- return this->emitRet(*VarT, VD);
-
- // Return non-primitive values as pointers here.
- return this->emitRet(PT_Ptr, VD);
+ // Return the value.
+ if (!this->emitRet(VarT.value_or(PT_Ptr), VD)) {
+ // If the Ret above failed and this is a global variable, mark it as
+ // uninitialized, even everything else succeeded.
+ if (Context::shouldBeGloballyIndexed(VD)) {
+ auto GlobalIndex = P.getGlobal(VD);
+ assert(GlobalIndex);
+ Block *GlobalBlock = P.getGlobal(*GlobalIndex);
+ InlineDescriptor &ID =
+ *reinterpret_cast<InlineDescriptor *>(GlobalBlock->rawData());
+ ID.IsInitialized = false;
+ GlobalBlock->invokeDtor();
+ }
+ return false;
+ }
+ return true;
}
template <class Emitter>
More information about the cfe-commits
mailing list