Add Type::getAsBuiltinType() and Type::builtinTypesAreCompatible().
Modified Type::typesAreCompatible() to use the above.

This fixes the following bug submitted by Keith Bauer (thanks!).

int equal(char *a, const char *b)
{
    return a == b;
}

Also tweaked Sema::CheckCompareOperands() to ignore the qualifiers when
comparing two pointer types (though it doesn't relate directly to this bug).



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41476 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/Type.cpp b/AST/Type.cpp
index 65ba90a..f4c5aa7 100644
--- a/AST/Type.cpp
+++ b/AST/Type.cpp
@@ -75,6 +75,18 @@
   return isa<ComplexType>(CanonicalType);
 }
 
+const BuiltinType *Type::getAsBuiltinType() const {
+  // If this is directly a builtin type, return it.
+  if (const BuiltinType *BTy = dyn_cast<BuiltinType>(this))
+    return BTy;
+  
+  // If this is a typedef for a builtin type, strip the typedef off without
+  // losing all typedef information.
+  if (isa<BuiltinType>(CanonicalType))
+    return cast<BuiltinType>(cast<TypedefType>(this)->LookThroughTypedefs());
+  return 0;
+}
+
 const FunctionType *Type::getAsFunctionType() const {
   // If this is directly a function type, return it.
   if (const FunctionType *FTy = dyn_cast<FunctionType>(this))
@@ -204,6 +216,12 @@
   return 0;
 }
 
+bool Type::builtinTypesAreCompatible(QualType lhs, QualType rhs) {
+  const BuiltinType *lBuiltin = lhs->getAsBuiltinType();
+  const BuiltinType *rBuiltin = rhs->getAsBuiltinType();
+  
+  return lBuiltin->getKind() == rBuiltin->getKind();
+}
 
 // C99 6.2.7p1: If both are complete types, then the following additional
 // requirements apply...FIXME (handle compatibility across source files).
@@ -334,7 +352,7 @@
     case Type::Tagged: // handle structures, unions
       return tagTypesAreCompatible(lcanon, rcanon);
     case Type::Builtin:
-      return false; 
+      return builtinTypesAreCompatible(lcanon, rcanon); 
     default:
       assert(0 && "unexpected type");
   }