This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Use command line adjusters for inserting compile flags
ClosedPublic

Authored by kadircet on Mar 29 2021, 11:34 AM.

Details

Diff Detail

Event Timeline

kadircet created this revision.Mar 29 2021, 11:34 AM
kadircet requested review of this revision.Mar 29 2021, 11:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2021, 11:34 AM

I was able to replicate the issue on Fedora 33 and cause clangd to fail by adding -- before the file to be compiled.

After applying the patch, the issue is fixed. All the unit tests and relevant test past.

I could go on Windows and replicate the issue and apply the fix as I have a llvm build setup there, but not sure if it is worth the time sink.

sammccall accepted this revision.Jun 1 2021, 3:26 AM

Thanks for fixing!

clang-tools-extra/clangd/CompileCommands.cpp
230

This extra copy is really silly :-(
please move(ToAppend) and make the whole thing conditional on !ToAppend.empty() (even though that'll be pretty much always...). Sadly move(Cmd) won't work.

One day if we feel like shaving a yak, we could add migrate to an ArgsAdjuster interface that takes a mutable CompileCommand&...

clang-tools-extra/clangd/ConfigCompile.cpp
273

Hmm, with this new logic in place, if we "normalized" command lines by moving the filename to the end, we'd resolve https://github.com/clangd/clangd/issues/555 without having to complicate the config file model.

I wonder how hard that is...

274–276

maybe a comment "The point to insert at - usually the end"?
(Since this looks suspiciously like an unhandled error case)

This revision is now accepted and ready to land.Jun 1 2021, 3:26 AM
kadircet marked an inline comment as done.Jun 1 2021, 7:27 AM
kadircet added inline comments.
clang-tools-extra/clangd/ConfigCompile.cpp
273

yes actually that sounds like a good idea. Ofc, but at the cost of one extra command line arg parsing. I don't think we have any other reliable way to detect input argument in the flags.

Within CommandMangler::adjust, we can start by doing the normalization, parsing args considering normalized if it has -- already, and moving filename to the end with a -- before otherwise.

Shouldn't be too hard, can't think of a better place in the pipeline. We can also do this inside OverlayCDB before calling the adjusters, but it feels a little bit less natural.

Happy to send out a patch if you think that's a good idea.

kadircet updated this revision to Diff 348972.Jun 1 2021, 7:27 AM
  • Address comments