This fixes <rdar://problem/6497650> More type mismatches issues with clang.

Move two key ObjC typechecks from Sema::CheckPointerTypesForAssignment() to ASTContext::mergeTypes().

This allows us to take advantage of the recursion in ASTContext::mergeTypes(), removing some bogus warnings.

This test case I've added includes an example where we still warn (and GCC doesn't). Need to talk with folks and decide what to do. At this point, the major bogosities should be fixed.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65231 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 9ed6251..e24de53 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -2680,6 +2680,15 @@
 
   // If the canonical type classes don't match.
   if (LHSClass != RHSClass) {
+    const ObjCInterfaceType* LHSIface = LHS->getAsObjCInterfaceType();
+    const ObjCInterfaceType* RHSIface = RHS->getAsObjCInterfaceType();
+
+    // ID acts sort of like void* for ObjC interfaces
+    if (LHSIface && isObjCIdStructType(RHS))
+      return LHS;
+    if (RHSIface && isObjCIdStructType(LHS))
+      return RHS;
+    
     // ID is compatible with all qualified id types.
     if (LHS->isObjCQualifiedIdType()) {
       if (const PointerType *PT = RHS->getAsPointerType()) {
@@ -2808,8 +2817,13 @@
       return LHS;
     return QualType();
   case Type::ObjCInterface:
-    // Distinct ObjC interfaces are not compatible; see canAssignObjCInterfaces
-    // for checking assignment/comparison safety
+    // Check if the interfaces are assignment compatible.
+    const ObjCInterfaceType* LHSIface = LHS->getAsObjCInterfaceType();
+    const ObjCInterfaceType* RHSIface = RHS->getAsObjCInterfaceType();
+    if (LHSIface && RHSIface &&
+        canAssignObjCInterfaces(LHSIface, RHSIface))
+      return LHS;
+
     return QualType();
   case Type::ObjCQualifiedId:
     // Distinct qualified id's are not compatible.