[cfe-commits] r64308 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def lib/Sema/SemaStmt.cpp test/Parser/objc-try-catch-1.m test/SemaObjC/try-catch.m
Steve Naroff
snaroff at apple.com
Wed Feb 11 09:45:08 PST 2009
Author: snaroff
Date: Wed Feb 11 11:45:08 2009
New Revision: 64308
URL: http://llvm.org/viewvc/llvm-project?rev=64308&view=rev
Log:
Fix <rdar://problem/6206858> [sema] type check @throw statements.
Added a FIXME to handle 'rethrow' check.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
cfe/trunk/lib/Sema/SemaStmt.cpp
cfe/trunk/test/Parser/objc-try-catch-1.m
cfe/trunk/test/SemaObjC/try-catch.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def?rev=64308&r1=64307&r2=64308&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Wed Feb 11 11:45:08 2009
@@ -846,6 +846,8 @@
"method %objcinstance0 not found in protocol (return type defaults to 'id')")
DIAG(error_bad_receiver_type, ERROR,
"bad receiver type %0")
+DIAG(warn_objc_throw_expects_object, WARNING,
+ "invalid %0 argument (expected an ObjC object type)")
// C++ casts
Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=64308&r1=64307&r2=64308&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Wed Feb 11 11:45:08 2009
@@ -981,9 +981,22 @@
}
Action::OwningStmtResult
-Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, ExprArg Throw) {
- return Owned(new (Context) ObjCAtThrowStmt(AtLoc,
- static_cast<Expr*>(Throw.release())));
+Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, ExprArg expr) {
+ Expr *ThrowExpr = static_cast<Expr*>(expr.release());
+ if (!ThrowExpr) {
+ // FIXME: verify the 'rethrow' is within a @catch block
+ } else {
+ QualType ThrowType = ThrowExpr->getType();
+ // Make sure the expression type is an ObjC pointer or "void *".
+ if (!Context.isObjCObjectPointerType(ThrowType)) {
+ const PointerType *PT = ThrowType->getAsPointerType();
+ if (!PT || !PT->getPointeeType()->isVoidType())
+ // This should be an error, however GCC only yields a warning.
+ Diag(AtLoc, diag::warn_objc_throw_expects_object)
+ << ThrowExpr->getType() << ThrowExpr->getSourceRange();
+ }
+ }
+ return Owned(new (Context) ObjCAtThrowStmt(AtLoc, ThrowExpr));
}
Action::OwningStmtResult
Modified: cfe/trunk/test/Parser/objc-try-catch-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/objc-try-catch-1.m?rev=64308&r1=64307&r2=64308&view=diff
==============================================================================
--- cfe/trunk/test/Parser/objc-try-catch-1.m (original)
+++ cfe/trunk/test/Parser/objc-try-catch-1.m Wed Feb 11 11:45:08 2009
@@ -27,7 +27,7 @@
return proc();
}
@catch (Frob* ex) {
- @throw 1,2;
+ @throw 1,2; // expected-warning {{invalid 'int' argument (expected an ObjC object type)}}
}
@catch(...) {
@throw (4,3,proc());
Modified: cfe/trunk/test/SemaObjC/try-catch.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/try-catch.m?rev=64308&r1=64307&r2=64308&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/try-catch.m (original)
+++ cfe/trunk/test/SemaObjC/try-catch.m Wed Feb 11 11:45:08 2009
@@ -35,3 +35,9 @@
// the exception name is optional (weird)
@catch (NSException *) {}
}
+ at end
+
+int foo() {
+ @throw 42; // expected-warning {{invalid 'int' argument (expected an ObjC object type)}}
+ @throw; // FIXME: error: â@throwâ (rethrow) used outside of a @catch block
+}
More information about the cfe-commits
mailing list