Skip to content

Commit bf2d785

Browse files
authored
Fix bug in the type promotion for complex division in strict FP mode. (#87500)
Complex division on Windows with `-fcomplex-arithmetic=promoted` and `-ffp-model=strict` is crashing. This patch fixes the issue. See https://godbolt.org/z/15Gh7nvdM
1 parent 212b2bb commit bf2d785

File tree

2 files changed

+659
-3
lines changed

2 files changed

+659
-3
lines changed

clang/lib/CodeGen/CGExprComplex.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,12 @@ class ComplexExprEmitter
319319
// doubles the exponent of SmallerType.LargestFiniteVal)
320320
if (llvm::APFloat::semanticsMaxExponent(ElementTypeSemantics) * 2 + 1 <=
321321
llvm::APFloat::semanticsMaxExponent(HigherElementTypeSemantics)) {
322+
FPHasBeenPromoted = true;
322323
return CGF.getContext().getComplexType(HigherElementType);
323324
} else {
324-
FPHasBeenPromoted = true;
325325
DiagnosticsEngine &Diags = CGF.CGM.getDiags();
326326
Diags.Report(diag::warn_next_larger_fp_type_same_size_than_fp);
327-
return CGF.getContext().getComplexType(ElementType);
327+
return QualType();
328328
}
329329
}
330330

@@ -1037,7 +1037,7 @@ ComplexPairTy ComplexExprEmitter::EmitBinDiv(const BinOpInfo &Op) {
10371037
LHSi = llvm::Constant::getNullValue(RHSi->getType());
10381038
if (Op.FPFeatures.getComplexRange() == LangOptions::CX_Improved ||
10391039
(Op.FPFeatures.getComplexRange() == LangOptions::CX_Promoted &&
1040-
FPHasBeenPromoted))
1040+
!FPHasBeenPromoted))
10411041
return EmitRangeReductionDiv(LHSr, LHSi, RHSr, RHSi);
10421042
else if (Op.FPFeatures.getComplexRange() == LangOptions::CX_Basic ||
10431043
Op.FPFeatures.getComplexRange() == LangOptions::CX_Promoted)

0 commit comments

Comments
 (0)