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

--query-driver does not work with fallback flags for .h file if driver is gcc and objective-c++ support is not installed #1568

Closed
HighCommander4 opened this issue Apr 2, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@HighCommander4
Copy link

HighCommander4 commented Apr 2, 2023

One of the main use cases of the Compiler: config option is to allow specifying the compiler to query for built-in include paths in projects that don't have a compile_commands.json file.

While the Compiler: config option itself was added in clangd 14, this use case was broken until clangd 16 due to #1089 (the edit to the compile command to replace argv[0] with Compiler: was performed after the system include extractor had already run).

Today, I discovered that this use case is still partially broken even in clangd 16.

If the project has no compile_commands.json file, the initial compile command is the fallback command returned by GlobalCompilationDatabase::getFallbackCommand(). If the file being opened is a .h file, the fallback command contains -xobjective-c++-header, since we don't know the language of the header and objective-c++ is the most permissive of the supported languages. This -x flag is preserved in the command used to extract system includes from the driver.

If the driver is a gcc, we run into an unfortunate snag: gcc's objective-c++ support is often contained in a separate package, e.g. gobjc++, which is not necessarily installed if the user isn't actually writing objective-c++. In such cases, the system include extraction command fails with:

g++: error trying to exec 'cc1objplus': execvp: No such file or directory
@HighCommander4 HighCommander4 added the bug Something isn't working label Apr 2, 2023
@HighCommander4
Copy link
Author

I should add that the issue also arises in cases where the project itself has a compile_commands.json file, but the user is trying to open an external header (and not using --compile-commands-dir).

@HighCommander4
Copy link
Author

HighCommander4 commented Apr 2, 2023

I installed gobjc++ and looked at the built-in include paths with -xobjective-c++-header, and they're the same as with -xc++-header.

Maybe it's safe to just unconditionally downgrade -xobjective-c++-header to -xc++-header in the system include extractor?

@HighCommander4
Copy link
Author

Linking to proposed fix for this: https://reviews.llvm.org/D147905

@HighCommander4
Copy link
Author

Fixed on trunk, which is now targeting clangd 18.

It would be nice to have the fix in clangd 17 as well (too late for clangd 16); I will request a cherry-pick.

llvmbot pushed a commit to llvm/llvm-project-release-prs that referenced this issue Aug 18, 2023
tru pushed a commit to llvm/llvm-project-release-prs that referenced this issue Aug 21, 2023
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 2, 2023
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 2, 2023
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 2, 2023
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 3, 2023
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 3, 2023
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 6, 2023
razmser pushed a commit to SuduIDE/llvm-project that referenced this issue Oct 11, 2023
nachovizzo added a commit to nachovizzo/dotfiles that referenced this issue Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant