Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combining compile & link with Clang results in erroneous entry #571

Open
roubert opened this issue Apr 22, 2024 · 2 comments
Open

Combining compile & link with Clang results in erroneous entry #571

roubert opened this issue Apr 22, 2024 · 2 comments

Comments

@roubert
Copy link

roubert commented Apr 22, 2024

Create any trivial Hello, World! style program and combine compile & link on the command line like this:

$ g++-13 -o hello hello.cc
$ clang++-17 -o hello hello.cc

That's a perfectly normal thing to do and should work perfectly fine.

Then do that through Bear:

$ bear -- g++-13 -o hello hello.cc

That works fine and generates a compile_commands.json file with a single entry, which contains exactly that one single command line, just as expected.

Then do that with Clang instead:

$ bear -- clang++-17 -o hello hello.cc

That generates a compile_commands.json file with two different entries, one with that one single command line plus one for the underlying execution of the compile step, with a very long arguments list.

This is a problem because that internal command line for the internal compile step can't be executed directly from the command line and trying to use this compilation database with Clang-Tidy will therefore result in a compilation error:

$ clang-tidy-17 -checks='*' hello.cc
[…]
error: error reading 'pic': No such file or directory [clang-diagnostic-error]

That pic comes from the internal command line, which shouldn't have been included in the compile_commands.json file.

This happens both with the Bear 3.1.3 release and with Bear built from source at current HEAD.

@rizsotto
Copy link
Owner

Hey @roubert , thanks for the report.

Clang has a "driver" which implements the GCC command line, and it calls itself with the more verbose command line flags. Is this the issue? (It means the second entry is not the linking, but the same compiling pass.)

Could you send me the output?

@roubert
Copy link
Author

roubert commented Apr 23, 2024

compile_commands.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants