Skip to content

Commit

Permalink
Fix getStoredFOFeaturesOrDefault function.
Browse files Browse the repository at this point in the history
  • Loading branch information
zahiraam committed Jul 16, 2024
1 parent 26adc4f commit a48cda1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
19 changes: 19 additions & 0 deletions clang/include/clang/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2333,6 +2333,11 @@ class UnaryOperator final
return getTrailingFPFeatures();
}

/// Get the store FPOptionsOverride or default if not stored.
FPOptionsOverride getStoredFPFeaturesOrDefault() const {
return hasStoredFPFeatures() ? getStoredFPFeatures() : FPOptionsOverride();
}

protected:
/// Set FPFeatures in trailing storage, used by Serialization & ASTImporter.
void setStoredFPFeatures(FPOptionsOverride F) { getTrailingFPFeatures() = F; }
Expand Down Expand Up @@ -3096,6 +3101,11 @@ class CallExpr : public Expr {
*getTrailingFPFeatures() = F;
}

/// Get the store FPOptionsOverride or default if not stored.
FPOptionsOverride getStoredFPFeaturesOrDefault() const {
return hasStoredFPFeatures() ? getStoredFPFeatures() : FPOptionsOverride();
}

/// Get the FP features status of this operator. Only meaningful for
/// operations on floating point types.
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const {
Expand Down Expand Up @@ -3592,6 +3602,11 @@ class CastExpr : public Expr {
return *getTrailingFPFeatures();
}

/// Get the store FPOptionsOverride or default if not stored.
FPOptionsOverride getStoredFPFeaturesOrDefault() const {
return hasStoredFPFeatures() ? getStoredFPFeatures() : FPOptionsOverride();
}

/// Get the FP features status of this operation. Only meaningful for
/// operations on floating point types.
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const {
Expand Down Expand Up @@ -4038,6 +4053,10 @@ class BinaryOperator : public Expr {
assert(BinaryOperatorBits.HasFPFeatures);
*getTrailingFPFeatures() = F;
}
/// Get the store FPOptionsOverride or default if not stored.
FPOptionsOverride getStoredFPFeaturesOrDefault() const {
return hasStoredFPFeatures() ? getStoredFPFeatures() : FPOptionsOverride();
}

/// Get the FP features status of this operator. Only meaningful for
/// operations on floating point types.
Expand Down
5 changes: 5 additions & 0 deletions clang/include/clang/AST/Stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,11 @@ class CompoundStmt final
return *getTrailingObjects<FPOptionsOverride>();
}

/// Get the store FPOptionsOverride or default if not stored.
FPOptionsOverride getStoredFPFeaturesOrDefault() const {
return hasStoredFPFeatures() ? getStoredFPFeatures() : FPOptionsOverride();
}

using body_iterator = Stmt **;
using body_range = llvm::iterator_range<body_iterator>;

Expand Down
22 changes: 8 additions & 14 deletions clang/lib/CodeGen/CGExprComplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,17 +352,10 @@ class ComplexExprEmitter
return QualType();
}

template <typename T>
FPOptionsOverride getStoredFPFeaturesOrDefault(const T *E,
const CodeGenFunction &CGF) {
return E->hasStoredFPFeatures() ? E->getStoredFPFeatures()
: FPOptionsOverride();
}

#define HANDLEBINOP(OP) \
ComplexPairTy VisitBin##OP(const BinaryOperator *E) { \
QualType promotionTy = getPromotionType( \
getStoredFPFeaturesOrDefault(E, CGF), E->getType(), \
E->getStoredFPFeaturesOrDefault(), E->getType(), \
(E->getOpcode() == BinaryOperatorKind::BO_Div) ? true : false); \
ComplexPairTy result = EmitBin##OP(EmitBinOps(E, promotionTy)); \
if (!promotionTy.isNull()) \
Expand Down Expand Up @@ -656,9 +649,10 @@ ComplexPairTy ComplexExprEmitter::EmitCast(CastKind CK, Expr *Op,

ComplexPairTy ComplexExprEmitter::VisitUnaryPlus(const UnaryOperator *E,
QualType PromotionType) {
E->hasStoredFPFeatures();
QualType promotionTy =
PromotionType.isNull()
? getPromotionType(getStoredFPFeaturesOrDefault(E, CGF),
? getPromotionType(E->getStoredFPFeaturesOrDefault(),
E->getSubExpr()->getType())
: PromotionType;
ComplexPairTy result = VisitPlus(E, promotionTy);
Expand All @@ -677,10 +671,10 @@ ComplexPairTy ComplexExprEmitter::VisitPlus(const UnaryOperator *E,
}

ComplexPairTy ComplexExprEmitter::VisitUnaryMinus(const UnaryOperator *E,
QualType PromotionType) {
QualType PromotionType) {
QualType promotionTy =
PromotionType.isNull()
? getPromotionType(getStoredFPFeaturesOrDefault(E, CGF),
? getPromotionType(E->getStoredFPFeaturesOrDefault(),
E->getSubExpr()->getType())
: PromotionType;
ComplexPairTy result = VisitMinus(E, promotionTy);
Expand Down Expand Up @@ -1242,15 +1236,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(getStoredFPFeaturesOrDefault(E, CGF),
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(
getStoredFPFeaturesOrDefault(E, CGF), E->getRHS()->getType());
E->getStoredFPFeaturesOrDefault(), E->getRHS()->getType());

// The RHS should have been converted to the computation type.
if (E->getRHS()->getType()->isRealFloatingType()) {
Expand Down Expand Up @@ -1279,7 +1273,7 @@ EmitCompoundAssignLValue(const CompoundAssignOperator *E,
// Load from the l-value and convert it.
SourceLocation Loc = E->getExprLoc();
QualType PromotionTypeLHS = getPromotionType(
getStoredFPFeaturesOrDefault(E, CGF), E->getComputationLHSType());
E->getStoredFPFeaturesOrDefault(), E->getComputationLHSType());
if (LHSTy->isAnyComplexType()) {
ComplexPairTy LHSVal = EmitLoadOfLValue(LHS, Loc);
if (!PromotionTypeLHS.isNull())
Expand Down

0 comments on commit a48cda1

Please sign in to comment.