From: Argyrios Kyrtzidis Date: Fri, 4 Mar 2016 07:17:53 +0000 (+0000) Subject: [index] Distinguish USRs of anonymous enums by using their first enumerator. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4885d08982b191d580515701aafdeccb770884ad;p=clang [index] Distinguish USRs of anonymous enums by using their first enumerator. rdar://24609949. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262695 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Index/IndexingContext.cpp b/lib/Index/IndexingContext.cpp index 87bedd778a..204e4300f8 100644 --- a/lib/Index/IndexingContext.cpp +++ b/lib/Index/IndexingContext.cpp @@ -206,10 +206,6 @@ static const Decl *adjustParent(const Decl *Parent) { if (auto NS = dyn_cast(Parent)) { if (NS->isAnonymousNamespace()) continue; - } else if (auto EnumD = dyn_cast(Parent)) { - // Move enumerators under anonymous enum to the enclosing parent. - if (EnumD->getDeclName().isEmpty()) - continue; } else if (auto RD = dyn_cast(Parent)) { if (RD->isAnonymousStructOrUnion()) continue; diff --git a/lib/Index/USRGeneration.cpp b/lib/Index/USRGeneration.cpp index cb30090adc..2722f081fe 100644 --- a/lib/Index/USRGeneration.cpp +++ b/lib/Index/USRGeneration.cpp @@ -426,7 +426,8 @@ void USRGenerator::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) { void USRGenerator::VisitTagDecl(const TagDecl *D) { // Add the location of the tag decl to handle resolution across // translation units. - if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D))) + if (!isa(D) && + ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D))) return; D = D->getCanonicalDecl(); @@ -482,8 +483,16 @@ void USRGenerator::VisitTagDecl(const TagDecl *D) { else { if (D->isEmbeddedInDeclarator() && !D->isFreeStanding()) { printLoc(Out, D->getLocation(), Context->getSourceManager(), true); - } else + } else { Buf[off] = 'a'; + if (auto *ED = dyn_cast(D)) { + // Distinguish USRs of anonymous enums by using their first enumerator. + auto enum_range = ED->enumerators(); + if (enum_range.begin() != enum_range.end()) { + Out << '@' << **enum_range.begin(); + } + } + } } } diff --git a/test/Index/Core/index-source.m b/test/Index/Core/index-source.m index d132662463..d70974ca03 100644 --- a/test/Index/Core/index-source.m +++ b/test/Index/Core/index-source.m @@ -48,3 +48,20 @@ void goo(Base *b) { void over_func(int x) __attribute__((overloadable)); // CHECK: [[@LINE+1]]:6 | function/C | over_func | c:@F@over_func#f# | __Z9over_funcf | Decl | rel: 0 void over_func(float x) __attribute__((overloadable)); + +// CHECK: [[@LINE+1]]:6 | enum/C | MyEnum | c:@E@MyEnum | | Def | rel: 0 +enum MyEnum { + // CHECK: [[@LINE+2]]:3 | enumerator/C | EnumeratorInNamed | c:@E@MyEnum@EnumeratorInNamed | | Def,RelChild | rel: 1 + // CHECK-NEXT: RelChild | MyEnum | c:@E@MyEnum + EnumeratorInNamed +}; + +// CHECK: [[@LINE+1]]:1 | enum/C | | c:@Ea@One | | Def | rel: 0 +enum { + // CHECK: [[@LINE+2]]:3 | enumerator/C | One | c:@Ea@One@One | | Def,RelChild | rel: 1 + // CHECK-NEXT: RelChild | | c:@Ea@One + One, + // CHECK: [[@LINE+2]]:3 | enumerator/C | Two | c:@Ea@One@Two | | Def,RelChild | rel: 1 + // CHECK-NEXT: RelChild | | c:@Ea@One + Two, +}; diff --git a/test/Index/usrs.m b/test/Index/usrs.m index fc3fbc9105..92c3a3fafe 100644 --- a/test/Index/usrs.m +++ b/test/Index/usrs.m @@ -110,12 +110,12 @@ int test_multi_declaration(void) { // CHECK: usrs.m c:usrs.m@F@my_helper Extent=[3:1 - 3:60] // CHECK: usrs.m c:usrs.m@95@F@my_helper@x Extent=[3:29 - 3:34] // CHECK: usrs.m c:usrs.m@102@F@my_helper@y Extent=[3:36 - 3:41] -// CHECK: usrs.m c:usrs.m@Ea Extent=[5:1 - 8:2] -// CHECK: usrs.m c:usrs.m@Ea@ABA Extent=[6:3 - 6:6] -// CHECK: usrs.m c:usrs.m@Ea@CADABA Extent=[7:3 - 7:9] -// CHECK: usrs.m c:usrs.m@Ea Extent=[10:1 - 13:2] -// CHECK: usrs.m c:usrs.m@Ea@FOO Extent=[11:3 - 11:6] -// CHECK: usrs.m c:usrs.m@Ea@BAR Extent=[12:3 - 12:6] +// CHECK: usrs.m c:@Ea@ABA Extent=[5:1 - 8:2] +// CHECK: usrs.m c:@Ea@ABA@ABA Extent=[6:3 - 6:6] +// CHECK: usrs.m c:@Ea@ABA@CADABA Extent=[7:3 - 7:9] +// CHECK: usrs.m c:@Ea@FOO Extent=[10:1 - 13:2] +// CHECK: usrs.m c:@Ea@FOO@FOO Extent=[11:3 - 11:6] +// CHECK: usrs.m c:@Ea@FOO@BAR Extent=[12:3 - 12:6] // CHECK: usrs.m c:@SA@MyStruct Extent=[15:9 - 18:2] // CHECK: usrs.m c:@SA@MyStruct@FI@wa Extent=[16:3 - 16:9] // CHECK: usrs.m c:@SA@MyStruct@FI@moo Extent=[17:3 - 17:10]