@@ -328,12 +328,20 @@ class ComplexExprEmitter
328
328
}
329
329
}
330
330
331
- QualType getPromotionType (QualType Ty, bool IsDivOpCode = false ) {
331
+ QualType getPromotionType (FPOptionsOverride Features, QualType Ty,
332
+ bool IsDivOpCode = false ) {
332
333
if (auto *CT = Ty->getAs <ComplexType>()) {
333
334
QualType ElementType = CT->getElementType ();
334
- if (IsDivOpCode && ElementType->isFloatingType () &&
335
- CGF.getLangOpts ().getComplexRange () ==
336
- LangOptions::ComplexRangeKind::CX_Promoted)
335
+ bool IsFloatingType = ElementType->isFloatingType ();
336
+ bool IsComplexRangePromoted = CGF.getLangOpts ().getComplexRange () ==
337
+ LangOptions::ComplexRangeKind::CX_Promoted;
338
+ bool HasNoComplexRangeOverride = !Features.hasComplexRangeOverride ();
339
+ bool HasMatchingComplexRange = Features.hasComplexRangeOverride () &&
340
+ Features.getComplexRangeOverride () ==
341
+ CGF.getLangOpts ().getComplexRange ();
342
+
343
+ if (IsDivOpCode && IsFloatingType && IsComplexRangePromoted &&
344
+ (HasNoComplexRangeOverride || HasMatchingComplexRange))
337
345
return HigherPrecisionTypeForComplexArithmetic (ElementType,
338
346
IsDivOpCode);
339
347
if (ElementType.UseExcessPrecision (CGF.getContext ()))
@@ -347,7 +355,7 @@ class ComplexExprEmitter
347
355
#define HANDLEBINOP (OP ) \
348
356
ComplexPairTy VisitBin##OP(const BinaryOperator *E) { \
349
357
QualType promotionTy = getPromotionType ( \
350
- E->getType (), \
358
+ E->getStoredFPFeaturesOrDefault (), E-> getType (), \
351
359
(E->getOpcode () == BinaryOperatorKind::BO_Div) ? true : false ); \
352
360
ComplexPairTy result = EmitBin##OP (EmitBinOps (E, promotionTy)); \
353
361
if (!promotionTy.isNull ()) \
@@ -641,9 +649,12 @@ ComplexPairTy ComplexExprEmitter::EmitCast(CastKind CK, Expr *Op,
641
649
642
650
ComplexPairTy ComplexExprEmitter::VisitUnaryPlus (const UnaryOperator *E,
643
651
QualType PromotionType) {
644
- QualType promotionTy = PromotionType.isNull ()
645
- ? getPromotionType (E->getSubExpr ()->getType ())
646
- : PromotionType;
652
+ E->hasStoredFPFeatures ();
653
+ QualType promotionTy =
654
+ PromotionType.isNull ()
655
+ ? getPromotionType (E->getStoredFPFeaturesOrDefault (),
656
+ E->getSubExpr ()->getType ())
657
+ : PromotionType;
647
658
ComplexPairTy result = VisitPlus (E, promotionTy);
648
659
if (!promotionTy.isNull ())
649
660
return CGF.EmitUnPromotedValue (result, E->getSubExpr ()->getType ());
@@ -661,9 +672,11 @@ ComplexPairTy ComplexExprEmitter::VisitPlus(const UnaryOperator *E,
661
672
662
673
ComplexPairTy ComplexExprEmitter::VisitUnaryMinus (const UnaryOperator *E,
663
674
QualType PromotionType) {
664
- QualType promotionTy = PromotionType.isNull ()
665
- ? getPromotionType (E->getSubExpr ()->getType ())
666
- : PromotionType;
675
+ QualType promotionTy =
676
+ PromotionType.isNull ()
677
+ ? getPromotionType (E->getStoredFPFeaturesOrDefault (),
678
+ E->getSubExpr ()->getType ())
679
+ : PromotionType;
667
680
ComplexPairTy result = VisitMinus (E, promotionTy);
668
681
if (!promotionTy.isNull ())
669
682
return CGF.EmitUnPromotedValue (result, E->getSubExpr ()->getType ());
@@ -1218,13 +1231,15 @@ EmitCompoundAssignLValue(const CompoundAssignOperator *E,
1218
1231
// __block variables need to have the rhs evaluated first, plus this should
1219
1232
// improve codegen a little.
1220
1233
QualType PromotionTypeCR;
1221
- PromotionTypeCR = getPromotionType (E->getComputationResultType ());
1234
+ PromotionTypeCR = getPromotionType (E->getStoredFPFeaturesOrDefault (),
1235
+ E->getComputationResultType ());
1222
1236
if (PromotionTypeCR.isNull ())
1223
1237
PromotionTypeCR = E->getComputationResultType ();
1224
1238
OpInfo.Ty = PromotionTypeCR;
1225
1239
QualType ComplexElementTy =
1226
1240
OpInfo.Ty ->castAs <ComplexType>()->getElementType ();
1227
- QualType PromotionTypeRHS = getPromotionType (E->getRHS ()->getType ());
1241
+ QualType PromotionTypeRHS = getPromotionType (
1242
+ E->getStoredFPFeaturesOrDefault (), E->getRHS ()->getType ());
1228
1243
1229
1244
// The RHS should have been converted to the computation type.
1230
1245
if (E->getRHS ()->getType ()->isRealFloatingType ()) {
@@ -1252,7 +1267,8 @@ EmitCompoundAssignLValue(const CompoundAssignOperator *E,
1252
1267
1253
1268
// Load from the l-value and convert it.
1254
1269
SourceLocation Loc = E->getExprLoc ();
1255
- QualType PromotionTypeLHS = getPromotionType (E->getComputationLHSType ());
1270
+ QualType PromotionTypeLHS = getPromotionType (
1271
+ E->getStoredFPFeaturesOrDefault (), E->getComputationLHSType ());
1256
1272
if (LHSTy->isAnyComplexType ()) {
1257
1273
ComplexPairTy LHSVal = EmitLoadOfLValue (LHS, Loc);
1258
1274
if (!PromotionTypeLHS.isNull ())
0 commit comments