[cfe-commits] r95164 - in /cfe/trunk: include/clang/Parse/Action.h lib/Parse/ParseObjc.cpp lib/Sema/Sema.h lib/Sema/SemaDecl.cpp test/CodeGenObjC/blocks-4.m

Douglas Gregor dgregor at apple.com
Tue Feb 2 16:20:10 PST 2010


On Feb 2, 2010, at 4:01 PM, Fariborz Jahanian wrote:

> Author: fjahanian
> Date: Tue Feb  2 18:01:43 2010
> New Revision: 95164
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=95164&view=rev
> Log:
> Fix DeclContext of an objective-c @catch variable
> declaration. Fixes radar 7590273.
> 
> 
> Added:
>    cfe/trunk/test/CodeGenObjC/blocks-4.m
> Modified:
>    cfe/trunk/include/clang/Parse/Action.h
>    cfe/trunk/lib/Parse/ParseObjc.cpp
>    cfe/trunk/lib/Sema/Sema.h
>    cfe/trunk/lib/Sema/SemaDecl.cpp
> 
> Modified: cfe/trunk/include/clang/Parse/Action.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=95164&r1=95163&r2=95164&view=diff
> 
> ==============================================================================
> --- cfe/trunk/include/clang/Parse/Action.h (original)
> +++ cfe/trunk/include/clang/Parse/Action.h Tue Feb  2 18:01:43 2010
> @@ -459,6 +459,8 @@
>   virtual DeclPtrTy ActOnParamDeclarator(Scope *S, Declarator &D) {
>     return DeclPtrTy();
>   }
> +  virtual void ActOnObjCCatchParam(DeclPtrTy D) {
> +  }
> 
>   /// AddInitializerToDecl - This action is called immediately after
>   /// ActOnDeclarator (when an initializer is present). The code is factored
> 
> Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=95164&r1=95163&r2=95164&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
> +++ cfe/trunk/lib/Parse/ParseObjc.cpp Tue Feb  2 18:01:43 2010
> @@ -1482,6 +1482,7 @@
>           // Inform the actions module about the parameter declarator, so it
>           // gets added to the current scope.
>           FirstPart = Actions.ActOnParamDeclarator(CurScope, ParmDecl);
> +          Actions.ActOnObjCCatchParam(FirstPart);
>         } else
>           ConsumeToken(); // consume '...'
> 
> 
> Modified: cfe/trunk/lib/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=95164&r1=95163&r2=95164&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Sema/Sema.h (original)
> +++ cfe/trunk/lib/Sema/Sema.h Tue Feb  2 18:01:43 2010
> @@ -676,6 +676,7 @@
>                                 bool &OverloadableAttrRequired);
>   void CheckMain(FunctionDecl *FD);
>   virtual DeclPtrTy ActOnParamDeclarator(Scope *S, Declarator &D);
> +  virtual void ActOnObjCCatchParam(DeclPtrTy D);
>   virtual void ActOnParamDefaultArgument(DeclPtrTy param,
>                                          SourceLocation EqualLoc,
>                                          ExprArg defarg);
> 
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=95164&r1=95163&r2=95164&view=diff
> 
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Feb  2 18:01:43 2010
> @@ -3934,6 +3934,19 @@
>   return DeclPtrTy::make(New);
> }
> 
> +void Sema::ActOnObjCCatchParam(DeclPtrTy D) {
> +  ParmVarDecl *Param = cast<ParmVarDecl>(D.getAs<Decl>());
> +  
> +  if (FunctionDecl *Function = dyn_cast<FunctionDecl>(CurContext))
> +    Param->setDeclContext(Function);
> +  else if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CurContext))
> +    Param->setDeclContext(MD);
> +  else if (BlockDecl *BD = dyn_cast<BlockDecl>(CurContext))
> +    Param->setDeclContext(BD);
> +  // FIXME. Other contexts?

Why not just use

	Param->setDeclContext(CurContext)

?

That would catch everything.

Another idea: why is it that we use a ParmVarDecl for the catch parameter, rather than a VarDecl? 

	- Doug



More information about the cfe-commits mailing list