diff options
-rw-r--r-- | clang/lib/Index/IndexingContext.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Index/USRGeneration.cpp | 13 | ||||
-rw-r--r-- | clang/test/Index/Core/index-source.m | 17 | ||||
-rw-r--r-- | clang/test/Index/usrs.m | 12 |
4 files changed, 34 insertions, 12 deletions
diff --git a/clang/lib/Index/IndexingContext.cpp b/clang/lib/Index/IndexingContext.cpp index 87bedd778ae..204e4300f87 100644 --- a/clang/lib/Index/IndexingContext.cpp +++ b/clang/lib/Index/IndexingContext.cpp @@ -206,10 +206,6 @@ static const Decl *adjustParent(const Decl *Parent) { 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; diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp index cb30090adc0..2722f081fef 100644 --- a/clang/lib/Index/USRGeneration.cpp +++ b/clang/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<EnumDecl>(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<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(); + } + } + } } } diff --git a/clang/test/Index/Core/index-source.m b/clang/test/Index/Core/index-source.m index d1326624630..d70974ca034 100644 --- a/clang/test/Index/Core/index-source.m +++ b/clang/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 | <no-cgname> | Def | rel: 0 +enum MyEnum { + // CHECK: [[@LINE+2]]:3 | enumerator/C | EnumeratorInNamed | c:@E@MyEnum@EnumeratorInNamed | <no-cgname> | Def,RelChild | rel: 1 + // CHECK-NEXT: RelChild | MyEnum | c:@E@MyEnum + EnumeratorInNamed +}; + +// CHECK: [[@LINE+1]]:1 | enum/C | <no-name> | c:@Ea@One | <no-cgname> | Def | rel: 0 +enum { + // CHECK: [[@LINE+2]]:3 | enumerator/C | One | c:@Ea@One@One | <no-cgname> | Def,RelChild | rel: 1 + // CHECK-NEXT: RelChild | <no-name> | c:@Ea@One + One, + // CHECK: [[@LINE+2]]:3 | enumerator/C | Two | c:@Ea@One@Two | <no-cgname> | Def,RelChild | rel: 1 + // CHECK-NEXT: RelChild | <no-name> | c:@Ea@One + Two, +}; diff --git a/clang/test/Index/usrs.m b/clang/test/Index/usrs.m index fc3fbc91057..92c3a3fafee 100644 --- a/clang/test/Index/usrs.m +++ b/clang/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] |