Fix DeclContext of an objective-c @catch variable
declaration. Fixes radar 7590273.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95164 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp
index ae85aa3..e837c76 100644
--- a/lib/Parse/ParseObjc.cpp
+++ b/lib/Parse/ParseObjc.cpp
@@ -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 '...'
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index d971b9c..b8831b4 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -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);
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index c604f6a..8c217f8 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -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?
+
+}
+
void Sema::ActOnFinishKNRParamDeclarations(Scope *S, Declarator &D,
SourceLocation LocAfterDecls) {
assert(D.getTypeObject(0).Kind == DeclaratorChunk::Function &&