llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

clang-tidy 13 on Windows fails with MSVC -external:W0 flag

Open ghost opened this issue 4 years ago • 15 comments

This issue is similar to https://github.com/llvm/llvm-project/issues/52687. When we use CMake 3.22.2 (which has a workaround for the clang-tidy bug regarding -external:I) in combination with clang-tidy 13, we see the following:

error: argument unused during compilation: '-external:W0' [clang-diagnostic-unused-command-line-argument,-warnings-as-errors]

This happens because CMake will generate a -external:W0 flag in order to avoid diagnostics on external headers. I believe clang-tidy shouldn't issue a warning for this, since it's desirable that we avoid diagnostics on such headers.

ghost avatar Feb 09 '22 13:02 ghost

@llvm/issue-subscribers-clang-tidy

llvmbot avatar Feb 09 '22 14:02 llvmbot

Hi, I'm pinging this issue since I haven't gotten a response for it (nor for #52687). Is anyone looking at these?

ghost avatar Mar 02 '22 13:03 ghost

Hi @EugeneZelenko, I'm pinging this issue again since I never got any response. Is anyone looking at this?

Thanks.

ghost avatar Jun 24 '22 08:06 ghost

@martingalvan-nordic: Looks like nobody doing that.

EugeneZelenko avatar Jun 24 '22 13:06 EugeneZelenko

@EugeneZelenko are you an LLVM maintainer? Is there any way to have someone take a look at these issues?

ghost avatar Jun 24 '22 13:06 ghost

@martingalvan-nordic: I only help with labeling issues which helps to notify developers interested in particular area of LLVM code. Sorry, I don't know how to increase priority o particular issue.

EugeneZelenko avatar Jun 24 '22 13:06 EugeneZelenko

@EugeneZelenko is there anyone who's actively maintaining clang-tidy who we can contact for this? I just want to keep it under the maintainers' radar.

ghost avatar Jun 24 '22 13:06 ghost

@AaronBallman, @LegalizeAdulthood, @njames93 are most active maintainers these days.

EugeneZelenko avatar Jun 24 '22 13:06 EugeneZelenko

I won't have the chance to look into this any time soon, but something fishy is going on.

https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td#L6374 https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Driver/Options.td#L6485

So the driver certainly knows about these options. But when I test locally on Windows, the behavior is a bit surprising.

F:\source\llvm-project>llvm\out\build\x64-Debug\bin\clang-tidy.exe "C:\Users\aballman\OneDrive - Intel Corporation\Desktop\test.cpp" -checks=-*,misc-* -- -external:W0
1 warning generated.
Suppressed 1 warnings (1 with check filters).

F:\source\llvm-project>

but using the clang-cl form of the flag gives different behavior:

F:\source\llvm-project>llvm\out\build\x64-Debug\bin\clang-tidy.exe "C:\Users\aballman\OneDrive - Intel Corporation\Desktop\test.cpp" -checks=-*,misc-* -- /external:W0

F:\source\llvm-project>

and then testing with an unknown flag suggests that clang-tidy is eating flags in this form perhaps?

F:\source\llvm-project>llvm\out\build\x64-Debug\bin\clang-tidy.exe "C:\Users\aballman\OneDrive - Intel Corporation\Desktop\test.cpp" -checks=-*,misc-* -- /sdfsdfsf

F:\source\llvm-project>

Because testing with an unknown flag using dash gives the expected diagnostic:

F:\source\llvm-project>llvm\out\build\x64-Debug\bin\clang-tidy.exe "C:\Users\aballman\OneDrive - Intel Corporation\Desktop\test.cpp" -checks=-*,misc-* -- -sdfsdfsf
1 error generated.
Error while processing C:\Users\aballman\OneDrive - Intel Corporation\Desktop\test.cpp.
error: unknown argument: '-sdfsdfsf' [clang-diagnostic-error]
Found compiler error(s).

F:\source\llvm-project>

So something weird is happening here. But what's interesting is that the diagnostic you're getting is not "unknown argument" but "argument unused". I can't seem to reproduce that diagnostic behavior locally.

AaronBallman avatar Jun 24 '22 14:06 AaronBallman

Hi @AaronBallman thanks for looking into this. We've seen these issues with clang-tidy 13; not sure if that's the same version you're using. There's also a related issue, https://github.com/llvm/llvm-project/issues/52687.

We can help out with any testing you may need.

ghost avatar Jun 24 '22 14:06 ghost

Contact Alexander Kornienko

LegalizeAdulthood avatar Jun 24 '22 18:06 LegalizeAdulthood

Unfortunately, I can't verify this on Windows and I can't tell you who could. But a few ideas that come to my mind: clang-tidy seems to complain about an unused command line option. If there's anything about unused-command-line-argument in .clang-tidy (e.g. Checks: 'clang-diagnostic-unused-command-line-argument' or Checks: 'clang-diagnostic-*'), you likely want to disable this diagnostic (e.g. by appending -clang-diagnostic-unused-command-line-argument at the end of the Checks option). It would also be useful if you provided the contents of your .clang-tidy file and the full clang-tidy command line. Apart from that, could you check if there's -Wunused-command-line-argument in some shape or form in the CMake configuration?

alexfh avatar Jul 11 '22 12:07 alexfh

Hi @alexfh, sorry for the extremely late reply. I tried using LLVM 14 with CMake 3.23.3, and the result is still the same. There's no mention of unused-command-line-argument anywhere; I'm guessing it's enabled by default.

An example invocation, as generated by CMake, is:

"C:\Program Files\CMake\bin\cmake.exe" -E __run_co_compile --tidy="C:/Program Files/LLVM/bin/clang-tidy.exe;--extra-arg-before=/std:c++17;--extra-arg-before=/EHsc;--extra-arg-before=--driver-mode=cl" --source=C:\Users\mag2\example.cpp -- C:\PROGRA~2\MICROS~3\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\cl.exe  /nologo /TP -DFMT_LOCALE -DFMT_SHARED -DJSONCONS_NO_DEPRECATED -DNOMINMAX -DWINVER=0x0602 -D_CRT_SECURE_NO_WARNINGS -D_WIN32_WINNT=0x0602 -Dgsl_CONFIG_CONTRACT_VIOLATION_THROWS -Dplugin_EXPORTS -IC:\Users\mag2\include -external:IC:\Users\mag2\external -external:W0 /DWIN32 /D_WINDOWS /GR /EHsc /Zc:__cplusplus /O2 /Ob2 /DNDEBUG -MD /W4 -std:c++17 /showIncludes /FoCMakeFiles\plugin.dir\plugin.cpp.obj /FdCMakeFiles\plugin.dir\ /FS -c C:\Users\mag2\example.cpp

Many of those options can probably be shaved off. I'll try disabling clang-diagnostic-unused-command-line-argument and see if that takes care of it; however, I believe https://github.com/llvm/llvm-project/issues/52687 and @AaronBallman's findings should be looked into.

I understand you don't maintain the Windows support for this; do you know who could we contact regarding that? Thanks.

ghost avatar Aug 02 '22 13:08 ghost

Looks to be fixed with Clang Tools 15, requires --extra-arg=--driver-mode=cl

PiotrZSL avatar Sep 18 '23 19:09 PiotrZSL

@PiotrZSL thank you for doing this!

ghost avatar Sep 19 '23 07:09 ghost