From f508d9b1d4fa48e7586b9587a22be23c976297a7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timm=20B=C3=A4der?= Date: Fri, 27 Jan 2023 09:32:20 +0100 Subject: [PATCH] [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 --- clang/lib/AST/Interp/ByteCodeExprGen.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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); -- 2.7.4