[clang] [clang][bytecode] Fix discarded Mulc/DivC opcodes (PR #180537)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 9 07:11:51 PST 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/180537
We need to pop the pointer in that case.
>From 3cba51d9572934aca3321fc92adc654028221d97 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 9 Feb 2026 16:10:41 +0100
Subject: [PATCH] [clang][bytecode] Fix discarded Mulc/DivC opcodes
We need to pop the pointer in that case.
---
clang/lib/AST/ByteCode/Compiler.cpp | 12 ++++++++++--
clang/test/AST/ByteCode/complex.cpp | 7 +++++++
2 files changed, 17 insertions(+), 2 deletions(-)
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, "");
}
More information about the cfe-commits
mailing list