From: Timm Bäder Date: Fri, 27 Jan 2023 08:32:20 +0000 (+0100) Subject: [clang][Interp] Don't create global variables more than once X-Git-Tag: upstream/17.0.6~11753 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f508d9b1d4fa48e7586b9587a22be23c976297a7;p=platform%2Fupstream%2Fllvm.git [clang][Interp] Don't create global variables more than once 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 --- diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp index 6ced8ca..a8e8b29 100644 --- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -1562,7 +1562,11 @@ bool ByteCodeExprGen::visitVarDecl(const VarDecl *VD) { std::optional VarT = classify(VD->getType()); if (shouldBeGloballyIndexed(VD)) { - std::optional GlobalIndex = P.getOrCreateGlobal(VD, Init); + // We've already seen and initialized this global. + if (P.getGlobal(VD)) + return true; + + std::optional GlobalIndex = P.createGlobal(VD, Init); if (!GlobalIndex) return this->bail(VD);