This is an archive of the discontinued LLVM Phabricator instance.

[clang] Mark re-injected tokens appropriately during pragma handling
ClosedPublic

Authored by kadircet on Mar 12 2021, 12:37 AM.

Details

Summary

This hides such tokens from TokenWatcher, preventing crashes in clients
trying to match spelled and expanded tokens.

Fixes https://github.com/clangd/clangd/issues/712

Diff Detail

Event Timeline

kadircet created this revision.Mar 12 2021, 12:37 AM
kadircet requested review of this revision.Mar 12 2021, 12:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 12 2021, 12:37 AM
kadircet updated this revision to Diff 330184.Mar 12 2021, 2:15 AM
  • Add test
sammccall accepted this revision.Mar 12 2021, 4:59 AM
sammccall added inline comments.
clang/lib/Parse/ParsePragma.cpp
2616

It was surprisingly hard for me to see that the changes here were just marking everything in TokenArray as reinjected.

Could you do that directly with a loop at the end instead? (It's hard to imagine a significant performance difference)

(And the same in all the other modified sites)

2623

as discussed offline, it wasn't clear to me that this was "in time" as we're not trying to affect the behavior of the subsequent PP.Lex call, not the previous one.

Maybe we could extract a function to mark an ArrayRef as reinject with a name that makes this clear.
markAsReinjectedForRelexing() or something...

This revision is now accepted and ready to land.Mar 12 2021, 4:59 AM
kadircet updated this revision to Diff 330266.Mar 12 2021, 9:14 AM
  • Introduce a helper to mark tokens as reinjected
This revision was landed with ongoing or failed builds.Mar 12 2021, 9:18 AM
This revision was automatically updated to reflect the committed changes.