aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Index/USRGeneration.cpp
diff options
context:
space:
mode:
authorAlex Lorenz <arphaman@gmail.com>2023-02-23 14:14:14 -0800
committerAlex Lorenz <arphaman@gmail.com>2023-02-23 14:59:26 -0800
commitc8b37e48f6f00bb2aa3882ca3cc26082f85ca999 (patch)
tree5e75ac7a02846bddc0e9addf2bf87595eedea841 /clang/lib/Index/USRGeneration.cpp
parent5a4f193afa0d73f7ec459648d8f02535577dd604 (diff)
downloadllvm-c8b37e48f6f00bb2aa3882ca3cc26082f85ca999.zip
llvm-c8b37e48f6f00bb2aa3882ca3cc26082f85ca999.tar.gz
llvm-c8b37e48f6f00bb2aa3882ca3cc26082f85ca999.tar.bz2
[clang] extend external_source_symbol attribute with USR clause
Allow the user to specify a concrete USR in the external_source_symbol attribute. That will let Clang's indexer to use Swift USRs for Swift declarations that are represented with C++ declarations. This new clause is used by Swift when generating a C++ header representation of a Swift module: https://github.com/apple/swift/pull/63002 Differential Revision: https://reviews.llvm.org/D141324
Diffstat (limited to 'clang/lib/Index/USRGeneration.cpp')
-rw-r--r--clang/lib/Index/USRGeneration.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp
index 77b05b6..06a3717 100644
--- a/clang/lib/Index/USRGeneration.cpp
+++ b/clang/lib/Index/USRGeneration.cpp
@@ -1141,6 +1141,15 @@ bool clang::index::generateUSRForDecl(const Decl *D,
// C++'s operator new function, can have invalid locations but it is fine to
// create USRs that can identify them.
+ // Check if the declaration has explicit external USR specified.
+ auto *CD = D->getCanonicalDecl();
+ if (auto *ExternalSymAttr = CD->getAttr<ExternalSourceSymbolAttr>()) {
+ if (!ExternalSymAttr->getUSR().empty()) {
+ llvm::raw_svector_ostream Out(Buf);
+ Out << ExternalSymAttr->getUSR();
+ return false;
+ }
+ }
USRGenerator UG(&D->getASTContext(), Buf);
UG.Visit(D);
return UG.ignoreResults();