From 278e1c460b2de9fbd425986416875d5bc2206e6c Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sun, 20 May 2018 19:26:44 +0000 Subject: [PATCH] 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 --- clang/lib/Sema/SemaDeclObjC.cpp | 11 ++++++++--- clang/test/SemaObjC/catch-invalid.m | 9 +++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 clang/test/SemaObjC/catch-invalid.m diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index 87d37e682578..d7544ecfaf79 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -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()->getInterfaceType()) { + Invalid = true; + Diag(IdLoc, diag::err_catch_param_not_objc_type); } VarDecl *New = VarDecl::Create(Context, CurContext, StartLoc, IdLoc, Id, diff --git a/clang/test/SemaObjC/catch-invalid.m b/clang/test/SemaObjC/catch-invalid.m new file mode 100644 index 000000000000..352b2fbaa8ed --- /dev/null +++ b/clang/test/SemaObjC/catch-invalid.m @@ -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}} + } +}