]> granicus.if.org Git - clang/commitdiff
Fix <rdar://problem/6635908> crash on invalid
authorSteve Naroff <snaroff@apple.com>
Tue, 3 Mar 2009 00:45:38 +0000 (00:45 +0000)
committerSteve Naroff <snaroff@apple.com>
Tue, 3 Mar 2009 00:45:38 +0000 (00:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65909 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaStmt.cpp
test/SemaObjC/method-no-context.m [new file with mode: 0644]

index 39b211f64b470a6127c7c43cc85b870d66b676d5..e7dff6d5b32efce878988b3cb8f8a39c09f1283c 100644 (file)
@@ -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 (file)
index 0000000..484322e
--- /dev/null
@@ -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 '}'}}