[PATCH] D154475: [clang][Interp] Fix ignoring MaterializeTemporaryExprs

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 4 23:35:46 PDT 2023


tbaeder created this revision.
tbaeder added reviewers: aaron.ballman, erichkeane, tahonermann, shafik.
Herald added a project: All.
tbaeder requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154475

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


Index: clang/test/AST/Interp/literals.cpp
===================================================================
--- clang/test/AST/Interp/literals.cpp
+++ clang/test/AST/Interp/literals.cpp
@@ -920,6 +920,10 @@
     (short)5;
     (bool)1;
 
+    /// Ignored MaterializeTemporaryExpr.
+    struct B{ const int &a; };
+    (B{12}, 0);
+
     return 0;
   }
   static_assert(ignoredExprs() == 0, "");
Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp
===================================================================
--- clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -894,6 +894,11 @@
   const Expr *SubExpr = E->getSubExpr();
   std::optional<PrimType> SubExprT = classify(SubExpr);
 
+  // If we don't end up using the materialized temporary anyway, don't
+  // bother creating it.
+  if (DiscardResult)
+    return this->discard(SubExpr);
+
   if (E->getStorageDuration() == SD_Static) {
     std::optional<unsigned> GlobalIndex = P.createGlobal(E);
     if (!GlobalIndex)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154475.537230.patch
Type: text/x-patch
Size: 1015 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230705/6028a896/attachment.bin>


More information about the cfe-commits mailing list