[clang] [clang][bytecode] Fix discarded Mulc/DivC opcodes (PR #180537)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 9 07:12:28 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
We need to pop the pointer in that case.
---
Full diff: https://github.com/llvm/llvm-project/pull/180537.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+10-2)
- (modified) clang/test/AST/ByteCode/complex.cpp (+7)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index a0138c402e143..121ff00e462fc 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 68a8e78d5b25b..9212c4fc47209 100644
--- a/clang/test/AST/ByteCode/complex.cpp
+++ b/clang/test/AST/ByteCode/complex.cpp
@@ -457,4 +457,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, "");
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/180537
More information about the cfe-commits
mailing list