aboutsummaryrefslogtreecommitdiff
path: root/Sema
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2007-08-27 01:27:54 +0000
committerSteve Naroff <snaroff@apple.com>2007-08-27 01:27:54 +0000
commitf1448a0e4a1e868ff873a8530a61a09cb68666cc (patch)
treefb389669d2f59f0aa3c84b6bd9018661c9475c4b /Sema
parent45a566cfcbec0efd50bc737991bdfcc70e986811 (diff)
Replaced ASTContext::maxComplexType() with ASTContext::getFloatingTypeOfSizeWithinDomain().
Changed Sema::UsualArithmeticConversions to correctly implement complex/float conversions, using maxFloatingType() with getFloatingTypeOfSizeWithinDomain(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41474 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'Sema')
-rw-r--r--Sema/SemaExpr.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp
index a859fe8ab2..cc9a64f726 100644
--- a/Sema/SemaExpr.cpp
+++ b/Sema/SemaExpr.cpp
@@ -811,13 +811,26 @@ QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr,
if (!isCompAssign) promoteExprToType(lhsExpr, rhs);
return rhs;
}
- // Two complex types. Convert the smaller operand to the bigger result.
- if (Context.maxComplexType(lhs, rhs) == lhs) { // convert the rhs
- if (!isCompAssign) promoteExprToType(rhsExpr, lhs);
- return lhs;
+ // This handles complex/complex, complex/float, or float/complex.
+ // When both operands are complex, the shorter operand is converted to the
+ // type of the longer, and that is the type of the result. This corresponds
+ // to what is done when combining two real floating-point operands.
+ // The fun begins when size promotion occur across type domains.
+ // From H&S 6.3.4: When one operand is complex and the other is a real
+ // floating-point type, the less precise type is converted, within it's
+ // real or complex domain, to the precision of the other type. For example,
+ // when combining a "long double" with a "double _Complex", the
+ // "double _Complex" is promoted to "long double _Complex".
+ if (Context.maxFloatingType(lhs, rhs) == lhs) {
+ // The left side is bigger, convert rhs within it's domain.
+ QualType tMax = Context.getFloatingTypeOfSizeWithinDomain(lhs, rhs);
+ if (!isCompAssign) promoteExprToType(rhsExpr, tMax);
+ return tMax;
}
- if (!isCompAssign) promoteExprToType(lhsExpr, rhs); // convert the lhs
- return rhs;
+ // The right side is bigger, convert lhs within it's domain.
+ QualType tMax = Context.getFloatingTypeOfSizeWithinDomain(rhs, lhs);
+ if (!isCompAssign) promoteExprToType(lhsExpr, tMax);
+ return tMax;
}
// Now handle "real" floating types (i.e. float, double, long double).
if (lhs->isRealFloatingType() || rhs->isRealFloatingType()) {