Skip to content

Commit

Permalink
Upstreaming changes (kythe#6128)
Browse files Browse the repository at this point in the history
* update llvm to "45726c1a3a3d89ff9f6ebe657c3cb7bcd59b88db"

For this update I changed...
* the llvm-bazel-glob.patch patch (manually because I don't know how
it was generated in the first place)
* the C++ indexer to work with changes in llvm about the representation
  of templates

* Update textproto plugin to offer some more overloads of CreateAndAddAnchorNode

* update llvm to "45726c1a3a3d89ff9f6ebe657c3cb7bcd59b88db"

For this update I changed...
* the llvm-bazel-glob.patch patch (manually because I don't know how
it was generated in the first place)
* the C++ indexer to work with changes in llvm about the representation
  of templates

* Update textproto plugin to offer some more overloads of CreateAndAddAnchorNode
  • Loading branch information
lfolger authored Aug 21, 2024
1 parent 68de2d1 commit b3f61c1
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 129 deletions.
48 changes: 30 additions & 18 deletions kythe/cxx/indexer/cxx/IndexerASTHooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2050,14 +2050,15 @@ bool IndexerASTVisitor::VisitTemplateTypeParmTypeLoc(
// NB: This function is *not* used for definition/declaration sites.
// Resolved is either a TemplateSpecializationType or a
// DeducedTemplateSpecializationType.
template <typename TypeLoc, typename Type>
template <typename Type>
bool IndexerASTVisitor::VisitTemplateSpecializationTypePairHelper(
TypeLoc Written, const Type* Resolved) {
auto NameLocation = Written.getTemplateNameLoc();
SourceRange WrittenRange, clang::TemplateName ResolvedTemplateName,
const Type* Resolved) {
auto NameLocation = WrittenRange.getBegin();
if (NameLocation.isFileID()) {
if (auto RCC = ExpandedRangeInCurrentContext(NameLocation)) {
if (auto TemplateName =
BuildNodeIdForTemplateName(Resolved->getTemplateName())) {
BuildNodeIdForTemplateName(ResolvedTemplateName)) {
NodeId DeclNode = [&] {
if (const auto* Decl = Resolved->getAsCXXRecordDecl()) {
// When aliasing is on, we need to point at the decls of total
Expand All @@ -2077,19 +2078,21 @@ bool IndexerASTVisitor::VisitTemplateSpecializationTypePairHelper(
}
}
}
RecordTypeLocSpellingLocation(Written, Resolved);
RecordTypeSpellingLocation(Resolved, WrittenRange);
return true;
}

bool IndexerASTVisitor::VisitTemplateSpecializationTypeLoc(
clang::TemplateSpecializationTypeLoc TL) {
return VisitTemplateSpecializationTypePairHelper(TL, TL.getTypePtr());
return VisitTemplateSpecializationTypePairHelper(
TL.getSourceRange(), TL.getTypePtr()->getTemplateName(), TL.getTypePtr());
}

bool IndexerASTVisitor::VisitDeducedTemplateSpecializationTypePair(
clang::DeducedTemplateSpecializationTypeLoc TL,
const clang::DeducedTemplateSpecializationType* T) {
return VisitTemplateSpecializationTypePairHelper(TL, T);
return VisitTemplateSpecializationTypePairHelper(TL.getSourceRange(),
T->getTemplateName(), T);
}

bool IndexerASTVisitor::VisitAutoTypePair(clang::AutoTypeLoc TL,
Expand Down Expand Up @@ -2904,13 +2907,24 @@ bool IndexerASTVisitor::TraverseClassTemplateDecl(
// TraverseClassTemplate{Partial}SpecializationDecl will be called).
bool IndexerASTVisitor::TraverseClassTemplateSpecializationDecl(
clang::ClassTemplateSpecializationDecl* TD) {
// Differentiate between implicit instantiations and explicit instantiations
// based on the presence of TypeSourceInfo.
// See RecursiveASTVisitor::TraverseClassTemplateSpecializationDecl for more
// detail.
if (clang::TypeSourceInfo* TSI = TD->getTypeAsWritten()) {
if (!TraverseTypeLoc(TSI->getTypeLoc())) {
return false;
SourceRange RangeOfNameWithArgs;
if (const clang::ASTTemplateArgumentListInfo* ATALI =
TD->getTemplateArgsAsWritten()) {
RangeOfNameWithArgs =
clang::SourceRange(TD->getLocation(), ATALI->getRAngleLoc());
}
VisitTemplateSpecializationTypePairHelper(
RangeOfNameWithArgs, clang::TemplateName(TD->getSpecializedTemplate()),
TD->getTypeForDecl());

if (const clang::ASTTemplateArgumentListInfo* ATALI =
TD->getTemplateArgsAsWritten()) {
for (const clang::TemplateArgumentLoc& Loc : ATALI->arguments()) {
if (auto* SourceInfo = Loc.getTypeSourceInfo()) {
if (!TraverseTypeLoc(SourceInfo->getTypeLoc())) {
return false;
}
}
}
}
if (!TraverseNestedNameSpecifierLoc(TD->getQualifierLoc())) {
Expand Down Expand Up @@ -3973,7 +3987,8 @@ IndexerASTVisitor::BuildNodeIdForTemplateName(const clang::TemplateName& Name) {
// TODO(zarko): Do we need to canonicalize `Name`?
// Maybe with Context.getCanonicalTemplateName()?
switch (Name.getKind()) {
case TemplateName::Template: {
case TemplateName::Template:
case TemplateName::QualifiedTemplate: {
const clang::TemplateDecl* TD = Name.getAsTemplateDecl();
if (const auto* TTPD = dyn_cast<clang::TemplateTemplateParmDecl>(TD)) {
return BuildNodeIdForDecl(TTPD);
Expand Down Expand Up @@ -4046,9 +4061,6 @@ IndexerASTVisitor::BuildNodeIdForTemplateName(const clang::TemplateName& Name) {
case TemplateName::AssumedTemplate:
CHECK(options_.IgnoreUnimplemented) << "TN.AssumedTemplate";
return std::nullopt;
case TemplateName::QualifiedTemplate:
CHECK(options_.IgnoreUnimplemented) << "TN.QualifiedTemplate";
return std::nullopt;
case TemplateName::DependentTemplate:
CHECK(options_.IgnoreUnimplemented) << "TN.DependentTemplate";
return std::nullopt;
Expand Down
7 changes: 4 additions & 3 deletions kythe/cxx/indexer/cxx/IndexerASTHooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,10 @@ class IndexerASTVisitor : public RecursiveTypeVisitor<IndexerASTVisitor> {
bool VisitSubstTemplateTypeParmTypeLoc(
clang::SubstTemplateTypeParmTypeLoc TL);

template <typename TypeLoc, typename Type>
bool VisitTemplateSpecializationTypePairHelper(TypeLoc Written,
const Type* Resolved);
template <typename Type>
bool VisitTemplateSpecializationTypePairHelper(
clang::SourceRange WrittenRange, clang::TemplateName ResolvedTemplateName,
const Type* Resolved);

bool VisitTemplateSpecializationTypeLoc(
clang::TemplateSpecializationTypeLoc TL);
Expand Down
26 changes: 26 additions & 0 deletions kythe/cxx/indexer/textproto/analyzer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ class TextprotoAnalyzer : public PluginApi {
proto::VName CreateAndAddAnchorNode(const proto::VName& file_vname,
absl::string_view sp) override;

proto::VName CreateAndAddAnchorNode(const proto::VName& file_vname,
absl::string_view sp, int pos,
int len) override;

proto::VName CreateAndAddAnchorNode(const proto::VName& file_vname,
absl::string_view sp, int pos) override;
proto::VName VNameForRelPath(
absl::string_view simplified_path) const override;

Expand Down Expand Up @@ -832,6 +838,26 @@ proto::VName TextprotoAnalyzer::CreateAndAddAnchorNode(
return CreateAndAddAnchorNode(file_vname, begin, end);
}

// Adds an anchor node, using the string_view's offset relative to
// `textproto_content_` (adding the given position offset) as the start
// location, with the given length.
proto::VName TextprotoAnalyzer::CreateAndAddAnchorNode(
const proto::VName& file_vname, absl::string_view sp, int pos, int len) {
CHECK(pos >= 0) << "substring in range of source";
CHECK(pos + len <= sp.size()) << "substring in range of source";
const int begin = sp.begin() + pos - textproto_content_.begin();
const int end = begin + len;
return CreateAndAddAnchorNode(file_vname, begin, end);
}

// Adds an anchor node, using the string_view's offset relative to
// `textproto_content_` (adding the given position offset) as the start
// location.
proto::VName TextprotoAnalyzer::CreateAndAddAnchorNode(
const proto::VName& file_vname, absl::string_view sp, int pos) {
return CreateAndAddAnchorNode(file_vname, sp, pos, sp.size() - pos);
}

void TextprotoAnalyzer::EmitDiagnostic(const proto::VName& file_vname,
absl::string_view signature,
absl::string_view msg) {
Expand Down
11 changes: 11 additions & 0 deletions kythe/cxx/indexer/textproto/plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <string>

#include "absl/status/status.h"
#include "absl/strings/string_view.h"
#include "kythe/cxx/common/indexing/KytheGraphRecorder.h"
#include "kythe/proto/analysis.pb.h"

Expand All @@ -43,6 +44,16 @@ class PluginApi {
virtual proto::VName CreateAndAddAnchorNode(const proto::VName& file_vname,
absl::string_view sp) = 0;

// Adds an anchor for a substring of the text span and returns its VName.
virtual proto::VName CreateAndAddAnchorNode(const proto::VName& file_vname,
absl::string_view sp, int pos,
int len) = 0;

// Adds an anchor for a substring of the text span and returns its VName.
virtual proto::VName CreateAndAddAnchorNode(const proto::VName& file_vname,
absl::string_view sp,
int pos) = 0;

virtual KytheGraphRecorder* recorder() = 0;

virtual void EmitDiagnostic(const proto::VName& file_vname,
Expand Down
2 changes: 1 addition & 1 deletion setup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def kythe_rule_repositories():
maybe(
github_archive,
repo_name = "llvm/llvm-project",
commit = "63d8058ef50a3186b6b6a5db254f44673fea3d19",
commit = "45726c1a3a3d89ff9f6ebe657c3cb7bcd59b88db",
name = "llvm-raw",
build_file_content = "#empty",
patch_args = ["-p1"],
Expand Down
110 changes: 3 additions & 107 deletions third_party/llvm-bazel-glob.patch
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,6 @@ index be02c2270432..fc106de5df7e 100644
load(
":libc_build_rules.bzl",
"libc_function",
diff --git a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
index b1140a5a1609..dfd80c704527 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
@@ -85,9 +85,9 @@ libc_support_library(
"//libc:__support_fputil_fp_bits",
"//libc:__support_fputil_fpbits_str",
"//libc:__support_fputil_rounding_mode",
+ "//libc:hdr_fenv_macros",
"//libc:hdr_math_macros",
- "//libc:hdr_fenv_macros",
- "//libc:types_fenv_t",
+ "//libc:types_fenv_t",
],
)

diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/__support/FPUtil/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/__support/FPUtil/BUILD.bazel
index ff3b035f64ad..998fdfe7e005 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/__support/FPUtil/BUILD.bazel
Expand All @@ -150,83 +134,6 @@ index ff3b035f64ad..998fdfe7e005 100644
- "//libc:hdr_fenv_macros",
],
)
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/fenv/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/fenv/BUILD.bazel
index fc3ab3da3587..195185d5581e 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/fenv/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/fenv/BUILD.bazel
@@ -21,7 +21,7 @@ libc_test(
],
deps = [
"//libc:__support_fputil_fenv_impl",
- "//libc:hdr_fenv_macros",
+ "//libc:hdr_fenv_macros",
],
)

@@ -48,8 +48,8 @@ libc_test(
"//libc:__support_common",
"//libc:__support_fputil_fenv_impl",
"//libc:__support_macros_properties_architectures",
+ "//libc:hdr_fenv_macros",
"//libc/test/UnitTest:fp_test_helpers",
- "//libc:hdr_fenv_macros",
],
)

@@ -64,8 +64,8 @@ libc_test(
"//libc:__support_common",
"//libc:__support_fputil_fenv_impl",
"//libc:__support_macros_properties_architectures",
+ "//libc:types_fenv_t",
"//libc/test/UnitTest:fp_test_helpers",
- "//libc:types_fenv_t",
],
)

@@ -79,7 +79,7 @@ libc_test(
],
deps = [
"//libc:__support_fputil_fenv_impl",
- "//libc:types_fexcept_t",
+ "//libc:types_fexcept_t",
],
)

@@ -91,7 +91,7 @@ libc_test(
],
deps = [
"//libc:__support_fputil_fenv_impl",
- "//libc:hdr_fenv_macros",
+ "//libc:hdr_fenv_macros",
],
)

@@ -106,7 +106,7 @@ libc_test(
deps = [
"//libc:__support_common",
"//libc:__support_macros_properties_architectures",
- "//libc:hdr_fenv_macros",
+ "//libc:hdr_fenv_macros",
],
)

@@ -118,7 +118,7 @@ libc_test(
],
deps = [
"//libc:__support_fputil_fenv_impl",
- "//libc:types_fenv_t",
+ "//libc:types_fenv_t",
],
)

@@ -133,6 +133,6 @@ libc_test(
],
deps = [
"//libc:__support_fputil_fenv_impl",
- "//libc:types_fenv_t",
+ "//libc:types_fenv_t",
],
)
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
index 7d4b9978db3f..eccea8faeebc 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/math/smoke/BUILD.bazel
Expand Down Expand Up @@ -260,9 +167,9 @@ index 7958c6024875..fe245355846e 100644
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
+load("@io_kythe//tools:build_rules/support.bzl", glob = "allow_empty_glob")
load("@build_bazel_apple_support//rules:apple_genrule.bzl", "apple_genrule")
load("//:vars.bzl", "LLVM_VERSION_MAJOR", "LLVM_VERSION_MINOR", "LLVM_VERSION_PATCH", "LLVM_VERSION_SUFFIX", "PACKAGE_VERSION")
load("//lldb/source/Plugins:plugin_config.bzl", "DEFAULT_PLUGINS", "DEFAULT_SCRIPT_PLUGINS", "OBJCPP_COPTS")
load("//mlir:tblgen.bzl", "gentbl_cc_library", "td_library")
diff --git a/utils/bazel/llvm-project-overlay/lldb/source/Plugins/BUILD.bazel b/utils/bazel/llvm-project-overlay/lldb/source/Plugins/BUILD.bazel
index e0907a838148..18c2ed793912 100644
--- a/utils/bazel/llvm-project-overlay/lldb/source/Plugins/BUILD.bazel
Expand Down Expand Up @@ -316,8 +223,8 @@ index 58538b66c5e0..b32ab40843f3 100644
--- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
@@ -6,6 +6,7 @@
# The MLIR "Multi-Level Intermediate Representation" Compiler Infrastructure

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
+load("@io_kythe//tools:build_rules/support.bzl", glob = "allow_empty_glob")
load(
Expand Down Expand Up @@ -436,19 +343,8 @@ index dc5f4047c286..79b1cf855c1e 100644
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
+load("@io_kythe//tools:build_rules/support.bzl", glob = "allow_empty_glob")
load("//llvm:lit_test.bzl", "package_path")
load("//mlir:tblgen.bzl", "gentbl_cc_library", "td_library")
load("//mlir:tblgen.bzl", "gentbl_cc_library", "gentbl_sharded_ops", "td_library")

@@ -418,9 +419,9 @@ cc_library(
"//mlir:SideEffectInterfaces",
"//mlir:Support",
"//mlir:TensorDialect",
- "//mlir:TranslateLib",
"//mlir:TransformUtils",
"//mlir:Transforms",
+ "//mlir:TranslateLib",
"//mlir:ValueBoundsOpInterface",
"//mlir:ViewLikeInterface",
],
diff --git a/utils/bazel/llvm-project-overlay/mlir/test/Conversion/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/test/Conversion/BUILD.bazel
index b00e8f243c29..0bd0450c4690 100644
--- a/utils/bazel/llvm-project-overlay/mlir/test/Conversion/BUILD.bazel
Expand Down

0 comments on commit b3f61c1

Please sign in to comment.