[clang] 97cddb7 - [clang][Interp] Fix ignoring MaterializeTemporaryExprs

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 1 00:45:50 PDT 2023


Author: Timm Bäder
Date: 2023-08-01T09:45:33+02:00
New Revision: 97cddb78502eee583b5f4ee02c59b7156398587f

URL: https://github.com/llvm/llvm-project/commit/97cddb78502eee583b5f4ee02c59b7156398587f
DIFF: https://github.com/llvm/llvm-project/commit/97cddb78502eee583b5f4ee02c59b7156398587f.diff

LOG: [clang][Interp] Fix ignoring MaterializeTemporaryExprs

Differential Revision: https://reviews.llvm.org/D154475

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index de024180765031..fcdfe19bd84439 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -865,6 +865,11 @@ bool ByteCodeExprGen<Emitter>::VisitMaterializeTemporaryExpr(
   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) {
     if (std::optional<unsigned> GlobalIndex = P.createGlobal(E)) {
       const LifetimeExtendedTemporaryDecl *TempDecl =

diff  --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp
index ad0adc23b42e40..505ab8fc764f14 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -890,7 +890,9 @@ constexpr int ignoredExprs() {
 
   1 ? 0 : 1; // expected-warning {{unused}} \
              // ref-warning {{unused}}
-
+  /// Ignored MaterializeTemporaryExpr.
+  struct B{ const int &a; };
+  (void)B{12};
   return 0;
 }
 


        


More information about the cfe-commits mailing list