]> granicus.if.org Git - clang/commitdiff
Fix DeclContext of an objective-c @catch variable
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 3 Feb 2010 00:01:43 +0000 (00:01 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 3 Feb 2010 00:01:43 +0000 (00:01 +0000)
declaration. Fixes radar 7590273.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95164 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Parse/Action.h
lib/Parse/ParseObjc.cpp
lib/Sema/Sema.h
lib/Sema/SemaDecl.cpp
test/CodeGenObjC/blocks-4.m [new file with mode: 0644]

index 6b398f62f60b687040a1fed81dc3b781c9a5dde7..91854aa480cc4c586712162bb3ed3e57d1798901 100644 (file)
@@ -459,6 +459,8 @@ public:
   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
index ae85aa3a8aef0a1f5a61448434a3bbd42f3eec9c..e837c765bff260a8e3e0a6fa48afa0f2d9c4d438 100644 (file)
@@ -1482,6 +1482,7 @@ Parser::OwningStmtResult Parser::ParseObjCTryStmt(SourceLocation atLoc) {
           // 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 '...'
 
index d971b9caebf35da436a559e950a039b40a55dad3..b8831b4b7ab451ee4d390f3b12923159008b7619 100644 (file)
@@ -676,6 +676,7 @@ public:
                                 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);
index c604f6a4eef44c50d8f68e8dfcb0b0a05ab2b784..8c217f8e0d2705d18b6f98681c980512fdece79e 100644 (file)
@@ -3934,6 +3934,19 @@ Sema::ActOnParamDeclarator(Scope *S, Declarator &D) {
   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?
+  
+}
+
 void Sema::ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
                                            SourceLocation LocAfterDecls) {
   assert(D.getTypeObject(0).Kind == DeclaratorChunk::Function &&
diff --git a/test/CodeGenObjC/blocks-4.m b/test/CodeGenObjC/blocks-4.m
new file mode 100644 (file)
index 0000000..d945ed4
--- /dev/null
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple i386-apple-darwin9 -emit-llvm -fblocks -o %t %s
+// rdar://7590273
+
+void EXIT(id e);
+
+@interface NSBlockOperation {
+}
++(id)blockOperationWithBlock:(void (^)(void))block ;
+@end
+
+void FUNC() {
+        [NSBlockOperation blockOperationWithBlock:^{
+            @try {
+
+            }
+            @catch (id exception) {
+               EXIT(exception);
+            }
+        }];
+
+}