[cfe-commits] r46005 - in /cfe/trunk: AST/Type.cpp Sema/SemaExpr.cpp include/clang/AST/Type.h test/Sema/complex-int.c
Steve Naroff
snaroff at apple.com
Tue Jan 15 11:36:12 PST 2008
Author: snaroff
Date: Tue Jan 15 13:36:10 2008
New Revision: 46005
URL: http://llvm.org/viewvc/llvm-project?rev=46005&view=rev
Log:
- Change Type::isComplexType() to exlude GCC's complex integer extension. In general, we will keep the lowest level Type predicates "pure" (i.e. true to the C99 spec).
- Modify Sema::UsualArithmeticConversions() to work with the new definition of Type::isComplexType().
This is a nice cleanup and also fixes a bug submitted by Eli (which I've added to the test suite).
Modified:
cfe/trunk/AST/Type.cpp
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/test/Sema/complex-int.c
Modified: cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Type.cpp?rev=46005&r1=46004&r2=46005&view=diff
==============================================================================
--- cfe/trunk/AST/Type.cpp (original)
+++ cfe/trunk/AST/Type.cpp Tue Jan 15 13:36:10 2008
@@ -74,7 +74,9 @@
}
bool Type::isComplexType() const {
- return isa<ComplexType>(CanonicalType);
+ if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
+ return CT->getElementType()->isFloatingType();
+ return false;
}
bool Type::isComplexIntegerType() const {
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=46005&r1=46004&r2=46005&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Tue Jan 15 13:36:10 2008
@@ -951,25 +951,12 @@
// Handle complex types first (C99 6.3.1.8p1).
if (lhs->isComplexType() || rhs->isComplexType()) {
- // Handle GCC complex int extension first.
- // FIXME: need to verify these conversion rules are consistent with GCC.
- const ComplexType *lhsComplexInt = lhs->getAsComplexIntegerType();
- const ComplexType *rhsComplexInt = rhs->getAsComplexIntegerType();
-
- if (lhsComplexInt && rhsComplexInt) {
- if (Context.maxIntegerType(lhsComplexInt->getElementType(),
- rhsComplexInt->getElementType()) == lhs) {
- if (!isCompAssign) promoteExprToType(rhsExpr, lhs); // convert the rhs
- return lhs;
- }
- if (!isCompAssign) promoteExprToType(lhsExpr, rhs); // convert the lhs
- return rhs;
- } else if (lhsComplexInt && rhs->isIntegerType()) {
- // convert the rhs to the lhs complex type.
+ // if we have an integer operand, the result is the complex type.
+ if (rhs->isIntegerType()) { // convert the rhs to the lhs complex type.
if (!isCompAssign) promoteExprToType(rhsExpr, lhs);
return lhs;
- } else if (rhsComplexInt && lhs->isIntegerType()) {
- // convert the lhs to the rhs complex type.
+ }
+ if (lhs->isIntegerType()) { // convert the lhs to the rhs complex type.
if (!isCompAssign) promoteExprToType(lhsExpr, rhs);
return rhs;
}
@@ -1035,6 +1022,30 @@
}
assert(0 && "Sema::UsualArithmeticConversions(): illegal float comparison");
}
+ 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();
+
+ if (lhsComplexInt && rhsComplexInt) {
+ if (Context.maxIntegerType(lhsComplexInt->getElementType(),
+ rhsComplexInt->getElementType()) == lhs) {
+ if (!isCompAssign) promoteExprToType(rhsExpr, lhs); // convert the rhs
+ return lhs;
+ }
+ if (!isCompAssign) promoteExprToType(lhsExpr, rhs); // convert the lhs
+ return rhs;
+ } else if (lhsComplexInt && rhs->isIntegerType()) {
+ // convert the rhs to the lhs complex type.
+ if (!isCompAssign) promoteExprToType(rhsExpr, lhs);
+ return lhs;
+ } else if (rhsComplexInt && lhs->isIntegerType()) {
+ // convert the lhs to the rhs complex type.
+ if (!isCompAssign) promoteExprToType(lhsExpr, rhs);
+ return rhs;
+ }
+ }
// Finally, we have two differing integer types.
if (Context.maxIntegerType(lhs, rhs) == lhs) { // convert the rhs
if (!isCompAssign) promoteExprToType(rhsExpr, lhs);
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=46005&r1=46004&r2=46005&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Tue Jan 15 13:36:10 2008
@@ -276,6 +276,8 @@
/// Floating point categories.
bool isRealFloatingType() const; // C99 6.2.5p10 (float, double, long double)
+ /// isComplexType() does *not* include complex integers (a GCC extension).
+ /// isComplexIntegerType() can be used to test for complex integers.
bool isComplexType() const; // C99 6.2.5p11 (complex)
bool isFloatingType() const; // C99 6.2.5p11 (real floating + complex)
bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
Modified: cfe/trunk/test/Sema/complex-int.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/complex-int.c?rev=46005&r1=46004&r2=46005&view=diff
==============================================================================
--- cfe/trunk/test/Sema/complex-int.c (original)
+++ cfe/trunk/test/Sema/complex-int.c Tue Jan 15 13:36:10 2008
@@ -7,6 +7,7 @@
__complex__ signed yy;
__complex__ int result;
int ii;
+int aa = 1 + 1.0iF;
result = arr*ii;
result = ii*brr;
More information about the cfe-commits
mailing list