Author: Timm Baeder Date: 2026-02-10T05:46:16+01:00 New Revision: fdd9555fc015b0be790226c68391537d12581a82
URL: https://github.com/llvm/llvm-project/commit/fdd9555fc015b0be790226c68391537d12581a82 DIFF: https://github.com/llvm/llvm-project/commit/fdd9555fc015b0be790226c68391537d12581a82.diff LOG: [clang][bytecode] Fix discarded Mulc/DivC opcodes (#180537) We need to pop the pointer in that case. Added: Modified: clang/lib/AST/ByteCode/Compiler.cpp clang/test/AST/ByteCode/complex.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index b981cd3c7090d..07237263e2971 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -1217,7 +1217,11 @@ bool Compiler<Emitter>::VisitComplexBinOp(const BinaryOperator *E) { return false; if (!this->visit(RHS)) return false; - return this->emitMulc(ElemT, E); + if (!this->emitMulc(ElemT, E)) + return false; + if (DiscardResult) + return this->emitPopPtr(E); + return true; } if (Op == BO_Div && RHSIsComplex) { @@ -1254,7 +1258,11 @@ bool Compiler<Emitter>::VisitComplexBinOp(const BinaryOperator *E) { if (!this->visit(RHS)) return false; - return this->emitDivc(ElemT, E); + if (!this->emitDivc(ElemT, E)) + return false; + if (DiscardResult) + return this->emitPopPtr(E); + return true; } // Evaluate LHS and save value to LHSOffset. diff --git a/clang/test/AST/ByteCode/complex.cpp b/clang/test/AST/ByteCode/complex.cpp index 4440f201bb059..716b798277589 100644 --- a/clang/test/AST/ByteCode/complex.cpp +++ b/clang/test/AST/ByteCode/complex.cpp @@ -459,4 +459,11 @@ namespace Discard { return k; } static_assert(test_side_effect() == 1); + + constexpr int discardedMulDiv() { + (void)(3 * 2i); + (void)(3 / 2i); + return 0; + } + static_assert(discardedMulDiv() == 0, ""); } _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
