]> granicus.if.org Git - clang/commitdiff
[Index] Use locations to uniquify function-scope BindingDecl USR
authorFangrui Song <maskray@google.com>
Tue, 9 Oct 2018 01:02:56 +0000 (01:02 +0000)
committerFangrui Song <maskray@google.com>
Tue, 9 Oct 2018 01:02:56 +0000 (01:02 +0000)
Summary:
This makes BindingDecl's of the same name have different USRs, so that references can be correctly attributed.

    int a[1] = {};
    { auto [x] = a; x; }
    { auto [x] = a; x; }

Reviewers: akyrtzi, arphaman, rsmith, hokein

Reviewed By: hokein

Subscribers: cfe-commits

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

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

lib/Index/USRGeneration.cpp
test/Index/Core/index-source.cpp

index 8194c9508fb7e632559f0926750a6aac05a28bda..f7be0a90b0afa28e8f10aa77bd5b5ffa92d4e5e4 100644 (file)
@@ -97,6 +97,7 @@ public:
   void VisitTypedefDecl(const TypedefDecl *D);
   void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
   void VisitVarDecl(const VarDecl *D);
+  void VisitBindingDecl(const BindingDecl *D);
   void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
   void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
   void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D);
@@ -334,6 +335,12 @@ void USRGenerator::VisitVarDecl(const VarDecl *D) {
   }
 }
 
+void USRGenerator::VisitBindingDecl(const BindingDecl *D) {
+  if (isLocal(D) && GenLoc(D, /*IncludeOffset=*/true))
+    return;
+  VisitNamedDecl(D);
+}
+
 void USRGenerator::VisitNonTypeTemplateParmDecl(
                                         const NonTypeTemplateParmDecl *D) {
   GenLoc(D, /*IncludeOffset=*/true);
index 6f485feb47c505eff4de419be4f3d5cdbaf3e015..0bf663e30be35a37196313920a08cbf49e6de7bd 100644 (file)
@@ -1,4 +1,5 @@
 // RUN: c-index-test core -print-source-symbols -- %s -std=c++1z -target x86_64-apple-macosx10.7 | FileCheck %s
+// RUN: c-index-test core -print-source-symbols -include-locals -- %s -std=c++1z -target x86_64-apple-macosx10.7 | FileCheck -check-prefix=LOCAL %s
 
 // CHECK: [[@LINE+1]]:7 | class/C++ | Cls | [[Cls_USR:.*]] | <no-cgname> | Def | rel: 0
 class Cls { public:
@@ -493,6 +494,7 @@ void localStructuredBindingAndRef() {
 // CHECK: [[@LINE-1]]:69 | variable/C++ | structuredBinding2 | c:@N@cpp17structuredBinding@structuredBinding2 | <no-cgname> | Ref,Read,RelCont | rel: 1
 // CHECK-NEXT: RelCont | localStructuredBindingAndRef | c:@N@cpp17structuredBinding@F@localStructuredBindingAndRef#
 // CHECK-NOT: localBinding
+// LOCAL: [[@LINE-4]]:9 | variable(local)/C++ | localBinding1 | c:index-source.cpp@25382@N@cpp17structuredBinding@F@localStructuredBindingAndRef#@localBinding1
 }
 
 }