]> granicus.if.org Git - clang/commitdiff
Make sure to promote expressions of the form (floating point + complex integer) corre...
authorAnders Carlsson <andersca@mac.com>
Wed, 10 Dec 2008 23:30:05 +0000 (23:30 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 10 Dec 2008 23:30:05 +0000 (23:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60862 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/complex-promotion.c [new file with mode: 0644]

index 3870f0736ec22df8982a444a0dea74c831cbe7e0..b2542542417723451b0dcf6f6f56312d80696bd6 100644 (file)
@@ -189,14 +189,22 @@ QualType Sema::UsualArithmeticConversionsType(QualType lhs, QualType rhs) {
   // 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);
diff --git a/test/Sema/complex-promotion.c b/test/Sema/complex-promotion.c
new file mode 100644 (file)
index 0000000..a9b557d
--- /dev/null
@@ -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];