Sema::CheckConditionalOperands(): Soften pointer/integer mismatch from error->warning.

Fixes <rdar://problem/6762239> [sema] gcc incompatibility; error on incompatible operand types in ?:.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68617 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index d442b1f..4f8ad5b 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2714,6 +2714,20 @@
     }
   }
 
+  // GCC compatibility: soften pointer/integer mismatch.
+  if (RHSTy->isPointerType() && LHSTy->isIntegerType()) {
+    Diag(QuestionLoc, diag::warn_typecheck_cond_pointer_integer_mismatch)
+      << LHSTy << RHSTy << LHS->getSourceRange() << RHS->getSourceRange();
+    ImpCastExprToType(LHS, RHSTy); // promote the integer to a pointer.
+    return RHSTy;
+  }
+  if (LHSTy->isPointerType() && RHSTy->isIntegerType()) {
+    Diag(QuestionLoc, diag::warn_typecheck_cond_pointer_integer_mismatch)
+      << LHSTy << RHSTy << LHS->getSourceRange() << RHS->getSourceRange();
+    ImpCastExprToType(RHS, LHSTy); // promote the integer to a pointer.
+    return LHSTy;
+  }
+
   // Selection between block pointer types is ok as long as they are the same.
   if (LHSTy->isBlockPointerType() && RHSTy->isBlockPointerType() &&
       Context.getCanonicalType(LHSTy) == Context.getCanonicalType(RHSTy))