[clang] [clang][bytecode] Fix multi-word complex division (PR #181325)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 12 23:31:54 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
Looks like I forgot about `isZero()` when writing this.
---
Full diff: https://github.com/llvm/llvm-project/pull/181325.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Interp.h (+2-4)
- (modified) clang/test/AST/ByteCode/complex.c (+2)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 1bfa347a9016a..db9514486aa6b 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -481,10 +481,8 @@ inline bool Divc(InterpState &S, CodePtr OpPC) {
const T &RHSR = RHS.elem<T>(0);
const T &RHSI = RHS.elem<T>(1);
unsigned Bits = LHSR.bitWidth();
- const T Zero = T::from(0, Bits);
- if (Compare(RHSR, Zero) == ComparisonCategoryResult::Equal &&
- Compare(RHSI, Zero) == ComparisonCategoryResult::Equal) {
+ if (RHSR.isZero() && RHSI.isZero()) {
const SourceInfo &E = S.Current->getSource(OpPC);
S.FFDiag(E, diag::note_expr_divide_by_zero);
return false;
@@ -507,7 +505,7 @@ inline bool Divc(InterpState &S, CodePtr OpPC) {
if (T::add(A, B, Bits, &Den))
return false;
- if (Compare(Den, Zero) == ComparisonCategoryResult::Equal) {
+ if (Den.isZero()) {
const SourceInfo &E = S.Current->getSource(OpPC);
S.FFDiag(E, diag::note_expr_divide_by_zero);
return false;
diff --git a/clang/test/AST/ByteCode/complex.c b/clang/test/AST/ByteCode/complex.c
index a39f83160ef8c..2834401d55fc6 100644
--- a/clang/test/AST/ByteCode/complex.c
+++ b/clang/test/AST/ByteCode/complex.c
@@ -28,3 +28,5 @@ void testComplexFloat(_Atomic(_Complex float) *fp) {
_Complex float f = *fp;
*fp = f;
}
+
+void ZeroNeedsAlloc() { 9999999999999999999wb / 1wbi; }
``````````
</details>
https://github.com/llvm/llvm-project/pull/181325
More information about the cfe-commits
mailing list