some more minor asqualtype bugs.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62064 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index 9c6e036..d7c821f 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -163,11 +163,14 @@
     return 0;
   }
   
-  // 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())
+  // If the canonical form of this type isn't what we want, reject it.
+  if (!isa<ComplexType>(CanonicalType)) {
+    // Look through type qualifiers (e.g. ASQualType's).
+    if (isa<ComplexType>(CanonicalType.getUnqualifiedType()))
+      return CanonicalType.getUnqualifiedType()->getAsComplexIntegerType();
     return 0;
-
+  }
+  
   // If this is a typedef for a complex type, strip the typedef off without
   // losing all typedef information.
   return getDesugaredType()->getAsComplexIntegerType();
@@ -180,7 +183,7 @@
 
   // If the canonical form of this type isn't a builtin type, reject it.
   if (!isa<BuiltinType>(CanonicalType)) {
-    // Look through type qualifiers
+    // Look through type qualifiers (e.g. ASQualType's).
     if (isa<BuiltinType>(CanonicalType.getUnqualifiedType()))
       return CanonicalType.getUnqualifiedType()->getAsBuiltinType();
     return 0;
@@ -256,8 +259,12 @@
     return PTy;
   
   // If the canonical form of this type isn't the right kind, reject it.
-  if (!isa<BlockPointerType>(CanonicalType))
+  if (!isa<BlockPointerType>(CanonicalType)) {
+    // Look through type qualifiers
+    if (isa<BlockPointerType>(CanonicalType.getUnqualifiedType()))
+      return CanonicalType.getUnqualifiedType()->getAsBlockPointerType();
     return 0;
+  }
   
   // If this is a typedef for a block pointer type, strip the typedef off 
   // without losing all typedef information.
@@ -295,14 +302,14 @@
     return T->isVariablyModifiedType();
 
   // A pointer can point to a variably modified type
-  if (const PointerType* PT = getAsPointerType())
+  if (const PointerType *PT = getAsPointerType())
     return PT->getPointeeType()->isVariablyModifiedType();
 
   // A function can return a variably modified type
   // This one isn't completely obvious, but it follows from the
   // definition in C99 6.7.5p3. Because of this rule, it's
   // illegal to declare a function returning a variably modified type.
-  if (const FunctionType* FT = getAsFunctionType())
+  if (const FunctionType *FT = getAsFunctionType())
     return FT->getResultType()->isVariablyModifiedType();
 
   return false;
@@ -434,14 +441,15 @@
 
 const ObjCInterfaceType *Type::getAsObjCInterfaceType() const {
   // There is no sugar for ObjCInterfaceType's, just return the canonical
-  // type pointer if it is the right class.
+  // type pointer if it is the right class.  There is no typedef information to
+  // return and these cannot be Address-space qualified.
   return dyn_cast<ObjCInterfaceType>(CanonicalType);
 }
 
 const ObjCQualifiedInterfaceType *
 Type::getAsObjCQualifiedInterfaceType() const {
-  // There is no sugar for ObjCQualifiedInterfaceType's, just return the canonical
-  // type pointer if it is the right class.
+  // There is no sugar for ObjCQualifiedInterfaceType's, just return the
+  // canonical type pointer if it is the right class.
   return dyn_cast<ObjCQualifiedInterfaceType>(CanonicalType);
 }
 
@@ -454,6 +462,7 @@
 const TemplateTypeParmType *Type::getAsTemplateTypeParmType() const {
   // There is no sugar for template type parameters, so just return
   // the canonical type pointer if it is the right class.
+  // FIXME: can these be address-space qualified?
   return dyn_cast<TemplateTypeParmType>(CanonicalType);
 }
 
@@ -711,22 +720,20 @@
 }
 
 bool Type::isPromotableIntegerType() const {
-  if (const ASQualType *ASQT = dyn_cast<ASQualType>(CanonicalType))
-    return ASQT->getBaseType()->isPromotableIntegerType();
-  const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType);
-  if (!BT) return false;
-  switch (BT->getKind()) {
-  case BuiltinType::Bool:
-  case BuiltinType::Char_S:
-  case BuiltinType::Char_U:
-  case BuiltinType::SChar:
-  case BuiltinType::UChar:
-  case BuiltinType::Short:
-  case BuiltinType::UShort:
-    return true;
-  default: 
-    return false;
-  }
+  if (const BuiltinType *BT = getAsBuiltinType())
+    switch (BT->getKind()) {
+    case BuiltinType::Bool:
+    case BuiltinType::Char_S:
+    case BuiltinType::Char_U:
+    case BuiltinType::SChar:
+    case BuiltinType::UChar:
+    case BuiltinType::Short:
+    case BuiltinType::UShort:
+      return true;
+    default: 
+      return false;
+    }
+  return false;
 }
 
 const char *BuiltinType::getName() const {