This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG97cddb78502e: [clang][Interp] Fix ignoring MaterializeTemporaryExprs (authored by tbaeder).
Changed prior to commit: https://reviews.llvm.org/D154475?vs=537230&id=545946#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D154475/new/ 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 @@ -890,7 +890,9 @@ 1 ? 0 : 1; // expected-warning {{unused}} \ // ref-warning {{unused}} - + /// Ignored MaterializeTemporaryExpr. + struct B{ const int &a; }; + (void)B{12}; return 0; } Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -865,6 +865,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) { if (std::optional<unsigned> GlobalIndex = P.createGlobal(E)) { const LifetimeExtendedTemporaryDecl *TempDecl =
Index: clang/test/AST/Interp/literals.cpp =================================================================== --- clang/test/AST/Interp/literals.cpp +++ clang/test/AST/Interp/literals.cpp @@ -890,7 +890,9 @@ 1 ? 0 : 1; // expected-warning {{unused}} \ // ref-warning {{unused}} - + /// Ignored MaterializeTemporaryExpr. + struct B{ const int &a; }; + (void)B{12}; return 0; } Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -865,6 +865,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) { if (std::optional<unsigned> GlobalIndex = P.createGlobal(E)) { const LifetimeExtendedTemporaryDecl *TempDecl =
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits