This is an archive of the discontinued LLVM Phabricator instance.

Preserve -nostdinc and --sysroot when calling query driver
ClosedPublic

Authored by topisani on Jan 27 2020, 2:14 AM.

Details

Reviewers
kadircet
klimek
Summary

Solves this issue: https://github.com/clangd/clangd/issues/157

This is my first contribution to an llvm project, so I hope I'm doing it right!

Diff Detail

Event Timeline

topisani created this revision.Jan 27 2020, 2:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 27 2020, 2:14 AM

Hi @topisani, thanks for working on clangd!

Yes that bug fell through the cracks since the logs proposed in the comments were not making use of -query-driver option. Do you mind adding some logs to the bug report, without your patch so that we can clearly see its effect.

Initially we left it out, because it is always hairy to parse command line options textually, and also kind of unclear why clang wouldn't pick it up itself once you have isysroot or sysroot set, with extra logs we can be sure there are
no bugs in clang/clangd side, and it is just about a custom logic in the driver you are using.

We also need some tests, could you add some to test/system-include-extractor.test ?

clang-tools-extra/clangd/QueryDriverDatabase.cpp
257

we should also handle -nobuiltininc, --no-standard-includes and -nostdinc++.

259

could you also handle isysroot ?

280–281

let's pass the Cmd->CommandLine to extractSystemIncludes and perform the preservation logic there, so that we only do it once.

topisani updated this revision to Diff 240643.EditedJan 27 2020, 11:07 AM
topisani marked an inline comment as done.

Addressed CR comments

I'm not sure about the tests, I basically just added to the one test that already exists that it passes one of each "type" of preservable argument.

tests look good, but please upload the logs to the bug report for investigation.

clang-tools-extra/clangd/QueryDriverDatabase.cpp
137

s/auto/llvm::StringRef

same for the other two lambdas below

139

instead of having the third case, you can check whether the Arg.startswith(S), then call Arg.consume_front(S) to drop the prefix and check for emptiness or starting with equals.

clang-tools-extra/clangd/test/system-include-extractor.test
10

could you rather make use of [ -z "${args##"-nostdinc"}" ] to be compatible with non-bash shells ?

topisani updated this revision to Diff 240815.Jan 28 2020, 2:49 AM
topisani marked an inline comment as done.

Address CR Comments

I couldn't think of a good way to check for --sysroot /my/sysroot in the test in posix shell, so i hope the grep usage is OK.

kadircet added inline comments.Jan 28 2020, 3:45 AM
clang-tools-extra/clangd/QueryDriverDatabase.cpp
144

nit: early exit with

if(Found == std::end(ArgsToPreserve))
  continue;
148

nit: also increment I

clang-tools-extra/clangd/test/system-include-extractor.test
10

sorry I forgot to include *s, it should've been [ -z "${args##*"-nostdinc"*}" ].

Also you need to populate args with $* or $@ first.

topisani updated this revision to Diff 241914.Feb 2 2020, 3:08 AM

it seems like the last diff is same as the previous one, maybe you've uploaded the wrong diff ?

topisani updated this revision to Diff 242334.Feb 4 2020, 7:31 AM

Woops yeah, still getting used to using git like this

kadircet accepted this revision.Feb 4 2020, 7:57 AM

LGTM, thanks

let me know if you need me to commit this.

This revision is now accepted and ready to land.Feb 4 2020, 7:57 AM

let me know if you need me to commit this.

Yes please, thanks for your time!