[cfe-commits] r39892 - in /cfe/trunk: AST/Type.cpp Sema/SemaExpr.cpp include/clang/AST/Type.h
Chris Lattner
sabre at nondot.org
Sun Jul 15 17:23:25 PDT 2007
Author: lattner
Date: Sun Jul 15 19:23:25 2007
New Revision: 39892
URL: http://llvm.org/viewvc/llvm-project?rev=39892&view=rev
Log:
Now that isPointerType can return a pointer type, avoid stripping off typedef
information in the common case. On this invalid code:
typedef float float4 __attribute__((vector_size(16)));
typedef int int4 __attribute__((vector_size(16)));
void test(float4 a, int4 *result, int i) {
result[i] = a;
}
we now generate:
t.c:5:15: error: incompatible types assigning 'float4' to 'int4'
instead of:
t.c:5:15: error: incompatible types assigning 'float4' to 'int __attribute__((vector_size(16)))'
This implements test/Sema/typedef-retain.c
Modified:
cfe/trunk/AST/Type.cpp
cfe/trunk/Sema/SemaExpr.cpp
cfe/trunk/include/clang/AST/Type.h
Modified: cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Type.cpp?rev=39892&r1=39891&r2=39892&view=diff
==============================================================================
--- cfe/trunk/AST/Type.cpp (original)
+++ cfe/trunk/AST/Type.cpp Sun Jul 15 19:23:25 2007
@@ -60,8 +60,12 @@
return isa<FunctionType>(CanonicalType);
}
-PointerType *Type::isPointerType() const {
- if (PointerType *PTy = dyn_cast<PointerType>(CanonicalType))
+const PointerType *Type::isPointerType() const {
+ // If this is directly a pointer type, return it.
+ if (const PointerType *PTy = dyn_cast<PointerType>(this))
+ return PTy;
+ // If this is a typedef for a pointer type, strip the typedef off.
+ if (const PointerType *PTy = dyn_cast<PointerType>(CanonicalType))
return PTy;
return 0;
}
@@ -90,6 +94,21 @@
return false;
}
+bool Type::isComplexType() const {
+ return isa<ComplexType>(CanonicalType);
+}
+
+const VectorType *Type::isVectorType() const {
+ // Are we directly a vector type?
+ if (const VectorType *VTy = dyn_cast<VectorType>(this))
+ return VTy;
+ // If this is a typedef for a vector type, strip the typedef off.
+ if (const VectorType *VTy = dyn_cast<VectorType>(CanonicalType))
+ return VTy;
+ return 0;
+}
+
+
// C99 6.2.7p1: If both are complete types, then the following additional
// requirements apply...FIXME (handle compatibility across source files).
bool Type::tagTypesAreCompatible(QualType lhs, QualType rhs) {
@@ -289,16 +308,6 @@
return false;
}
-bool Type::isComplexType() const {
- return isa<ComplexType>(CanonicalType);
-}
-
-VectorType *Type::isVectorType() const {
- if (VectorType *VTy = dyn_cast<VectorType>(CanonicalType))
- return VTy;
- return 0;
-}
-
bool Type::isArithmeticType() const {
if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
return BT->getKind() != BuiltinType::Void;
Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=39892&r1=39891&r2=39892&view=diff
==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Sun Jul 15 19:23:25 2007
@@ -294,17 +294,18 @@
// and index from the expression types.
Expr *BaseExpr, *IndexExpr;
QualType ResultType;
- if (PointerType *PTy = LHSTy->isPointerType()) {
+ if (const PointerType *PTy = LHSTy->isPointerType()) {
BaseExpr = LHSExp;
IndexExpr = RHSExp;
// FIXME: need to deal with const...
ResultType = PTy->getPointeeType();
- } else if (PointerType *PTy = RHSTy->isPointerType()) { // uncommon: 123[Ptr]
+ } else if (const PointerType *PTy = RHSTy->isPointerType()) {
+ // Handle the uncommon case of "123[Ptr]".
BaseExpr = RHSExp;
IndexExpr = LHSExp;
// FIXME: need to deal with const...
ResultType = PTy->getPointeeType();
- } else if (VectorType *VTy = LHSTy->isVectorType()) { // vectors: V[123]
+ } else if (const VectorType *VTy = LHSTy->isVectorType()) { // vectors: V[123]
BaseExpr = LHSExp;
IndexExpr = RHSExp;
// FIXME: need to deal with const...
Modified: cfe/trunk/include/clang/AST/Type.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=39892&r1=39891&r2=39892&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sun Jul 15 19:23:25 2007
@@ -230,11 +230,11 @@
bool isArithmeticType() const; // C99 6.2.5p18 (integer + floating)
/// Vector types
- VectorType *isVectorType() const; // GCC vector type.
+ const VectorType *isVectorType() const; // GCC vector type.
/// Derived types (C99 6.2.5p20). isFunctionType() is also a derived type.
bool isDerivedType() const;
- PointerType *isPointerType() const;
+ const PointerType *isPointerType() const;
bool isReferenceType() const;
bool isArrayType() const;
bool isStructureType() const;
More information about the cfe-commits
mailing list