r307855 - [index] Don't add relation to a NamedDecl with no name

Ben Langmuir via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 12 15:05:30 PDT 2017


Author: benlangmuir
Date: Wed Jul 12 15:05:30 2017
New Revision: 307855

URL: http://llvm.org/viewvc/llvm-project?rev=307855&view=rev
Log:
[index] Don't add relation to a NamedDecl with no name

Unless it's one of the special cases (tag, category) that we can handle.
This syncs up the check between handling a decl and handling a relation.

This would cause invalid nameless decls to end up in relations despite
having no name or USR.

rdar://problem/32474406

Added:
    cfe/trunk/test/Index/Core/index-source-invalid-name.cpp
Modified:
    cfe/trunk/lib/Index/IndexingContext.cpp

Modified: cfe/trunk/lib/Index/IndexingContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexingContext.cpp?rev=307855&r1=307854&r2=307855&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexingContext.cpp (original)
+++ cfe/trunk/lib/Index/IndexingContext.cpp Wed Jul 12 15:05:30 2017
@@ -229,6 +229,12 @@ static bool isDeclADefinition(const Decl
   return false;
 }
 
+/// Whether the given NamedDecl should be skipped because it has no name.
+static bool shouldSkipNamelessDecl(const NamedDecl *ND) {
+  return ND->getDeclName().isEmpty() && !isa<TagDecl>(ND) &&
+         !isa<ObjCCategoryDecl>(ND);
+}
+
 static const Decl *adjustParent(const Decl *Parent) {
   if (!Parent)
     return nullptr;
@@ -243,8 +249,8 @@ static const Decl *adjustParent(const De
     } else if (auto RD = dyn_cast<RecordDecl>(Parent)) {
       if (RD->isAnonymousStructOrUnion())
         continue;
-    } else if (auto FD = dyn_cast<FieldDecl>(Parent)) {
-      if (FD->getDeclName().isEmpty())
+    } else if (auto ND = dyn_cast<NamedDecl>(Parent)) {
+      if (shouldSkipNamelessDecl(ND))
         continue;
     }
     return Parent;
@@ -315,9 +321,7 @@ bool IndexingContext::handleDeclOccurren
                                            const DeclContext *ContainerDC) {
   if (D->isImplicit() && !isa<ObjCMethodDecl>(D))
     return true;
-  if (!isa<NamedDecl>(D) ||
-      (cast<NamedDecl>(D)->getDeclName().isEmpty() &&
-       !isa<TagDecl>(D) && !isa<ObjCCategoryDecl>(D)))
+  if (!isa<NamedDecl>(D) || shouldSkipNamelessDecl(cast<NamedDecl>(D)))
     return true;
 
   SourceManager &SM = Ctx->getSourceManager();

Added: cfe/trunk/test/Index/Core/index-source-invalid-name.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/Core/index-source-invalid-name.cpp?rev=307855&view=auto
==============================================================================
--- cfe/trunk/test/Index/Core/index-source-invalid-name.cpp (added)
+++ cfe/trunk/test/Index/Core/index-source-invalid-name.cpp Wed Jul 12 15:05:30 2017
@@ -0,0 +1,13 @@
+// RUN: c-index-test core -print-source-symbols -- %s -std=c++1z -target x86_64-apple-macosx10.7 | FileCheck %s
+
+namespace rdar32474406 {
+// CHECK: [[@LINE+1]]:6 | function/C | foo | c:@N at rdar32474406@F at foo# | __ZN12rdar324744063fooEv | Decl,RelChild | rel: 1
+void foo();
+// CHECK: [[@LINE+1]]:16 | type-alias/C | Func_t | c:index-source-invalid-name.cpp at N@rdar32474406 at T@Func_t | <no-cgname> | Def,RelChild | rel: 1
+typedef void (*Func_t)();
+// CHECK: [[@LINE+4]]:1 | type-alias/C | Func_t | c:index-source-invalid-name.cpp at N@rdar32474406 at T@Func_t | <no-cgname> | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | rdar32474406 | c:@N at rdar32474406
+// CHECK: [[@LINE+2]]:14 | function/C | foo | c:@N at rdar32474406@F at foo# | __ZN12rdar324744063fooEv | Ref,RelCont | rel: 1
+// CHECK-NEXT: RelCont | rdar32474406 | c:@N at rdar32474406
+Func_t[] = { foo }; // invalid decomposition
+}




More information about the cfe-commits mailing list