r262695 - [index] Distinguish USRs of anonymous enums by using their first enumerator.
Argyrios Kyrtzidis via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 3 23:17:54 PST 2016
Author: akirtzidis
Date: Fri Mar 4 01:17:53 2016
New Revision: 262695
URL: http://llvm.org/viewvc/llvm-project?rev=262695&view=rev
Log:
[index] Distinguish USRs of anonymous enums by using their first enumerator.
rdar://24609949.
Modified:
cfe/trunk/lib/Index/IndexingContext.cpp
cfe/trunk/lib/Index/USRGeneration.cpp
cfe/trunk/test/Index/Core/index-source.m
cfe/trunk/test/Index/usrs.m
Modified: cfe/trunk/lib/Index/IndexingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.cpp?rev=262695&r1=262694&r2=262695&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexingContext.cpp (original)
+++ cfe/trunk/lib/Index/IndexingContext.cpp Fri Mar 4 01:17:53 2016
@@ -206,10 +206,6 @@ static const Decl *adjustParent(const De
if (auto NS = dyn_cast<NamespaceDecl>(Parent)) {
if (NS->isAnonymousNamespace())
continue;
- } else if (auto EnumD = dyn_cast<EnumDecl>(Parent)) {
- // Move enumerators under anonymous enum to the enclosing parent.
- if (EnumD->getDeclName().isEmpty())
- continue;
} else if (auto RD = dyn_cast<RecordDecl>(Parent)) {
if (RD->isAnonymousStructOrUnion())
continue;
Modified: cfe/trunk/lib/Index/USRGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/USRGeneration.cpp?rev=262695&r1=262694&r2=262695&view=diff
==============================================================================
--- cfe/trunk/lib/Index/USRGeneration.cpp (original)
+++ cfe/trunk/lib/Index/USRGeneration.cpp Fri Mar 4 01:17:53 2016
@@ -426,7 +426,8 @@ void USRGenerator::VisitObjCPropertyImpl
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<EnumDecl>(D) &&
+ ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
return;
D = D->getCanonicalDecl();
@@ -482,8 +483,16 @@ void USRGenerator::VisitTagDecl(const Ta
else {
if (D->isEmbeddedInDeclarator() && !D->isFreeStanding()) {
printLoc(Out, D->getLocation(), Context->getSourceManager(), true);
- } else
+ } else {
Buf[off] = 'a';
+ if (auto *ED = dyn_cast<EnumDecl>(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();
+ }
+ }
+ }
}
}
Modified: cfe/trunk/test/Index/Core/index-source.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source.m?rev=262695&r1=262694&r2=262695&view=diff
==============================================================================
--- cfe/trunk/test/Index/Core/index-source.m (original)
+++ cfe/trunk/test/Index/Core/index-source.m Fri Mar 4 01:17:53 2016
@@ -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 at over_func#f# | __Z9over_funcf | Decl | rel: 0
void over_func(float x) __attribute__((overloadable));
+
+// CHECK: [[@LINE+1]]:6 | enum/C | MyEnum | c:@E at MyEnum | <no-cgname> | Def | rel: 0
+enum MyEnum {
+ // CHECK: [[@LINE+2]]:3 | enumerator/C | EnumeratorInNamed | c:@E at MyEnum@EnumeratorInNamed | <no-cgname> | Def,RelChild | rel: 1
+ // CHECK-NEXT: RelChild | MyEnum | c:@E at MyEnum
+ EnumeratorInNamed
+};
+
+// CHECK: [[@LINE+1]]:1 | enum/C | <no-name> | c:@Ea at One | <no-cgname> | Def | rel: 0
+enum {
+ // CHECK: [[@LINE+2]]:3 | enumerator/C | One | c:@Ea at One@One | <no-cgname> | Def,RelChild | rel: 1
+ // CHECK-NEXT: RelChild | <no-name> | c:@Ea at One
+ One,
+ // CHECK: [[@LINE+2]]:3 | enumerator/C | Two | c:@Ea at One@Two | <no-cgname> | Def,RelChild | rel: 1
+ // CHECK-NEXT: RelChild | <no-name> | c:@Ea at One
+ Two,
+};
Modified: cfe/trunk/test/Index/usrs.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/usrs.m?rev=262695&r1=262694&r2=262695&view=diff
==============================================================================
--- cfe/trunk/test/Index/usrs.m (original)
+++ cfe/trunk/test/Index/usrs.m Fri Mar 4 01:17:53 2016
@@ -110,12 +110,12 @@ int test_multi_declaration(void) {
// CHECK: usrs.m c:usrs.m at F@my_helper Extent=[3:1 - 3:60]
// CHECK: usrs.m c:usrs.m at 95@F at my_helper@x Extent=[3:29 - 3:34]
// CHECK: usrs.m c:usrs.m at 102@F at my_helper@y Extent=[3:36 - 3:41]
-// CHECK: usrs.m c:usrs.m at Ea Extent=[5:1 - 8:2]
-// CHECK: usrs.m c:usrs.m at Ea@ABA Extent=[6:3 - 6:6]
-// CHECK: usrs.m c:usrs.m at Ea@CADABA Extent=[7:3 - 7:9]
-// CHECK: usrs.m c:usrs.m at Ea Extent=[10:1 - 13:2]
-// CHECK: usrs.m c:usrs.m at Ea@FOO Extent=[11:3 - 11:6]
-// CHECK: usrs.m c:usrs.m at Ea@BAR Extent=[12:3 - 12:6]
+// CHECK: usrs.m c:@Ea at ABA Extent=[5:1 - 8:2]
+// CHECK: usrs.m c:@Ea at ABA@ABA Extent=[6:3 - 6:6]
+// CHECK: usrs.m c:@Ea at ABA@CADABA Extent=[7:3 - 7:9]
+// CHECK: usrs.m c:@Ea at FOO Extent=[10:1 - 13:2]
+// CHECK: usrs.m c:@Ea at FOO@FOO Extent=[11:3 - 11:6]
+// CHECK: usrs.m c:@Ea at FOO@BAR Extent=[12:3 - 12:6]
// CHECK: usrs.m c:@SA at MyStruct Extent=[15:9 - 18:2]
// CHECK: usrs.m c:@SA at MyStruct@FI at wa Extent=[16:3 - 16:9]
// CHECK: usrs.m c:@SA at MyStruct@FI at moo Extent=[17:3 - 17:10]
More information about the cfe-commits
mailing list