From 2e85c5f297e6f141bf1dbe09d326457102daa288 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Thu, 23 Feb 2012 21:11:20 +0000 Subject: [PATCH] [libclang] Make sure that all top-level decls in a @implementation are marked as such. Previously we missed tag declarations; fixes rdar://10902015 llvm-svn: 151283 --- clang/include/clang/Sema/Sema.h | 3 +++ clang/lib/Parse/ParseObjc.cpp | 4 +--- clang/lib/Sema/SemaDeclObjC.cpp | 19 +++++++++++++++++++ clang/test/Index/get-cursor.m | 15 +++++++++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 19db26dd5a89..7aed347d4107 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -5477,6 +5477,9 @@ public: IdentifierInfo *CatName, SourceLocation CatLoc); + DeclGroupPtrTy ActOnFinishObjCImplementation(Decl *ObjCImpDecl, + ArrayRef Decls); + DeclGroupPtrTy ActOnForwardClassDeclaration(SourceLocation Loc, IdentifierInfo **IdentList, SourceLocation *IdentLocs, diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index 416cb39a6396..27bdd0beb1d2 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -1532,9 +1532,7 @@ Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc) { } } - DeclsInGroup.push_back(ObjCImpDecl); - return Actions.BuildDeclaratorGroup( - DeclsInGroup.data(), DeclsInGroup.size(), false); + return Actions.ActOnFinishObjCImplementation(ObjCImpDecl, DeclsInGroup); } Parser::DeclGroupPtrTy diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index f3db4be1117c..661c580cc97b 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -988,6 +988,25 @@ Decl *Sema::ActOnStartClassImplementation( return ActOnObjCContainerStartDefinition(IMPDecl); } +Sema::DeclGroupPtrTy +Sema::ActOnFinishObjCImplementation(Decl *ObjCImpDecl, ArrayRef Decls) { + SmallVector DeclsInGroup; + DeclsInGroup.reserve(Decls.size() + 1); + + for (unsigned i = 0, e = Decls.size(); i != e; ++i) { + Decl *Dcl = Decls[i]; + if (!Dcl) + continue; + if (Dcl->getDeclContext()->isFileContext()) + Dcl->setTopLevelDeclInObjCContainer(); + DeclsInGroup.push_back(Dcl); + } + + DeclsInGroup.push_back(ObjCImpDecl); + + return BuildDeclaratorGroup(DeclsInGroup.data(), DeclsInGroup.size(), false); +} + void Sema::CheckImplementationIvars(ObjCImplementationDecl *ImpDecl, ObjCIvarDecl **ivars, unsigned numIvars, SourceLocation RBrace) { diff --git a/clang/test/Index/get-cursor.m b/clang/test/Index/get-cursor.m index 7acf7bf38c87..97730b1ef604 100644 --- a/clang/test/Index/get-cursor.m +++ b/clang/test/Index/get-cursor.m @@ -26,6 +26,18 @@ @synthesize name = _name; @end +@interface rdar10902015 +@end + +@implementation rdar10902015 + +struct S {}; + +-(void)mm:(struct S*)s { + rdar10902015 *i = 0; +} +@end + // RUN: c-index-test -cursor-at=%s:4:28 -cursor-at=%s:5:28 %s | FileCheck -check-prefix=CHECK-PROP %s // CHECK-PROP: ObjCPropertyDecl=foo1:4:26 // CHECK-PROP: ObjCPropertyDecl=foo2:5:27 @@ -35,3 +47,6 @@ // RUN: c-index-test -cursor-at=%s:20:10 %s | FileCheck -check-prefix=CHECK-METHOD %s // CHECK-METHOD: ObjCInstanceMethodDecl=name:20:1 + +// RUN: c-index-test -cursor-at=%s:37:17 %s | FileCheck -check-prefix=CHECK-IN-IMPL %s +// CHECK-IN-IMPL: VarDecl=i:37:17