Skip to content

Commit

Permalink
[clang][Interp] Don't create global variables more than once
Browse files Browse the repository at this point in the history
just because we're being told to evaluate it twice. This sometimes
happens when a variable is evaluated again during codegen.

Differential Revision: https://reviews.llvm.org/D147535
  • Loading branch information
tbaederr committed Apr 13, 2023
1 parent 2ecbe7c commit f508d9b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion clang/lib/AST/Interp/ByteCodeExprGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,11 @@ bool ByteCodeExprGen<Emitter>::visitVarDecl(const VarDecl *VD) {
std::optional<PrimType> VarT = classify(VD->getType());

if (shouldBeGloballyIndexed(VD)) {
std::optional<unsigned> GlobalIndex = P.getOrCreateGlobal(VD, Init);
// We've already seen and initialized this global.
if (P.getGlobal(VD))
return true;

std::optional<unsigned> GlobalIndex = P.createGlobal(VD, Init);

if (!GlobalIndex)
return this->bail(VD);
Expand Down

0 comments on commit f508d9b

Please sign in to comment.