[cfe-commits] r65909 - in /cfe/trunk: lib/Sema/SemaStmt.cpp test/SemaObjC/method-no-context.m

Steve Naroff snaroff at apple.com
Mon Mar 2 16:45:39 PST 2009


Author: snaroff
Date: Mon Mar  2 18:45:38 2009
New Revision: 65909

URL: http://llvm.org/viewvc/llvm-project?rev=65909&view=rev
Log:
Fix <rdar://problem/6635908> crash on invalid

Added:
    cfe/trunk/test/SemaObjC/method-no-context.m
Modified:
    cfe/trunk/lib/Sema/SemaStmt.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Mon Mar  2 18:45:38 2009
@@ -785,9 +785,11 @@
   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;

Added: cfe/trunk/test/SemaObjC/method-no-context.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-no-context.m?rev=65909&view=auto

==============================================================================
--- cfe/trunk/test/SemaObjC/method-no-context.m (added)
+++ cfe/trunk/test/SemaObjC/method-no-context.m Mon Mar  2 18:45:38 2009
@@ -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 '}'}}





More information about the cfe-commits mailing list