From: Steve Naroff Date: Fri, 25 Jul 2008 17:57:26 +0000 (+0000) Subject: Move fix in r54013 from the parser to sema. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=394f3f483fa4e7b472630cfcd03f7840520958c5;p=clang Move fix in r54013 from the parser to sema. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@54032 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index 38379b14e6..7d7ba10a38 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -1292,10 +1292,8 @@ Parser::DeclTy *Parser::ParseObjCMethodDefinition() { EnterScope(Scope::FnScope|Scope::DeclScope); // Tell the actions module that we have entered a method definition with the - // specified Declarator for the method. If we don't have an MDecl, avoid - // calling the actions module. - if (MDecl) - Actions.ObjCActOnStartOfMethodDef(CurScope, MDecl); + // specified Declarator for the method. + Actions.ObjCActOnStartOfMethodDef(CurScope, MDecl); StmtResult FnBody = ParseCompoundStatementBody(); @@ -1307,8 +1305,7 @@ Parser::DeclTy *Parser::ParseObjCMethodDefinition() { ExitScope(); // TODO: Pass argument information. - if (MDecl) - Actions.ActOnFinishFunctionBody(MDecl, FnBody.Val); + Actions.ActOnFinishFunctionBody(MDecl, FnBody.Val); return MDecl; } diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 25d4ad5751..4d726cf0a8 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1576,12 +1576,13 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclTy *D) { Sema::DeclTy *Sema::ActOnFinishFunctionBody(DeclTy *D, StmtTy *Body) { Decl *dcl = static_cast(D); - if (FunctionDecl *FD = dyn_cast(dcl)) { + if (FunctionDecl *FD = dyn_cast_or_null(dcl)) { FD->setBody((Stmt*)Body); assert(FD == getCurFunctionDecl() && "Function parsing confused"); - } else if (ObjCMethodDecl *MD = dyn_cast(dcl)) { + } else if (ObjCMethodDecl *MD = dyn_cast_or_null(dcl)) { MD->setBody((Stmt*)Body); - } + } else + return 0; PopDeclContext(); // Verify and clean out per-function state. diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index f71f4f4b78..79f1e2d682 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -22,8 +22,11 @@ using namespace clang; /// and user declared, in the method definition's AST. void Sema::ObjCActOnStartOfMethodDef(Scope *FnBodyScope, DeclTy *D) { assert(getCurMethodDecl() == 0 && "Method parsing confused"); - ObjCMethodDecl *MDecl = dyn_cast(static_cast(D)); - assert(MDecl != 0 && "Not a method declarator!"); + ObjCMethodDecl *MDecl = dyn_cast_or_null((Decl *)D); + + // If we don't have a valid method decl, simply return. + if (!MDecl) + return; // Allow the rest of sema to find private method decl implementations. if (MDecl->isInstance())