diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 0ad20123cc00..6c1059c05cdb 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -7470,6 +7470,7 @@ public: SourceRange SuperTypeArgsRange); void ActOnTypedefedProtocols(SmallVectorImpl &ProtocolRefs, + SmallVectorImpl &ProtocolLocs, IdentifierInfo *SuperName, SourceLocation SuperLoc); diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp index 980ea77d84a4..42081a29ad97 100644 --- a/clang/lib/Parse/ParseObjc.cpp +++ b/clang/lib/Parse/ParseObjc.cpp @@ -369,7 +369,8 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc, } if (Tok.isNot(tok::less)) - Actions.ActOnTypedefedProtocols(protocols, superClassId, superClassLoc); + Actions.ActOnTypedefedProtocols(protocols, protocolLocs, + superClassId, superClassLoc); Decl *ClsType = Actions.ActOnStartClassInterface(getCurScope(), AtLoc, nameId, nameLoc, diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index 1b030801f23a..17e7141711ee 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -1028,6 +1028,7 @@ ActOnStartClassInterface(Scope *S, SourceLocation AtInterfaceLoc, /// typedef'ed use for a qualified super class and adds them to the list /// of the protocols. void Sema::ActOnTypedefedProtocols(SmallVectorImpl &ProtocolRefs, + SmallVectorImpl &ProtocolLocs, IdentifierInfo *SuperName, SourceLocation SuperLoc) { if (!SuperName) @@ -1040,8 +1041,14 @@ void Sema::ActOnTypedefedProtocols(SmallVectorImpl &ProtocolRefs, if (const TypedefNameDecl *TDecl = dyn_cast_or_null(IDecl)) { QualType T = TDecl->getUnderlyingType(); if (T->isObjCObjectType()) - if (const ObjCObjectType *OPT = T->getAs()) + if (const ObjCObjectType *OPT = T->getAs()) { ProtocolRefs.append(OPT->qual_begin(), OPT->qual_end()); + // FIXME: Consider whether this should be an invalid loc since the loc + // is not actually pointing to a protocol name reference but to the + // typedef reference. Note that the base class name loc is also pointing + // at the typedef. + ProtocolLocs.append(OPT->getNumProtocols(), SuperLoc); + } } } diff --git a/clang/test/Index/Core/index-source.m b/clang/test/Index/Core/index-source.m index 554378ea3cf7..fc1b6232cfe8 100644 --- a/clang/test/Index/Core/index-source.m +++ b/clang/test/Index/Core/index-source.m @@ -129,3 +129,23 @@ extern int setjmp(jmp_buf); // CHECK: [[@LINE+1]]:12 | extension/ObjC | | | | Decl | rel: 0 @interface NonExistent() @end + +@interface MyGenCls : Base +@end + +@protocol MyEnumerating +@end + +// CHECK: [[@LINE+4]]:41 | type-alias/C | MyEnumerator | c:index-source.m@T@MyEnumerator | | Def | rel: 0 +// CHECK: [[@LINE+3]]:26 | protocol/ObjC | MyEnumerating | c:objc(pl)MyEnumerating | | Ref | rel: 0 +// CHECK: [[@LINE+2]]:9 | class/ObjC | MyGenCls | c:objc(cs)MyGenCls | _OBJC_CLASS_$_MyGenCls | Ref | rel: 0 +// CHECK: [[@LINE+1]]:18 | class/ObjC | Base | c:objc(cs)Base | _OBJC_CLASS_$_Base | Ref | rel: 0 +typedef MyGenCls MyEnumerator; + +// CHECK: [[@LINE+5]]:12 | class/ObjC | PermanentEnumerator | c:objc(cs)PermanentEnumerator | _OBJC_CLASS_$_PermanentEnumerator | Decl | rel: 0 +// CHECK: [[@LINE+4]]:34 | class/ObjC | MyGenCls | c:objc(cs)MyGenCls | _OBJC_CLASS_$_MyGenCls | Ref,RelBase | rel: 1 +// CHECK-NEXT: RelBase | PermanentEnumerator | c:objc(cs)PermanentEnumerator +// CHECK: [[@LINE+2]]:34 | protocol/ObjC | MyEnumerating | c:objc(pl)MyEnumerating | | Ref,RelBase | rel: 1 +// CHECK-NEXT: RelBase | PermanentEnumerator | c:objc(cs)PermanentEnumerator +@interface PermanentEnumerator : MyEnumerator +@end