]> granicus.if.org Git - clang/commitdiff
Sema: diagnose invalid catch parameter in ObjC
authorSaleem Abdulrasool <compnerd@compnerd.org>
Sun, 20 May 2018 19:26:44 +0000 (19:26 +0000)
committerSaleem Abdulrasool <compnerd@compnerd.org>
Sun, 20 May 2018 19:26:44 +0000 (19:26 +0000)
Ensure that the type being used has an associated interface when
declaring the parameter for `@catch`.

Resolves PR37384!

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

lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/catch-invalid.m [new file with mode: 0644]

index 87d37e682578ace84f2917ae790feb543dcdba84..d7544ecfaf79c16a9ae6b7cc66142a04e7f4257c 100644 (file)
@@ -4838,12 +4838,17 @@ VarDecl *Sema::BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType T,
     // Don't do any further checking.
   } else if (T->isDependentType()) {
     // Okay: we don't know what this type will instantiate to.
-  } else if (!T->isObjCObjectPointerType()) {
-    Invalid = true;
-    Diag(IdLoc ,diag::err_catch_param_not_objc_type);
   } else if (T->isObjCQualifiedIdType()) {
     Invalid = true;
     Diag(IdLoc, diag::err_illegal_qualifiers_on_catch_parm);
+  } else if (T->isObjCIdType()) {
+    // Okay: we don't know what this type will instantiate to.
+  } else if (!T->isObjCObjectPointerType()) {
+    Invalid = true;
+    Diag(IdLoc, diag::err_catch_param_not_objc_type);
+  } else if (!T->getAs<ObjCObjectPointerType>()->getInterfaceType()) {
+    Invalid = true;
+    Diag(IdLoc, diag::err_catch_param_not_objc_type);
   }
   
   VarDecl *New = VarDecl::Create(Context, CurContext, StartLoc, IdLoc, Id,
diff --git a/test/SemaObjC/catch-invalid.m b/test/SemaObjC/catch-invalid.m
new file mode 100644 (file)
index 0000000..352b2fb
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -triple thumbv7-unknown-windows-msvc -fobjc-exceptions -fobjc-runtime=ios -verify %s
+
+extern void g(void);
+void f() {
+  @try {
+    g();
+  } @catch (Class c) { // expected-error{{@catch parameter is not a pointer to an interface type}}
+  }
+}