This is an archive of the discontinued LLVM Phabricator instance.

[cland] Dont emit missing newline warnings when building preamble
ClosedPublic

Authored by kadircet on Apr 14 2021, 12:20 PM.

Details

Summary

When building preamble, clangd truncates file contents. This yielded
errnous warnings in some cases.

This patch fixes the issue by turning off no-newline-at-eof warnings whenever
the file has more contents than the preamble.

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

Diff Detail

Event Timeline

kadircet created this revision.Apr 14 2021, 12:20 PM
kadircet requested review of this revision.Apr 14 2021, 12:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2021, 12:20 PM
hokein accepted this revision.Apr 21 2021, 11:43 PM

Thanks! And sorry for the delay, I somehow missed it in my inbox.

clang-tools-extra/clangd/Preamble.cpp
350

it seems that there is another similar warning warn_cxx98_compat_no_newline_eof, I think we probably should cover it.

This revision is now accepted and ready to land.Apr 21 2021, 11:43 PM
kadircet updated this revision to Diff 339901.Apr 22 2021, 11:55 PM
kadircet marked an inline comment as done.
  • Handle cxx98 and extension versions of the warning too.
This revision was landed with ongoing or failed builds.Apr 23 2021, 12:02 AM
This revision was automatically updated to reflect the committed changes.

A too-late drive-by - maybe we'd be better detecting these in clang never emitting these

Hit send too soon. But IIRC PP knows whether it's building a preamble.

Hit send too soon. But IIRC PP knows whether it's building a preamble.

That's a good point. But PP doesn't know if there's trailing content or not (in clangd's case).
So we'll end up not showing the diag even when we should (i.e. whole file is preamble without a new line at eof).
It doesn't sound too bad, but it'll effect all tools building preambles (including clang) and not just clangd so I am a little hesitant.