Skip to content

Commit 1ea5688

Browse files
committed
[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.
1 parent 54b20cb commit 1ea5688

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3080,12 +3080,22 @@ bool ByteCodeExprGen<Emitter>::visitDecl(const VarDecl *VD) {
30803080
}
30813081
}
30823082

3083-
// Return the value
3084-
if (VarT)
3085-
return this->emitRet(*VarT, VD);
3086-
3087-
// Return non-primitive values as pointers here.
3088-
return this->emitRet(PT_Ptr, VD);
3083+
// Return the value.
3084+
if (!this->emitRet(VarT.value_or(PT_Ptr), VD)) {
3085+
// If the Ret above failed and this is a global variable, mark it as
3086+
// uninitialized, even everything else succeeded.
3087+
if (Context::shouldBeGloballyIndexed(VD)) {
3088+
auto GlobalIndex = P.getGlobal(VD);
3089+
assert(GlobalIndex);
3090+
Block *GlobalBlock = P.getGlobal(*GlobalIndex);
3091+
InlineDescriptor &ID =
3092+
*reinterpret_cast<InlineDescriptor *>(GlobalBlock->rawData());
3093+
ID.IsInitialized = false;
3094+
GlobalBlock->invokeDtor();
3095+
}
3096+
return false;
3097+
}
3098+
return true;
30893099
}
30903100

30913101
template <class Emitter>

0 commit comments

Comments
 (0)