diff options
| author | Steve Naroff <snaroff@apple.com> | 2008-01-15 22:21:49 +0000 |
|---|---|---|
| committer | Steve Naroff <snaroff@apple.com> | 2008-01-15 22:21:49 +0000 |
| commit | abefc391dd699bff1d1aa41ea0a8b26647b71a18 (patch) | |
| tree | 2e439046d1ec0cf0dc5483bebc828ab62e4dffad /clang | |
| parent | 51a09143c2faca1f28c666305e3e6bd442dba8ff (diff) | |
| download | bcm5719-llvm-abefc391dd699bff1d1aa41ea0a8b26647b71a18.tar.gz bcm5719-llvm-abefc391dd699bff1d1aa41ea0a8b26647b71a18.zip | |
Finish up handling all permutations of "complex int" (in Sema::UsualArithmeticConversions()).
A FIXME remains to verify the conversion rules are consistent with GCC.
Thanks to Eli for the new/improved test case...
llvm-svn: 46022
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/Sema/SemaExpr.cpp | 14 | ||||
| -rw-r--r-- | clang/test/Sema/complex-int.c | 20 |
2 files changed, 29 insertions, 5 deletions
diff --git a/clang/Sema/SemaExpr.cpp b/clang/Sema/SemaExpr.cpp index c5a9bff5fe8..f8053a4fbe8 100644 --- a/clang/Sema/SemaExpr.cpp +++ b/clang/Sema/SemaExpr.cpp @@ -927,6 +927,7 @@ Expr *Sema::UsualUnaryConversions(Expr *&Expr) { /// binary operators (C99 6.3.1.8). If both operands aren't arithmetic, this /// routine returns the first non-arithmetic type found. The client is /// responsible for emitting appropriate error diagnostics. +/// FIXME: verify the conversion rules for "complex int" are consistent with GCC. QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr, bool isCompAssign) { if (!isCompAssign) { @@ -952,11 +953,13 @@ QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr, // Handle complex types first (C99 6.3.1.8p1). if (lhs->isComplexType() || rhs->isComplexType()) { // if we have an integer operand, the result is the complex type. - if (rhs->isIntegerType()) { // convert the rhs to the lhs complex type. + if (rhs->isIntegerType() || rhs->isComplexIntegerType()) { + // convert the rhs to the lhs complex type. if (!isCompAssign) promoteExprToType(rhsExpr, lhs); return lhs; } - if (lhs->isIntegerType()) { // convert the lhs to the rhs complex type. + if (lhs->isIntegerType() || lhs->isComplexIntegerType()) { + // convert the lhs to the rhs complex type. if (!isCompAssign) promoteExprToType(lhsExpr, rhs); return rhs; } @@ -1000,11 +1003,13 @@ QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr, // 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()) { // convert rhs to the lhs floating point type. + if (rhs->isIntegerType() || rhs->isComplexIntegerType()) { + // convert rhs to the lhs floating point type. if (!isCompAssign) promoteExprToType(rhsExpr, lhs); return lhs; } - if (lhs->isIntegerType()) { // convert lhs to the rhs floating point type. + if (lhs->isIntegerType() || lhs->isComplexIntegerType()) { + // convert lhs to the rhs floating point type. if (!isCompAssign) promoteExprToType(lhsExpr, rhs); return rhs; } @@ -1024,7 +1029,6 @@ QualType Sema::UsualArithmeticConversions(Expr *&lhsExpr, Expr *&rhsExpr, } if (lhs->isComplexIntegerType() || rhs->isComplexIntegerType()) { // Handle GCC complex int extension. - // FIXME: need to verify these conversion rules are consistent with GCC. const ComplexType *lhsComplexInt = lhs->getAsComplexIntegerType(); const ComplexType *rhsComplexInt = rhs->getAsComplexIntegerType(); diff --git a/clang/test/Sema/complex-int.c b/clang/test/Sema/complex-int.c index 1e2f8cf4ed2..d7244d113bb 100644 --- a/clang/test/Sema/complex-int.c +++ b/clang/test/Sema/complex-int.c @@ -21,3 +21,23 @@ switch (arr) { // expected-error{{statement requires expression of integer type } } +void Tester() { +__complex short a1; +__complex int a2; +__complex float a3; +__complex double a4; +short a5; +int a6; +float a7; +double a8; +#define TestPair(m,n) int x##m##n = a##m+a##n; +#define TestPairs(m) TestPair(m,1) TestPair(m,2) \ + TestPair(m,3) TestPair(m,4) \ + TestPair(m,5) TestPair(m,6) \ + TestPair(m,7) TestPair(m,8) +TestPairs(1); TestPairs(2); +TestPairs(3); TestPairs(4); +TestPairs(5); TestPairs(6); +TestPairs(7); TestPairs(8); +} + |

