[cfe-commits] r60862 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/complex-promotion.c

Anders Carlsson andersca at mac.com
Wed Dec 10 15:30:10 PST 2008


Author: andersca
Date: Wed Dec 10 17:30:05 2008
New Revision: 60862

URL: http://llvm.org/viewvc/llvm-project?rev=60862&view=rev
Log:
Make sure to promote expressions of the form (floating point + complex integer) correctly, to (complex floating point + complex floating point)

Added:
    cfe/trunk/test/Sema/complex-promotion.c
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=60862&r1=60861&r2=60862&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Dec 10 17:30:05 2008
@@ -189,14 +189,22 @@
   // Now handle "real" floating types (i.e. float, double, long double).
   if (lhs->isRealFloatingType() || rhs->isRealFloatingType()) {
     // if we have an integer operand, the result is the real floating type.
-    if (rhs->isIntegerType() || rhs->isComplexIntegerType()) { 
+    if (rhs->isIntegerType()) {
       // convert rhs to the lhs floating point type.
       return lhs;
     }
-    if (lhs->isIntegerType() || lhs->isComplexIntegerType()) { 
+    if (rhs->isComplexIntegerType()) {
+      // convert rhs to the complex floating point type.
+      return Context.getComplexType(lhs);
+    }
+    if (lhs->isIntegerType()) {
       // convert lhs to the rhs floating point type.
       return rhs;
     }
+    if (lhs->isComplexIntegerType()) { 
+      // convert lhs to the complex floating point type.
+      return Context.getComplexType(rhs);
+    }
     // We have two real floating types, float/complex combos were handled above.
     // Convert the smaller operand to the bigger result.
     int result = Context.getFloatingTypeOrder(lhs, rhs);

Added: cfe/trunk/test/Sema/complex-promotion.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/complex-promotion.c?rev=60862&view=auto

==============================================================================
--- cfe/trunk/test/Sema/complex-promotion.c (added)
+++ cfe/trunk/test/Sema/complex-promotion.c Wed Dec 10 17:30:05 2008
@@ -0,0 +1,11 @@
+// RUN: clang %s -verify -fsyntax-only
+
+float a;
+
+int b[__builtin_classify_type(a + 1i) == 9 ? 1 : -1];
+int c[__builtin_classify_type(1i + a) == 9 ? 1 : -1];
+
+double d;
+__typeof__ (d + 1i) e;
+
+int f[sizeof(e) == 2 * sizeof(double) ? 1 : -1];





More information about the cfe-commits mailing list