[clang] f508d9b - [clang][Interp] Don't create global variables more than once
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 13 06:48:17 PDT 2023
Author: Timm Bäder
Date: 2023-04-13T15:41:43+02:00
New Revision: f508d9b1d4fa48e7586b9587a22be23c976297a7
URL: https://github.com/llvm/llvm-project/commit/f508d9b1d4fa48e7586b9587a22be23c976297a7
DIFF: https://github.com/llvm/llvm-project/commit/f508d9b1d4fa48e7586b9587a22be23c976297a7.diff
LOG: [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
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 6ced8ca4d07f..a8e8b2997dde 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -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);
More information about the cfe-commits
mailing list