lldb support: under debugger support flag, when sending message
to forward class, and assigning to an 'id' type var, message
sends default to 'id'. // rdar"//10988847



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152420 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 7957473..6c25a20 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -6209,6 +6209,18 @@
   // Get the decls type and save a reference for later, since
   // CheckInitializerTypes may change it.
   QualType DclT = VDecl->getType(), SavT = DclT;
+  
+  // Top-level message sends default to 'id' when we're in a debugger
+  // and we are assigning it to a variable of 'id' type.
+  if (getLangOptions().DebuggerCastResultToId && DclT->isObjCIdType())
+    if (Init->getType() == Context.UnknownAnyTy && isa<ObjCMessageExpr>(Init)) {
+      ExprResult Result = forceUnknownAnyToType(Init, Context.getObjCIdType());
+      if (Result.isInvalid()) {
+        VDecl->setInvalidDecl();
+        return;
+      }
+      Init = Result.take();
+    }
 
   // Perform the initialization.
   if (!VDecl->isInvalidDecl()) {
diff --git a/test/SemaObjC/debugger-cast-result-to-id.m b/test/SemaObjC/debugger-cast-result-to-id.m
index 81a6307..00a02be 100644
--- a/test/SemaObjC/debugger-cast-result-to-id.m
+++ b/test/SemaObjC/debugger-cast-result-to-id.m
@@ -7,3 +7,10 @@
   (void)(int)[[test0 unknownMethod] otherUnknownMethod];;
   (void)(id)[[test1() unknownMethod] otherUnknownMethod];
 }
+
+// rdar://10988847
+@class NSString; // expected-note {{forward declaration of class here}}
+
+void rdar10988847() {
+  id s = [NSString stringWithUTF8String:"foo"]; // expected-warning {{receiver 'NSString' is a forward class and corresponding @interface may not exist}}
+}
diff --git a/test/SemaObjCXX/debugger-cast-result-to-id.mm b/test/SemaObjCXX/debugger-cast-result-to-id.mm
index 9487a22..cd7aa7b 100644
--- a/test/SemaObjCXX/debugger-cast-result-to-id.mm
+++ b/test/SemaObjCXX/debugger-cast-result-to-id.mm
@@ -7,3 +7,11 @@
     [x foo];
   }
 }
+
+// rdar://10988847
+@class NSString; // expected-note {{forward declaration of class here}}
+namespace test1 {
+  void rdar10988847() {
+    id s = [NSString stringWithUTF8String:"foo"]; // expected-warning {{receiver 'NSString' is a forward class and corresponding @interface may not exist}}
+  }
+}