r332821 - Sema: diagnose invalid catch parameter in ObjC
Saleem Abdulrasool via cfe-commits
cfe-commits at lists.llvm.org
Sun May 20 12:26:44 PDT 2018
Author: compnerd
Date: Sun May 20 12:26:44 2018
New Revision: 332821
URL: http://llvm.org/viewvc/llvm-project?rev=332821&view=rev
Log:
Sema: diagnose invalid catch parameter in ObjC
Ensure that the type being used has an associated interface when
declaring the parameter for `@catch`.
Resolves PR37384!
Added:
cfe/trunk/test/SemaObjC/catch-invalid.m
Modified:
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=332821&r1=332820&r2=332821&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Sun May 20 12:26:44 2018
@@ -4838,12 +4838,17 @@ VarDecl *Sema::BuildObjCExceptionDecl(Ty
// 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,
Added: cfe/trunk/test/SemaObjC/catch-invalid.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/catch-invalid.m?rev=332821&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/catch-invalid.m (added)
+++ cfe/trunk/test/SemaObjC/catch-invalid.m Sun May 20 12:26:44 2018
@@ -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}}
+ }
+}
More information about the cfe-commits
mailing list