[clang] [Clang][Sema] Fix -Whigher-precision-for-complex-division (PR #131477)

Mészáros Gergely via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 9 00:01:58 PDT 2025


================
@@ -10591,6 +10591,45 @@ static void checkArithmeticNull(Sema &S, ExprResult &LHS, ExprResult &RHS,
       << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();
 }
 
+static void DetectPrecisionLossInComplexDivision(Sema &S, QualType DivisorTy,
+                                                 SourceLocation OpLoc) {
+  // If the divisor is real, then this is real/real or complex/real division.
+  // Either way there can be no precision loss.
+  auto *CT = DivisorTy->getAs<ComplexType>();
+  if (!CT)
+    return;
----------------
Maetveis wrote:

No, this is true either way, because we're doing elementwise divisions only.
Complex divided by real: `(a + bi)/c = a/c + (b/c)i`. Here both divisions are already precise by definition.

https://github.com/llvm/llvm-project/pull/131477


More information about the cfe-commits mailing list