[cfe-commits] r65968 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def lib/Sema/SemaStmt.cpp test/SemaObjC/catch-stmt.m

Steve Naroff snaroff at apple.com
Tue Mar 3 12:59:07 PST 2009


Author: snaroff
Date: Tue Mar  3 14:59:06 2009
New Revision: 65968

URL: http://llvm.org/viewvc/llvm-project?rev=65968&view=rev
Log:
Fix <rdar://problem/6632061> [sema] non object types should not be allowed in @catch statements.

Added:
    cfe/trunk/test/SemaObjC/catch-stmt.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
    cfe/trunk/lib/Sema/SemaStmt.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def?rev=65968&r1=65967&r2=65968&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Tue Mar  3 14:59:06 2009
@@ -960,6 +960,8 @@
      "@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

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=65968&r1=65967&r2=65968&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Tue Mar  3 14:59:06 2009
@@ -965,9 +965,15 @@
                            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);
 }
 

Added: cfe/trunk/test/SemaObjC/catch-stmt.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/catch-stmt.m?rev=65968&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/catch-stmt.m (added)
+++ cfe/trunk/test/SemaObjC/catch-stmt.m Tue Mar  3 14:59:06 2009
@@ -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}}
+  }
+}
+





More information about the cfe-commits mailing list