diff options
author | Steve Naroff <snaroff@apple.com> | 2009-03-03 20:59:06 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2009-03-03 20:59:06 +0000 |
commit | f50cb369273c6bd26c9629df92ee53f1d8af4149 (patch) | |
tree | 2b213ad14f1996e3399bce4625259861177752d7 | |
parent | 6328cc316d7032517399da9230a197cd29f2664d (diff) |
Fix <rdar://problem/6632061> [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
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.def | 2 | ||||
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 10 | ||||
-rw-r--r-- | test/SemaObjC/catch-stmt.m | 10 |
3 files changed, 20 insertions, 2 deletions
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<Stmt*>(catchList.release()); + ParmVarDecl *PVD = static_cast<ParmVarDecl*>(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<ParmVarDecl*>(Parm), static_cast<Stmt*>(Body.release()), - CatchList); + PVD, static_cast<Stmt*>(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}} + } +} + |