This is an archive of the discontinued LLVM Phabricator instance.

[Driver] Add an option for createInvocationFromCommandLine to recover on errors
ClosedPublic

Authored by ilya-biryukov on Aug 26 2019, 3:07 AM.

Details

Summary

Previously, it would always return nullptr on any error.
This change adds a parameter, controlling whether the function should
attempt to return a non-null result even if unknown arguments (or other
errors were encountered).

The new behavior is only used in clangd.

Considered an alternative of changing the return value instead of adding
a new parameter, but that would require updating all callsites. Settled
with the parameter to minimize the code changes.

Diff Detail

Repository
rL LLVM

Event Timeline

ilya-biryukov created this revision.Aug 26 2019, 3:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 26 2019, 3:07 AM

It does seem reasonable for Clangd to recover when it sees unknown command line flags (after all, in compiler_commands.json we can see command line flags from past and future versions of Clang, GCC and other compilers -- whatever the build system decided to write there). However I have two requests:

  • In the doc comment for CompilerInvocation::CreateFromArgs, could you add a note that it does a best effort to provide a CompilerInvocation even if it returns false? Right now the doc comment reads like there are no guarantees at all if it returns false.
  • (can be a separate patch) Could we produce a diagnostic in the affected TU notifying the user that the compiler commands could not be parsed and we did our best to recover, but it may be completely wrong?
  • In the doc comment for CompilerInvocation::CreateFromArgs, could you add a note that it does a best effort to provide a CompilerInvocation even if it returns false? Right now the doc comment reads like there are no guarantees at all if it returns false.

Will do and update this patch.

  • (can be a separate patch) Could we produce a diagnostic in the affected TU notifying the user that the compiler commands could not be parsed and we did our best to recover, but it may be completely wrong?

You are right, this is long overdue. Although not specific to this particular patch, which aims at options for better recovery rather than fixing this limitation of clangd.
Nevertheless, D66759 surfaces the errors from command-line arguments in clangd and should address this point as well.

nridge added a subscriber: nridge.Aug 26 2019, 7:19 PM
  • Add a comment to CreateFromArgs
  • Fix english grammar in the comment
gribozavr accepted this revision.Aug 27 2019, 1:41 AM
gribozavr added inline comments.
clang/include/clang/Frontend/CompilerInvocation.h
150 ↗(On Diff #217320)

\returns false if an error...

(\returns is a paragraph command. It starts a new paragraph.)

This revision is now accepted and ready to land.Aug 27 2019, 1:41 AM
ilya-biryukov marked 2 inline comments as done.
  • Start a paragrah with \returns instead of putting it in the middle
ilya-biryukov added inline comments.Aug 27 2019, 2:53 AM
clang/include/clang/Frontend/CompilerInvocation.h
150 ↗(On Diff #217320)

TIL something about doxygen :-)

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 27 2019, 3:06 AM