[clang] 089b6ef - [Index] Remove reference to `UnresolvedUsingIfExists`

Ben Barham via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 22 17:19:53 PDT 2022


Author: Ben Barham
Date: 2022-04-22T17:19:33-07:00
New Revision: 089b6efefc3dbfc88e8fa92673eeb63ee78e4adf

URL: https://github.com/llvm/llvm-project/commit/089b6efefc3dbfc88e8fa92673eeb63ee78e4adf
DIFF: https://github.com/llvm/llvm-project/commit/089b6efefc3dbfc88e8fa92673eeb63ee78e4adf.diff

LOG: [Index] Remove reference to `UnresolvedUsingIfExists`

Assuming `ns::foo` doesn't exist, given:
```
using ns::foo __attribute__((using_if_exists));
```

The AST will look something like:
UsingDecl
  UsingShadowDecl
    UnresolvedUsingIfExistsDecl

Thus we end up adding a reference to `UnresolvedUsingIfExistsDecl` when
processing `UsingDecl`, but never add the decl itself. In this case the
decl is really the `UsingDecl` anyway though (which we do output), so it
makes more sense to just remove the extra reference.

Differential Revision: https://reviews.llvm.org/D124288

Added: 
    clang/test/Index/using_if_exists.cpp

Modified: 
    clang/lib/Index/IndexDecl.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Index/IndexDecl.cpp b/clang/lib/Index/IndexDecl.cpp
index 3139aedaf01d4..635174500cee7 100644
--- a/clang/lib/Index/IndexDecl.cpp
+++ b/clang/lib/Index/IndexDecl.cpp
@@ -605,9 +605,16 @@ class IndexingDeclVisitor : public ConstDeclVisitor<IndexingDeclVisitor, bool> {
     const NamedDecl *Parent = dyn_cast<NamedDecl>(DC);
     IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent,
                                          D->getLexicalDeclContext());
-    for (const auto *I : D->shadows())
+    for (const auto *I : D->shadows()) {
+      // Skip unresolved using decls - we already have a decl for the using
+      // itself, so there's not much point adding another decl or reference to
+      // refer to the same location.
+      if (isa<UnresolvedUsingIfExistsDecl>(I->getUnderlyingDecl()))
+        continue;
+
       IndexCtx.handleReference(I->getUnderlyingDecl(), D->getLocation(), Parent,
                                D->getLexicalDeclContext(), SymbolRoleSet());
+    }
     return true;
   }
 

diff  --git a/clang/test/Index/using_if_exists.cpp b/clang/test/Index/using_if_exists.cpp
new file mode 100644
index 0000000000000..ed13dad9b1f74
--- /dev/null
+++ b/clang/test/Index/using_if_exists.cpp
@@ -0,0 +1,9 @@
+// RUN: c-index-test core -print-source-symbols -- %s -target x86_64-unknown-unknown 2>&1 | FileCheck %s
+
+namespace ns {
+//  void foo();
+}
+
+using ns::foo __attribute__((using_if_exists));
+// CHECK: [[@LINE-1]]:11 | using/C++ | foo | c:@UD at foo | <no-cgname> | Decl | rel: 0
+// CHECK-NOT: <unknown>


        


More information about the cfe-commits mailing list