diff options
author | Steve Naroff <snaroff@apple.com> | 2009-03-03 00:45:38 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2009-03-03 00:45:38 +0000 |
commit | c97fb9a394ce2cc5e664fcb472e93553528378ad (patch) | |
tree | 103dba12bbd7e9335413ca6b84e698badae68647 | |
parent | e184b1e4e06c059a8360fae4c9b5ea00fd62014d (diff) |
Fix <rdar://problem/6635908> crash on invalid
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65909 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 8 | ||||
-rw-r--r-- | test/SemaObjC/method-no-context.m | 4 |
2 files changed, 9 insertions, 3 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 39b211f64b..e7dff6d5b3 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -785,9 +785,11 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprArg rex) { QualType FnRetType; if (FunctionDecl *FD = getCurFunctionDecl()) FnRetType = FD->getResultType(); - else - FnRetType = getCurMethodDecl()->getResultType(); - + else if (ObjCMethodDecl *MD = getCurMethodDecl()) + FnRetType = MD->getResultType(); + else // If we don't have a function/method context, bail. + return StmtError(); + if (FnRetType->isVoidType()) { if (RetValExp) {// C99 6.8.6.4p1 (ext_ since GCC warns) unsigned D = diag::ext_return_has_expr; diff --git a/test/SemaObjC/method-no-context.m b/test/SemaObjC/method-no-context.m new file mode 100644 index 0000000000..484322e29e --- /dev/null +++ b/test/SemaObjC/method-no-context.m @@ -0,0 +1,4 @@ +// RUN: clang -fsyntax-only -verify %s + +- im0 { int a; return 0; // expected-error{{missing context for method declaration}} +// expected-error{{expected '}'}} |