[clang] [clang] fix divide by zero in ComplexExprEvaluator (PR #104666)
Sergei Barannikov via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 18 04:59:07 PDT 2024
================
@@ -15567,12 +15567,13 @@ bool ComplexExprEvaluator::VisitBinaryOperator(const BinaryOperator *E) {
HandleComplexComplexDiv(A, B, C, D, ResR, ResI);
}
} else {
- if (RHS.getComplexIntReal() == 0 && RHS.getComplexIntImag() == 0)
- return Error(E, diag::note_expr_divide_by_zero);
-
ComplexValue LHS = Result;
APSInt Den = RHS.getComplexIntReal() * RHS.getComplexIntReal() +
RHS.getComplexIntImag() * RHS.getComplexIntImag();
+ if ((RHS.getComplexIntReal() == 0 && RHS.getComplexIntImag() == 0) ||
+ Den.isZero())
----------------
s-barannikov wrote:
(nit) The first part of the check implies the second, why not just
```suggestion
if (Den.isZero())
```
https://github.com/llvm/llvm-project/pull/104666
More information about the cfe-commits
mailing list