This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGaed9646d8e29: [clang][Interp] Fix discarding void-typed comma expressions (authored by tbaeder).
Changed prior to commit: https://reviews.llvm.org/D148925?vs=515800&id=544214#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D148925/new/ https://reviews.llvm.org/D148925 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 @@ -855,9 +855,23 @@ (a); // expected-warning {{unused}} \ // ref-warning {{unused}} + (void)5, (void)6; + return 0; } +/// Ignored comma expressions still have their +/// expressions evaluated. +constexpr int Comma(int start) { + int i = start; + + (void)i++; + (void)i++,(void)i++; + return i; +} +constexpr int Value = Comma(5); +static_assert(Value == 8, ""); + #endif namespace PredefinedExprs { Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -223,8 +223,12 @@ // Deal with operations which have composite or void types. if (BO->isCommaOp()) { - if (!discard(LHS)) + if (!this->discard(LHS)) return false; + if (RHS->getType()->isVoidType()) + return this->discard(RHS); + + // Otherwise, visit RHS and optionally discard its value. return Discard(this->visit(RHS)); } @@ -1642,10 +1646,12 @@ if (!visit(Exp)) return false; + if (Exp->getType()->isVoidType()) + return this->emitRetVoid(Exp); + if (std::optional<PrimType> T = classify(Exp)) return this->emitRet(*T, Exp); - else - return this->emitRetValue(Exp); + return this->emitRetValue(Exp); } /// Toplevel visitDecl().
Index: clang/test/AST/Interp/literals.cpp =================================================================== --- clang/test/AST/Interp/literals.cpp +++ clang/test/AST/Interp/literals.cpp @@ -855,9 +855,23 @@ (a); // expected-warning {{unused}} \ // ref-warning {{unused}} + (void)5, (void)6; + return 0; } +/// Ignored comma expressions still have their +/// expressions evaluated. +constexpr int Comma(int start) { + int i = start; + + (void)i++; + (void)i++,(void)i++; + return i; +} +constexpr int Value = Comma(5); +static_assert(Value == 8, ""); + #endif namespace PredefinedExprs { Index: clang/lib/AST/Interp/ByteCodeExprGen.cpp =================================================================== --- clang/lib/AST/Interp/ByteCodeExprGen.cpp +++ clang/lib/AST/Interp/ByteCodeExprGen.cpp @@ -223,8 +223,12 @@ // Deal with operations which have composite or void types. if (BO->isCommaOp()) { - if (!discard(LHS)) + if (!this->discard(LHS)) return false; + if (RHS->getType()->isVoidType()) + return this->discard(RHS); + + // Otherwise, visit RHS and optionally discard its value. return Discard(this->visit(RHS)); } @@ -1642,10 +1646,12 @@ if (!visit(Exp)) return false; + if (Exp->getType()->isVoidType()) + return this->emitRetVoid(Exp); + if (std::optional<PrimType> T = classify(Exp)) return this->emitRet(*T, Exp); - else - return this->emitRetValue(Exp); + return this->emitRetValue(Exp); } /// Toplevel visitDecl().
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits