From: Steve Naroff Date: Tue, 3 Mar 2009 20:59:06 +0000 (+0000) Subject: Fix [sema] non object types should not be allowed in @catch... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f50cb369273c6bd26c9629df92ee53f1d8af4149;p=clang Fix [sema] non object types should not be allowed in @catch statements. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65968 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.def b/include/clang/Basic/DiagnosticSemaKinds.def index 4138436a88..c02ee6e538 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.def +++ b/include/clang/Basic/DiagnosticSemaKinds.def @@ -960,6 +960,8 @@ DIAG(error_rethrow_used_outside_catch, ERROR, "@throw (rethrow) used outside of a @catch block") DIAG(err_attribute_multiple_objc_gc, ERROR, "multiple garbage collection attributes specified for type") +DIAG(err_catch_param_not_objc_type, ERROR, + "@catch parameter is not an Objective-C class type") // C++ casts diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 49bd85a9e7..7e7edbe51a 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -965,9 +965,15 @@ Sema::ActOnObjCAtCatchStmt(SourceLocation AtLoc, SourceLocation RParen, DeclTy *Parm, StmtArg Body, StmtArg catchList) { Stmt *CatchList = static_cast(catchList.release()); + ParmVarDecl *PVD = static_cast(Parm); + + // PVD == 0 implies @catch(...). + if (PVD && !Context.isObjCObjectPointerType(PVD->getType())) + return StmtError(Diag(PVD->getLocation(), + diag::err_catch_param_not_objc_type)); + ObjCAtCatchStmt *CS = new (Context) ObjCAtCatchStmt(AtLoc, RParen, - static_cast(Parm), static_cast(Body.release()), - CatchList); + PVD, static_cast(Body.release()), CatchList); return Owned(CatchList ? CatchList : CS); } diff --git a/test/SemaObjC/catch-stmt.m b/test/SemaObjC/catch-stmt.m new file mode 100644 index 0000000000..9aa6e057f4 --- /dev/null +++ b/test/SemaObjC/catch-stmt.m @@ -0,0 +1,10 @@ +// RUN: clang -verify %s + +void f() { + @try { + } @catch (void a) { // expected-error{{@catch parameter is not an Objective-C class type}} + } @catch (int) { // expected-error{{@catch parameter is not an Objective-C class type}} + } @catch (int *b) { // expected-error{{@catch parameter is not an Objective-C class type}} + } +} +