This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Fix locateMacroAt() for macro definition outside preamble
ClosedPublic

Authored by nridge on Nov 7 2020, 11:59 PM.

Diff Detail

Event Timeline

nridge created this revision.Nov 7 2020, 11:59 PM
nridge requested review of this revision.Nov 7 2020, 11:59 PM

Sam, you're my go-to reviewer for "tricky macro stuff", but feel free to hand off if you prefer :)

Review ping :)

sammccall accepted this revision.Dec 8 2020, 6:45 AM

Nice catch! As always, sorry about the delay.

clang-tools-extra/clangd/SourceCode.cpp
987

nit: I guess these would be clearer with auto -> SourceLocation

988

I'm a little confused about the condition here: Loc points at the macro name, which must be at least 1 character long, so we can't be at EOF, right?

Unless i'm missing something, I think we can promote to an assert

993

on the other hand, I suppose this case *is* possible with e.g. a builtin macro used at the start of the file.

I think hoisting this into the condition might be clearer by avoiding the redundant case (the actual *performance* doesn't matter, just for readability)

// If this is foo in `#undef foo`, use the old definition.
if (!MI && SM.getLocForStartOfFile(FID) != Loc)
  MI = PP.getMacroDefinitionAtLoc(II, Loc.getLocWithOffset(-1)).getMacroInfo();
This revision is now accepted and ready to land.Dec 8 2020, 6:45 AM
nridge updated this revision to Diff 311472.Dec 13 2020, 3:32 PM
nridge marked 3 inline comments as done.

Address review comments

This revision was landed with ongoing or failed builds.Dec 13 2020, 3:34 PM
This revision was automatically updated to reflect the committed changes.