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

Zahira Ammarguellat via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 9 06:00:39 PDT 2025


=?utf-8?q?Mészáros?= Gergely <maetveis at gmail.com>,Gergely Meszaros
 <gergely.meszaros at intel.com>,Gergely Meszaros <gergely.meszaros at intel.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/131477 at github.com>


================
@@ -10685,6 +10724,7 @@ QualType Sema::CheckMultiplyDivideOperands(ExprResult &LHS, ExprResult &RHS,
   if (compType.isNull() || !compType->isArithmeticType())
     return InvalidOperands(Loc, LHS, RHS);
   if (IsDiv) {
+    DetectPrecisionLossInComplexDivision(*this, RHS.get()->getType(), Loc);
----------------
zahiraam wrote:

> The dividend is not relevant assuming its a built-in arithmetic type, which I think it must be at this point in the code already. I'll try verifying this assumption though. Note that IIUC the types have "usual arithmetic conversions" applied to them here.
> 
> Whether the dividend is real or complex does not matter because complex divided by complex and real divided by complex both need promotion, but neither complex by complex (because it is elementwise) or real by real do.

OK looking at the divisor's type only is enough. When the divisor is of complex type than a promotion is needed. When the complex type of the divisor and the dividend are not of the same precision, a promotion is needed but that's happening with the current code.
How about if we have `_Complex float / double`? Or` _Complex double / float`? This should need a promotion, and it's not in the patch.

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


More information about the cfe-commits mailing list