From: Steve Naroff Date: Mon, 27 Aug 2007 21:32:55 +0000 (+0000) Subject: Fix remaining bugs with complex/float promotions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=55fe455efe12c6fd23c096c57df7962c5dc2ff78;p=clang Fix remaining bugs with complex/float promotions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41515 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Sema/SemaExpr.cpp b/Sema/SemaExpr.cpp index 6cabbda8e2..2e949ba22c 100644 --- a/Sema/SemaExpr.cpp +++ b/Sema/SemaExpr.cpp @@ -824,23 +824,32 @@ QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr, int result = Context.compareFloatingType(lhs, rhs); if (result > 0) { // The left side is bigger, convert rhs. - QualType tMax = Context.getFloatingTypeOfSizeWithinDomain(lhs, rhs); - if (!isCompAssign) promoteExprToType(rhsExpr, tMax); - return tMax; - } - if (result < 0) { // The right side is bigger, convert lhs. - QualType tMax = Context.getFloatingTypeOfSizeWithinDomain(rhs, lhs); - if (!isCompAssign) promoteExprToType(lhsExpr, tMax); - return tMax; - } - // The floating point types were ranked equally. - if (lhs->isComplexType()) { // handle "_Complex double, double". - if (!isCompAssign) promoteExprToType(rhsExpr, lhs); - return lhs; + rhs = Context.getFloatingTypeOfSizeWithinDomain(lhs, rhs); + if (!isCompAssign) + promoteExprToType(rhsExpr, rhs); + } else if (result < 0) { // The right side is bigger, convert lhs. + lhs = Context.getFloatingTypeOfSizeWithinDomain(rhs, lhs); + if (!isCompAssign) + promoteExprToType(lhsExpr, lhs); + } + // At this point, lhs and rhs have the same rank/size. Now, make sure the + // domains match. This is a requirement for our implementation, C99 + // does not require this promotion. + if (lhs != rhs) { // Domains don't match, we have complex/float mix. + if (lhs->isRealFloatingType()) { // handle "double, _Complex double". + if (isCompAssign) + 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 right side is complex, handle "double, _Complex double". - if (!isCompAssign) promoteExprToType(lhsExpr, rhs); - return rhs; + // 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). if (lhs->isRealFloatingType() || rhs->isRealFloatingType()) {