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

ignore unknown compiler options #662

Open
Trass3r opened this issue Jan 22, 2021 · 8 comments
Open

ignore unknown compiler options #662

Trass3r opened this issue Jan 22, 2021 · 8 comments

Comments

@Trass3r
Copy link

Trass3r commented Jan 22, 2021

When a project is configured for building with gcc it may enable options that are not supported by clang.
Then I get lots of errors in the editor and in the problems view, e.g.

Unknown warning option '-Wformat-signedness' clang(-Wunknown-warning-option) [1, 1]
Unknown warning option '-Wsuggest-override'; did you mean '-Wshift-overflow'? clang(-Wunknown-warning-option) [1, 1]

System information
Output of clangd --version: 10.0.1 (https://github.com/llvm/llvm-project f79cd71e145c6fd005ba4dd1238128dfa0dc2cb6)
Editor/LSP plugin: VSCode
Operating system: WSL

@kadircet
Copy link
Member

it seems like you've explicitly turned on that warning via -Wunknown-warning-option. You can update your compilation database to not contain that flag, or switch to clangd-11 and make use of config to drop -Wunknown-warning-option. For the latter option see http://clangd.llvm.org/config.html#compileflags for details, specifically the Remove bit.

@Trass3r
Copy link
Author

Trass3r commented Jan 25, 2021

We didn't, it's on by default apparently: https://godbolt.org/z/366vTv

@kadircet
Copy link
Member

kadircet commented Jan 25, 2021

ah pardon my ignorance :/ then you can disable it by adding -Wno-unknown-warning-option via config again. e.g:

CompileFlags:
  Add: -Wno-unknown-warning-option

sam-mccall added a commit to llvm/llvm-project that referenced this issue Jan 25, 2021
This has been specifically requested:
  clangd/vscode-clangd#114
and various issues can be addressed with this as a workaround, e.g.:
  clangd/clangd#662

Differential Revision: https://reviews.llvm.org/D95349
arichardson pushed a commit to arichardson/llvm-project that referenced this issue Mar 30, 2021
This has been specifically requested:
  clangd/vscode-clangd#114
and various issues can be addressed with this as a workaround, e.g.:
  clangd/clangd#662

Differential Revision: https://reviews.llvm.org/D95349
mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
This has been specifically requested:
  clangd/vscode-clangd#114
and various issues can be addressed with this as a workaround, e.g.:
  clangd/clangd#662

Differential Revision: https://reviews.llvm.org/D95349
@ahogen
Copy link

ahogen commented Feb 27, 2023

For other googlers who found this issue and are needing to turn of GCC-specific compiler arguments like machine optimizations and whatnot, here's what I found.

I'm running Ubuntu clangd version 12.0.0-3ubuntu1~20.04.5 and am using VSCode + llvm-vs-code-extensions.vscode-clangd in a project which builds a Linux kernel module, so yes, GCC compiler. The compile_commands.json that clangd is ingesting is created by using Bear when invoking the Linux kernel makefiles.

I get lots of "Unknown argument" warnings, with a drv_unknown_argument code, such as:

Unknown argument: '-mno-fp-ret-in-387'
Unknown argument: '-mpreferred-stack-boundary=3'
Unknown argument: '-mskip-rax-setup'
Unknown argument: '-mindirect-branch=thunk-extern'
Unknown argument: '-fconserve-stack'
[...]

I found that adding the following to my .clangd config file removed these compile flags.

CompileFlags:
  Add: -Wno-unknown-warning-option
  Remove: [-m*, -f*]

(pretty sure I got this from somewhere else, but I can't seem to find it now. Will try to credit my source if I find it.)

Gnurou added a commit to Gnurou/virtio-media that referenced this issue Aug 7, 2023
Remove unknown warnings when building the compile_commands.json with
gcc. Courtesy to
clangd/clangd#662 (comment).
@lunasophia
Copy link

This "works", but it's messy. It ignores compiler flags which can change the semantics of the code the LSP is analyzing. This can mean that you miss warnings or errors that the compiler will catch later when you run it, instead of your LSP telling you about them--or, worse, that the LSP understands the code incorrectly. There are two better solutions, depending on what you want to do.

  • If sticking with gcc for building the kernel is more important to you, you can use ccls, another LSP server, which supports selecting another compiler. I encountered some errors with this that already have open bugs in the ccls project.
  • If you want to use clangd, in the specific case of building the Linux kernel (say, because you already have your system set up for it and don't want to install something else), then it makes more sense to build the kernel with clang. This support is relatively new (since ~February 2020), and it doesn't support all architectures, but if you're just doing general kernel hacking (or code reading) on your x86_64 machine, it'll work fine.

@HighCommander4
Copy link

HighCommander4 commented Apr 6, 2024

  • If sticking with gcc for building the kernel is more important to you, you can use ccls, another LSP server, which supports selecting another compiler. I encountered some errors with this that already have open bugs in the ccls project.

Do you know how this ("selecting another compiler") works with ccls? My understanding is that ccls is also built on top of the clang libraries, like clangd.

@lunasophia
Copy link

See the ccls documentation for the .ccls file, though this is getting offtopic for the clangd tracker :)

@HighCommander4
Copy link

See the ccls documentation for the .ccls file, though this is getting offtopic for the clangd tracker :)

I'm asking for the purpose of evaluating whether there is something clangd could be doing more like ccls.

I've looked at that link, but I haven't seen anything to indicate ccls has capabilities of imitating gcc more closely than clangd does. Being able to specify the compiler driver as discussed in this section seems to be the equivalent of https://clangd.llvm.org/config.html#compiler. It does not imply supporting command-line arguments that clang doesn't recognize.

Note that in the ccls FAQ, under Compiling with GCC, it says:

GCC is very similar to Clang and most options are portable. If you are using options with GCC which are not available in Clang you can use clang.excludeArgs to remove them.

which again just seems like the equivalent of https://clangd.llvm.org/config.html#remove.

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

5 participants