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!

llvm-svn: 332821
This commit is contained in:
Saleem Abdulrasool 2018-05-20 19:26:44 +00:00
parent 777afc7fbd
commit 278e1c460b
2 changed files with 17 additions and 3 deletions

View 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,

View File

@ -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}}
}
}