Fix <rdar://problem/6206858> [sema] type check @throw statements.
Added a FIXME to handle 'rethrow' check.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64308 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 18d9ad6..f4eb22d 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -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