]> granicus.if.org Git - clang/commitdiff
[index] Distinguish USRs of anonymous enums by using their first enumerator.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 4 Mar 2016 07:17:53 +0000 (07:17 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 4 Mar 2016 07:17:53 +0000 (07:17 +0000)
rdar://24609949.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@262695 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Index/IndexingContext.cpp
lib/Index/USRGeneration.cpp
test/Index/Core/index-source.m
test/Index/usrs.m

index 87bedd778aefa66e7b0c83ba1d5c444aa242db2a..204e4300f8788a4b2792e979f2f361ccf9e8d6c5 100644 (file)
@@ -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;
index cb30090adc03dcbacb5fe419c719184fc35972a4..2722f081fef923bba1846ee95229fe71ebb67673 100644 (file)
@@ -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();
+        }
+      }
+    }
   }
   }
   
index d1326624630b75a12f651f5a35795ad88f80f621..d70974ca0349f3b7708c59d3e00471178584d941 100644 (file)
@@ -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,
+};
index fc3fbc9105789f6f9dc0a680a75f4d1c11eb19f9..92c3a3fafee2caf8ba03c9a8102fb40ce4897503 100644 (file)
@@ -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]