This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Make use of preamble bounds from the patch inside ReplayPreamble
ClosedPublic

Authored by kadircet on Jun 16 2020, 12:56 PM.

Details

Summary

Clangd was using bounds from the stale preamble, which might result in
crashes. For example:

#include "a.h"
#include "b.h" // this line is newly inserted
#include "c.h"

PreambleBounds for the baseline only contains first two lines, but
ReplayPreamble logic contains an include from the third line. This would
result in a crash as we only lex preamble part of the current file
during ReplayPreamble.

This patch adds a preambleBounds method to PreamblePatch, which can be
used to figure out preamble bounds for the current version of the file.
Then uses it when attaching ReplayPreamble, so that it can lex the
up-to-date preamble region.

Diff Detail

Event Timeline

kadircet created this revision.Jun 16 2020, 12:56 PM
sammccall accepted this revision.Jun 17 2020, 8:16 AM
sammccall added inline comments.
clang-tools-extra/clangd/Preamble.cpp
220

nit: = {} again

288

(we know these are trivial structs, could drop move)

clang-tools-extra/clangd/Preamble.h
123

current -> Modified

I'd suggest calling this modifiedBounds()

136

nit: = {} seems less confusing.

Call this ModifiedBounds (or ModifiedPreambleBounds) as well? Not obvious to me what it is at the moment.

This revision is now accepted and ready to land.Jun 17 2020, 8:16 AM
kadircet updated this revision to Diff 271390.Jun 17 2020, 9:21 AM
kadircet marked 5 inline comments as done.
  • Address comments
clang-tools-extra/clangd/Preamble.h
136

unfortunately PreambleBounds doesn't have a default constructor :/

This revision was automatically updated to reflect the committed changes.