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



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39892 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/Type.cpp b/AST/Type.cpp
index 74e4793..0bc058f 100644
--- a/AST/Type.cpp
+++ b/AST/Type.cpp
@@ -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;