]> granicus.if.org Git - clang/commitdiff
Fix remaining bugs with complex/float promotions.
authorSteve Naroff <snaroff@apple.com>
Mon, 27 Aug 2007 21:32:55 +0000 (21:32 +0000)
committerSteve Naroff <snaroff@apple.com>
Mon, 27 Aug 2007 21:32:55 +0000 (21:32 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41515 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaExpr.cpp

index 6cabbda8e2e28609d3e0e1490bdc4463ac05bf8e..2e949ba22c0259d79cca352e53b0ab9f08fcacb3 100644 (file)
@@ -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()) {