diff options
| author | Zahira Ammarguellat <zahira.ammarguellat@intel.com> | 2024-07-17 14:05:51 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-17 14:05:51 -0400 |
| commit | 321a0c00425adeab84bce657cac85ae4634df910 (patch) | |
| tree | ec6953cd68ce7b54085b49ccae86582003239a82 /clang/lib/CodeGen/CGExprComplex.cpp | |
| parent | e3b8d3649789a59e54a32998780fb64d0663284c (diff) | |
The pragma STDC CX_LIMITED_RANGE ON should have precedence. (#98520)
The `pragma STDC CX_LIMITED_RANGE` should have precedence over the
command line `-fcomplex-arithmetic`.
Diffstat (limited to 'clang/lib/CodeGen/CGExprComplex.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CGExprComplex.cpp | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp index 000d4ff5c069..4d45f6d64c1c 100644 --- a/clang/lib/CodeGen/CGExprComplex.cpp +++ b/clang/lib/CodeGen/CGExprComplex.cpp @@ -328,12 +328,20 @@ public: } } - QualType getPromotionType(QualType Ty, bool IsDivOpCode = false) { + QualType getPromotionType(FPOptionsOverride Features, QualType Ty, + bool IsDivOpCode = false) { if (auto *CT = Ty->getAs<ComplexType>()) { QualType ElementType = CT->getElementType(); - if (IsDivOpCode && ElementType->isFloatingType() && - CGF.getLangOpts().getComplexRange() == - LangOptions::ComplexRangeKind::CX_Promoted) + bool IsFloatingType = ElementType->isFloatingType(); + bool IsComplexRangePromoted = CGF.getLangOpts().getComplexRange() == + LangOptions::ComplexRangeKind::CX_Promoted; + bool HasNoComplexRangeOverride = !Features.hasComplexRangeOverride(); + bool HasMatchingComplexRange = Features.hasComplexRangeOverride() && + Features.getComplexRangeOverride() == + CGF.getLangOpts().getComplexRange(); + + if (IsDivOpCode && IsFloatingType && IsComplexRangePromoted && + (HasNoComplexRangeOverride || HasMatchingComplexRange)) return HigherPrecisionTypeForComplexArithmetic(ElementType, IsDivOpCode); if (ElementType.UseExcessPrecision(CGF.getContext())) @@ -347,7 +355,7 @@ public: #define HANDLEBINOP(OP) \ ComplexPairTy VisitBin##OP(const BinaryOperator *E) { \ QualType promotionTy = getPromotionType( \ - E->getType(), \ + E->getStoredFPFeaturesOrDefault(), E->getType(), \ (E->getOpcode() == BinaryOperatorKind::BO_Div) ? true : false); \ ComplexPairTy result = EmitBin##OP(EmitBinOps(E, promotionTy)); \ if (!promotionTy.isNull()) \ @@ -641,9 +649,12 @@ ComplexPairTy ComplexExprEmitter::EmitCast(CastKind CK, Expr *Op, ComplexPairTy ComplexExprEmitter::VisitUnaryPlus(const UnaryOperator *E, QualType PromotionType) { - QualType promotionTy = PromotionType.isNull() - ? getPromotionType(E->getSubExpr()->getType()) - : PromotionType; + E->hasStoredFPFeatures(); + QualType promotionTy = + PromotionType.isNull() + ? getPromotionType(E->getStoredFPFeaturesOrDefault(), + E->getSubExpr()->getType()) + : PromotionType; ComplexPairTy result = VisitPlus(E, promotionTy); if (!promotionTy.isNull()) return CGF.EmitUnPromotedValue(result, E->getSubExpr()->getType()); @@ -661,9 +672,11 @@ ComplexPairTy ComplexExprEmitter::VisitPlus(const UnaryOperator *E, ComplexPairTy ComplexExprEmitter::VisitUnaryMinus(const UnaryOperator *E, QualType PromotionType) { - QualType promotionTy = PromotionType.isNull() - ? getPromotionType(E->getSubExpr()->getType()) - : PromotionType; + QualType promotionTy = + PromotionType.isNull() + ? getPromotionType(E->getStoredFPFeaturesOrDefault(), + E->getSubExpr()->getType()) + : PromotionType; ComplexPairTy result = VisitMinus(E, promotionTy); if (!promotionTy.isNull()) return CGF.EmitUnPromotedValue(result, E->getSubExpr()->getType()); @@ -1218,13 +1231,15 @@ EmitCompoundAssignLValue(const CompoundAssignOperator *E, // __block variables need to have the rhs evaluated first, plus this should // improve codegen a little. QualType PromotionTypeCR; - PromotionTypeCR = getPromotionType(E->getComputationResultType()); + PromotionTypeCR = getPromotionType(E->getStoredFPFeaturesOrDefault(), + E->getComputationResultType()); if (PromotionTypeCR.isNull()) PromotionTypeCR = E->getComputationResultType(); OpInfo.Ty = PromotionTypeCR; QualType ComplexElementTy = OpInfo.Ty->castAs<ComplexType>()->getElementType(); - QualType PromotionTypeRHS = getPromotionType(E->getRHS()->getType()); + QualType PromotionTypeRHS = getPromotionType( + E->getStoredFPFeaturesOrDefault(), E->getRHS()->getType()); // The RHS should have been converted to the computation type. if (E->getRHS()->getType()->isRealFloatingType()) { @@ -1252,7 +1267,8 @@ EmitCompoundAssignLValue(const CompoundAssignOperator *E, // Load from the l-value and convert it. SourceLocation Loc = E->getExprLoc(); - QualType PromotionTypeLHS = getPromotionType(E->getComputationLHSType()); + QualType PromotionTypeLHS = getPromotionType( + E->getStoredFPFeaturesOrDefault(), E->getComputationLHSType()); if (LHSTy->isAnyComplexType()) { ComplexPairTy LHSVal = EmitLoadOfLValue(LHS, Loc); if (!PromotionTypeLHS.isNull()) |
