]> granicus.if.org Git - clang/commitdiff
Don't assert when diagnosing a missing cast of an unknown-anytype
authorJohn McCall <rjmccall@apple.com>
Wed, 31 Aug 2011 20:57:36 +0000 (20:57 +0000)
committerJohn McCall <rjmccall@apple.com>
Wed, 31 Aug 2011 20:57:36 +0000 (20:57 +0000)
message send to an unknown method.

rdar://problem/9416370, redux.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138893 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
lib/Sema/SemaExprObjC.cpp
test/SemaObjCXX/unknown-anytype.mm [new file with mode: 0644]

index 89bc1064508739ac3c0cd8b52d58859f4e8d0bb5..d5f1564e6ac8dfb8f8f090ade4b850e68e476300 100644 (file)
@@ -4639,9 +4639,12 @@ def err_sizeof_pack_no_pack_name_suggest : Error<
 def note_parameter_pack_here : Note<"parameter pack %0 declared here">;
 
 def err_uncasted_use_of_unknown_any : Error<
-  "%0 has unknown type;  cast it to its declared type to use it">;
+  "%0 has unknown type; cast it to its declared type to use it">;
 def err_uncasted_call_of_unknown_any : Error<
-  "%0 has unknown return type;  cast the call to its declared return type">;
+  "%0 has unknown return type; cast the call to its declared return type">;
+def err_uncasted_send_to_unknown_any_method : Error<
+  "no known method %select{%objcinstance1|%objcclass1}0; cast the "
+  "message send to the method's return type">;
 def err_unsupported_unknown_any_decl : Error<
   "%0 has unknown type, which is unsupported for this kind of declaration">;
 def err_unsupported_unknown_any_expr : Error<
index d94e10b0096707d5db5efa9c9210fed4efdc3766..928b11bd0b6e21bb8415c2bd31b5f8f3f6d8a443 100644 (file)
@@ -9942,7 +9942,12 @@ static ExprResult diagnoseUnknownAnyExpr(Sema &S, Expr *e) {
     diagID = diag::err_uncasted_call_of_unknown_any;
     loc = msg->getSelectorLoc();
     d = msg->getMethodDecl();
-    assert(d && "unknown method returning __unknown_any?");
+    if (!d) {
+      S.Diag(loc, diag::err_uncasted_send_to_unknown_any_method)
+        << static_cast<unsigned>(msg->isClassMessage()) << msg->getSelector()
+        << orig->getSourceRange();
+      return ExprError();
+    }
   } else {
     S.Diag(e->getExprLoc(), diag::err_unsupported_unknown_any_expr)
       << e->getSourceRange();
index 402e54c0e80190f8525ea44801c3b289e6a21f11..aa9b4748a03914c68808aca593bf58c74ccc2509 100644 (file)
@@ -357,8 +357,9 @@ bool Sema::CheckMessageArgumentTypes(QualType ReceiverType,
     else
       DiagID = isClassMessage ? diag::warn_class_method_not_found
                               : diag::warn_inst_method_not_found;
-    Diag(lbrac, DiagID)
-      << Sel << isClassMessage << SourceRange(lbrac, rbrac);
+    if (!getLangOptions().DebuggerSupport)
+      Diag(lbrac, DiagID)
+        << Sel << isClassMessage << SourceRange(lbrac, rbrac);
 
     // In debuggers, we want to use __unknown_anytype for these
     // results so that clients can cast them.
diff --git a/test/SemaObjCXX/unknown-anytype.mm b/test/SemaObjCXX/unknown-anytype.mm
new file mode 100644 (file)
index 0000000..163ddde
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fdebugger-support -funknown-anytype -fsyntax-only -verify %s
+
+// rdar://problem/9416370
+namespace test0 {
+  void test(id x) {
+    [x foo]; // expected-error {{no known method '-foo'; cast the message send to the method's return type}}
+  }
+}