forked from OSchip/llvm-project
Fix remaining bugs with complex/float promotions.
llvm-svn: 41515
This commit is contained in:
parent
9e248870e5
commit
e31313d792
|
@ -824,23 +824,32 @@ QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr,
|
||||||
int result = Context.compareFloatingType(lhs, rhs);
|
int result = Context.compareFloatingType(lhs, rhs);
|
||||||
|
|
||||||
if (result > 0) { // The left side is bigger, convert rhs.
|
if (result > 0) { // The left side is bigger, convert rhs.
|
||||||
QualType tMax = Context.getFloatingTypeOfSizeWithinDomain(lhs, rhs);
|
rhs = Context.getFloatingTypeOfSizeWithinDomain(lhs, rhs);
|
||||||
if (!isCompAssign) promoteExprToType(rhsExpr, tMax);
|
if (!isCompAssign)
|
||||||
return tMax;
|
promoteExprToType(rhsExpr, rhs);
|
||||||
|
} else if (result < 0) { // The right side is bigger, convert lhs.
|
||||||
|
lhs = Context.getFloatingTypeOfSizeWithinDomain(rhs, lhs);
|
||||||
|
if (!isCompAssign)
|
||||||
|
promoteExprToType(lhsExpr, lhs);
|
||||||
}
|
}
|
||||||
if (result < 0) { // The right side is bigger, convert lhs.
|
// At this point, lhs and rhs have the same rank/size. Now, make sure the
|
||||||
QualType tMax = Context.getFloatingTypeOfSizeWithinDomain(rhs, lhs);
|
// domains match. This is a requirement for our implementation, C99
|
||||||
if (!isCompAssign) promoteExprToType(lhsExpr, tMax);
|
// does not require this promotion.
|
||||||
return tMax;
|
if (lhs != rhs) { // Domains don't match, we have complex/float mix.
|
||||||
}
|
if (lhs->isRealFloatingType()) { // handle "double, _Complex double".
|
||||||
// The floating point types were ranked equally.
|
if (isCompAssign)
|
||||||
if (lhs->isComplexType()) { // handle "_Complex double, double".
|
|
||||||
if (!isCompAssign) promoteExprToType(rhsExpr, lhs);
|
|
||||||
return lhs;
|
|
||||||
}
|
|
||||||
// The right side is complex, handle "double, _Complex double".
|
|
||||||
if (!isCompAssign) promoteExprToType(lhsExpr, rhs);
|
|
||||||
return rhs;
|
return rhs;
|
||||||
|
promoteExprToType(lhsExpr, rhs);
|
||||||
|
} else { // handle "_Complex double, double".
|
||||||
|
if (isCompAssign)
|
||||||
|
return lhs;
|
||||||
|
promoteExprToType(rhsExpr, lhs);
|
||||||
|
}
|
||||||
|
// Both expressions now have the same rank/domain.
|
||||||
|
return lhsExpr->getType();
|
||||||
|
}
|
||||||
|
// The domain/size match, simply return lhs (which may have been converted).
|
||||||
|
return lhs;
|
||||||
}
|
}
|
||||||
// Now handle "real" floating types (i.e. float, double, long double).
|
// Now handle "real" floating types (i.e. float, double, long double).
|
||||||
if (lhs->isRealFloatingType() || rhs->isRealFloatingType()) {
|
if (lhs->isRealFloatingType() || rhs->isRealFloatingType()) {
|
||||||
|
|
Loading…
Reference in New Issue