[cfe-commits] r45992 - 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
Mon Jan 14 17:42:00 PST 2008
Author: snaroff
Date: Mon Jan 14 19:41:59 2008
New Revision: 45992
URL: http://llvm.org/viewvc/llvm-project?rev=45992&view=rev
Log:
Rework commit r45976, which was incorrect.
- Add Type::isComplexIntegerType(), Type::getAsComplexIntegerType().
- Don't inlude complex types with Type::isIntegerType(), which is too general.
- Use the new predicates in Sema::UsualArithmeticConversions() to recognize/convert the types.
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=45992&r1=45991&r2=45992&view=diff
==============================================================================
--- cfe/trunk/AST/Type.cpp (original)
+++ cfe/trunk/AST/Type.cpp Mon Jan 14 19:41:59 2008
@@ -77,6 +77,29 @@
return isa<ComplexType>(CanonicalType);
}
+bool Type::isComplexIntegerType() const {
+ // Check for GCC complex integer extension.
+ if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
+ return CT->getElementType()->isIntegerType();
+ return false;
+}
+
+const ComplexType *Type::getAsComplexIntegerType() const {
+ // Are we directly a complex type?
+ if (const ComplexType *CTy = dyn_cast<ComplexType>(this)) {
+ if (CTy->getElementType()->isIntegerType())
+ return CTy;
+ }
+ // If the canonical form of this type isn't the right kind, reject it.
+ const ComplexType *CTy = dyn_cast<ComplexType>(CanonicalType);
+ if (!CTy || !CTy->getElementType()->isIntegerType())
+ return 0;
+
+ // If this is a typedef for a complex type, strip the typedef off without
+ // losing all typedef information.
+ return getDesugaredType()->getAsComplexIntegerType();
+}
+
/// getDesugaredType - Return the specified type with any "sugar" removed from
/// type type. This takes off typedefs, typeof's etc. If the outer level of
/// the type is already concrete, it returns it unmodified. This is similar
@@ -310,9 +333,6 @@
if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
if (TT->getDecl()->getKind() == Decl::Enum)
return true;
- // Check for GCC complex integer extension.
- if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
- return CT->getElementType()->isIntegerType();
if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
return VT->getElementType()->isIntegerType();
return false;
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=45992&r1=45991&r2=45992&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Mon Jan 14 19:41:59 2008
@@ -951,12 +951,25 @@
// 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.
+ // 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 (!isCompAssign) promoteExprToType(rhsExpr, lhs);
return lhs;
- }
- if (lhs->isIntegerType()) { // convert the lhs to the rhs complex type.
+ } else if (rhsComplexInt && lhs->isIntegerType()) {
+ // convert the lhs to the rhs complex type.
if (!isCompAssign) promoteExprToType(lhsExpr, rhs);
return rhs;
}
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=45992&r1=45991&r2=45992&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Jan 14 19:41:59 2008
@@ -291,7 +291,8 @@
bool isArrayType() const;
bool isRecordType() const;
bool isStructureType() const;
- bool isUnionType() const;
+ bool isUnionType() const;
+ bool isComplexIntegerType() const; // GCC complex int type.
bool isVectorType() const; // GCC vector type.
bool isOCUVectorType() const; // OCU vector type.
bool isObjCInterfaceType() const; // includes conforming protocol type
@@ -313,6 +314,7 @@
const RecordType *getAsUnionType() const;
const VectorType *getAsVectorType() const; // GCC vector type.
const ComplexType *getAsComplexType() const;
+ const ComplexType *getAsComplexIntegerType() const; // GCC complex int type.
const OCUVectorType *getAsOCUVectorType() const; // OCU vector type.
/// getDesugaredType - Return the specified type with any "sugar" removed from
Modified: cfe/trunk/test/Sema/complex-int.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/complex-int.c?rev=45992&r1=45991&r2=45992&view=diff
==============================================================================
--- cfe/trunk/test/Sema/complex-int.c (original)
+++ cfe/trunk/test/Sema/complex-int.c Mon Jan 14 19:41:59 2008
@@ -5,10 +5,18 @@
__complex__ short brr;
__complex__ unsigned xx;
__complex__ signed yy;
-
__complex__ int result;
+int ii;
+
+result = arr*ii;
+result = ii*brr;
result = arr*brr;
result = xx*yy;
+
+switch (arr) { // expected-error{{statement requires expression of integer type ('_Complex int' invalid)}}
+ case brr: ; // expected-error{{case label does not reduce to an integer constant}}
+ case xx: ; // expected-error{{case label does not reduce to an integer constant}}
+}
}
More information about the cfe-commits
mailing list