This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Avoid hanging in Selection when PP corrects the token sequence.
AcceptedPublic

Authored by sammccall on Oct 23 2022, 3:45 PM.

Details

Reviewers
hokein
Summary

Clang's error correction can invent extra tokens, including at the "eof"
position of various FileIDs.
(I thought this only happened at the AST level - I was mistaken).

Currently this can lead to Selection looping forever unable to make progress
because the location is not in range.
Unfortunately after fixing this the selection we get may be garbage: it can
also invent tokens whose locations coincide with real ones. Nevertheless
this is better than asserting/hanging.

Fixes https://github.com/llvm/llvm-project/issues/58482

Diff Detail

Event Timeline

sammccall created this revision.Oct 23 2022, 3:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 23 2022, 3:45 PM
sammccall requested review of this revision.Oct 23 2022, 3:45 PM
nridge added a subscriber: nridge.Oct 24 2022, 12:53 AM
hokein accepted this revision.Oct 28 2022, 5:00 AM
hokein added inline comments.
clang-tools-extra/clangd/Selection.cpp
316

It reminds me of this fix, the symptom is the same (triggers the Batch.empty() assertion).
With the current fix, it is no longer needed I think (maybe we should keep it, it seems an interesting special case.)

331

This is bad :( but I don't see other better alternative, I agree the current behavior is better than hanging forever.

This revision is now accepted and ready to land.Oct 28 2022, 5:00 AM