[PATCH] D147535: [clang][Interp] Don't create global variables more than once

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 13 06:48:32 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGf508d9b1d4fa: [clang][Interp] Don't create global variables more than once (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147535/new/

https://reviews.llvm.org/D147535

Files:
  clang/lib/AST/Interp/ByteCodeExprGen.cpp


Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1562,7 +1562,11 @@
   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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147535.513216.patch
Type: text/x-patch
Size: 630 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230413/b7034c8f/attachment-0001.bin>


More information about the cfe-commits mailing list