From 773f68761c745035130f8fec8b5419f7b14ceae5 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis <akyrtzi@gmail.com> Date: Mon, 8 Dec 2014 08:48:37 +0000 Subject: [PATCH] [libclang] Encode location info for anonymous embedded tag decls. Otherwise the USR will conflict with different embedded tag decls. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223633 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Index/USRGeneration.cpp | 6 +++++- test/Index/usrs.cpp | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Index/USRGeneration.cpp b/lib/Index/USRGeneration.cpp index ad092a20ed4..29a1b3dcd12 100644 --- a/lib/Index/USRGeneration.cpp +++ b/lib/Index/USRGeneration.cpp @@ -471,9 +471,13 @@ void USRGenerator::VisitTagDecl(const TagDecl *D) { Buf[off] = 'A'; Out << '@' << *TD; } - else + else { + if (D->isEmbeddedInDeclarator() && !D->isFreeStanding()) { + printLoc(Out, D->getLocation(), Context->getSourceManager(), true); + } else Buf[off] = 'a'; } + } // For a class template specialization, mangle the template arguments. if (const ClassTemplateSpecializationDecl *Spec diff --git a/test/Index/usrs.cpp b/test/Index/usrs.cpp index 0b66a2211ce..95d121d4829 100644 --- a/test/Index/usrs.cpp +++ b/test/Index/usrs.cpp @@ -87,6 +87,9 @@ void funWithChar(char c) {} void funWithChar(unsigned char c) {} void funWithChar(signed char c) {} +struct { int x; } embedS1; +struct { int x; } embedS2; + // RUN: c-index-test -test-load-source-usrs all %s | FileCheck %s // CHECK: usrs.cpp c:@N@foo Extent=[1:1 - 4:2] // CHECK: usrs.cpp c:@N@foo@x Extent=[2:3 - 2:8] @@ -159,3 +162,6 @@ void funWithChar(signed char c) {} // CHECK: usrs.cpp c:@F@funWithChar#C# Extent=[86:1 - 86:28] // CHECK: usrs.cpp c:@F@funWithChar#c# Extent=[87:1 - 87:37] // CHECK: usrs.cpp c:@F@funWithChar#r# Extent=[88:1 - 88:35] + +// CHECK: usrs.cpp c:usrs.cpp@S@usrs.cpp@1483@FI@x Extent=[90:10 - 90:15] +// CHECK: usrs.cpp c:usrs.cpp@S@usrs.cpp@1510@FI@x Extent=[91:10 - 91:15] -- GitLab