This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Try harder to get accurate ranges for documentSymbols in macros
ClosedPublic

Authored by nridge on Sep 28 2020, 7:31 PM.

Diff Detail

Event Timeline

nridge created this revision.Sep 28 2020, 7:31 PM
nridge requested review of this revision.Sep 28 2020, 7:31 PM

Sam, perhaps you could have a look at this? It involves tricky macro location stuff.

sammccall accepted this revision.Oct 12 2020, 2:57 AM

Thanks! This seems totally complete now, though I bet there's another case possible somehow!

clang-tools-extra/clangd/FindSymbols.cpp
196

Hmm... the common file-location case takes a pretty weird path here: both NameLoc and FallbackNameLoc end up set to Loc, and hopefully we never hit the !contains condition (but if we did, we'd just calculate it twice and then hit the second fallback)

Maybe clearer, though a little longer, to handle explicitly like

SourceLocation NameLoc = ND.getLocation();
SourceLocation FallbackNameLoc;
if (NameLoc.isMacroLocation()) {
  if (spelled in source) {
    NameLoc = getSpelling
    FallbackNameLoc = getExpanson
  } else {
    NameLoc = getExpansion
  }
}

up to you

clang-tools-extra/clangd/unittests/FindSymbolsTests.cpp
662

nit: despite the "contains" relation being critical, I think it's worth asserting the exact range

This revision is now accepted and ready to land.Oct 12 2020, 2:57 AM
nridge updated this revision to Diff 297712.Oct 12 2020, 4:25 PM
nridge marked 2 inline comments as done.

Address review comments

This revision was landed with ongoing or failed builds.Oct 12 2020, 4:26 PM
This revision was automatically updated to reflect the committed changes.