Skip to content

Commit

Permalink
fix(cxx_indexer): address issue #5935 (when aliasing is on) (#5937)
Browse files Browse the repository at this point in the history
  • Loading branch information
zrlk committed Nov 16, 2023
1 parent 7bb8054 commit 1ac7b16
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
7 changes: 7 additions & 0 deletions kythe/cxx/indexer/cxx/GraphObserver.h
Expand Up @@ -190,6 +190,13 @@ class GraphObserver {
}
const std::string& getRawIdentity() const { return Identity; }
const ClaimToken* getToken() const { return Token; }
/// \brief Create a derived NodeId from this one.
///
/// This is meant for debugging. You'll likely want to disable
/// `ForceEncodeString` in GraphObserver.cc.
NodeId derive(const std::string& s) const {
return NodeId(Token, Identity + s);
}

private:
friend class GraphObserver;
Expand Down
25 changes: 22 additions & 3 deletions kythe/cxx/indexer/cxx/IndexerASTHooks.cc
Expand Up @@ -3756,6 +3756,15 @@ bool IndexerASTVisitor::VisitUsingShadowDecl(
const clang::UsingShadowDecl* Decl) {
if (auto RCC =
ExplicitRangeInCurrentContext(RangeForNameOfDeclaration(Decl))) {
if (auto* ctd = llvm::dyn_cast_or_null<clang::ClassTemplateDecl>(
Decl->getTargetDecl());
ctd != nullptr && ctd->getTemplatedDecl() != nullptr &&
absl::GetFlag(FLAGS_experimental_alias_template_instantiations)) {
Observer.recordDeclUseLocation(
RCC.value(), BuildNodeIdForDecl(ctd->getTemplatedDecl()),
GraphObserver::Claimability::Claimable, IsImplicit(RCC.value()));
return true;
}
Observer.recordDeclUseLocation(
RCC.value(), BuildNodeIdForDecl(Decl->getTargetDecl()),
GraphObserver::Claimability::Claimable, IsImplicit(RCC.value()));
Expand Down Expand Up @@ -4072,6 +4081,19 @@ IndexerASTVisitor::BuildNodeIdForTemplateName(const clang::TemplateName& Name) {
LOG(FATAL) << "BuildNodeIdForTemplateName can't identify TemplateDecl";
}
}
case TemplateName::UsingTemplate: {
// UsingShadowDecl::getIntroducer() will return the specific
// using-declaration. We don't index UsingShadowDecls as definition sites,
// so it's not helpful to point at that declaration.
const clang::UsingShadowDecl* decl = Name.getAsUsingShadowDecl();
if (auto* ctd = llvm::dyn_cast_or_null<clang::ClassTemplateDecl>(
decl->getTargetDecl());
ctd != nullptr && ctd->getTemplatedDecl() != nullptr &&
absl::GetFlag(FLAGS_experimental_alias_template_instantiations)) {
return BuildNodeIdForDecl(ctd->getTemplatedDecl());
}
return BuildNodeIdForDecl(decl);
}
case TemplateName::OverloadedTemplate:
CHECK(options_.IgnoreUnimplemented) << "TN.OverloadedTemplate";
return std::nullopt;
Expand All @@ -4090,9 +4112,6 @@ IndexerASTVisitor::BuildNodeIdForTemplateName(const clang::TemplateName& Name) {
case TemplateName::SubstTemplateTemplateParmPack:
CHECK(options_.IgnoreUnimplemented) << "TN.SubstTemplateTemplateParmPack";
return std::nullopt;
case TemplateName::UsingTemplate:
CHECK(options_.IgnoreUnimplemented) << "TN.UsingTemplate";
return std::nullopt;
}
CHECK(options_.IgnoreUnimplemented)
<< "Unexpected TemplateName kind: " << Name.getKind();
Expand Down
1 change: 0 additions & 1 deletion kythe/cxx/indexer/cxx/testdata/BUILD
Expand Up @@ -2741,7 +2741,6 @@ cc_indexer_test(
srcs = ["template/template_using_name.cc"],
experimental_alias_template_instantiations = True,
ignore_dups = True,
ignore_unimplemented = True,
tags = ["template"],
)

Expand Down
Expand Up @@ -4,11 +4,10 @@ namespace ns {
//- @S defines/binding TemplateS
template <typename T> struct S {};
}
//- !{@S ref TemplateS} // TODO(zrlk): Targets missing node.
// NB: using declaration cannot refer to a template specialization
//- @S ref TemplateS
using ns::S;
// This trips an unimplemented check (TN.UsingTemplate) in
// BuildNodeIdForTemplateName
//- @"S<int>" ref TemplateSInt
//- TemplateSInt param.0 TemplateS
//- !{@S ref TemplateS} // TODO(zrlk): No anchor for S
//- @S ref TemplateS
S<int> s;

0 comments on commit 1ac7b16

Please sign in to comment.