[clang] [clang][bytecode] Fix multi-word complex division (PR #181325)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 12 23:31:21 PST 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/181325
Looks like I forgot about `isZero()` when writing this.
>From f2d12e8f57e0e88ea60732b8dde7a55f7ffb63d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Fri, 13 Feb 2026 08:26:21 +0100
Subject: [PATCH] [clang][bytecode] Fix multi-word complex division
---
clang/lib/AST/ByteCode/Interp.h | 6 ++----
clang/test/AST/ByteCode/complex.c | 2 ++
2 files changed, 4 insertions(+), 4 deletions(-)
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; }
More information about the cfe-commits
mailing list