llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.24k stars 12.07k forks source link

Clang18 bail out with no return code if AnalyzeTemporaryDtors is present in .clang-tidy #103024

Open CarstenTNielsen opened 3 months ago

CarstenTNielsen commented 3 months ago

If the .clang-tidy file contains the "AnalyzeTemporaryDtors: false" then clang18 is bailing out without any error code and accepts all code. If you have a syntax error you will get this output where clang report two errors due to a missing ';', but no error from clang-tidy due to the unknown AnalyzeTemporaryDtors.

[build] [1/3] Building CXX object Tasks/DataTypeTask/CMakeFiles/DataTypeTask.dir/src/DataTypeTask.cpp.o [build] FAILED: Tasks/DataTypeTask/CMakeFiles/DataTypeTask.dir/src/DataTypeTask.cpp.o ... [build] /workspaces/new524/Tasks/DataTypeTask/src/DataTypeTask.cpp:93:125: error: expected ';' at end of declaration [clang-diagnostic-error] [build] 93 | ( data.h.src == to_underlying ( TaskId::DispactherUart ) ) || ( data.h.src == to_underlying ( TaskId::DispactherUSB ) ) if ( isFromOutside ) [build] | ^ [build] | ; [build] /workspaces/new524/Tasks/DataTypeTask/src/DataTypeTask.cpp:97:3: error: expected expression [clang-diagnostic-error] [build] 97 | else [build] | ^ [build] /workspaces/new524/.clang-tidy:4:1: error: unknown key 'AnalyzeTemporaryDtors' [build] AnalyzeTemporaryDtors: false [build] ^~~~~~~~~~~~~~~~~~~~~ [build] Error parsing /workspaces/new524/.clang-tidy: Invalid argument [build] /workspaces/new524/.clang-tidy:4:1: error: unknown key 'AnalyzeTemporaryDtors' [build] AnalyzeTemporaryDtors: false [build] ^~~~~~~~~~~~~~~~~~~~~ [build] Error parsing /workspaces/new524/.clang-tidy: Invalid argument [build] /workspaces/new524/.clang-tidy:4:1: error: unknown key 'AnalyzeTemporaryDtors' [build] AnalyzeTemporaryDtors: false [build] ^~~~~~~~~~~~~~~~~~~~~ [build] Error parsing /workspaces/new524/.clang-tidy: Invalid argument [build] /workspaces/new524/.clang-tidy:4:1: error: unknown key 'AnalyzeTemporaryDtors' [build] AnalyzeTemporaryDtors: false [build] ^~~~~~~~~~~~~~~~~~~~~ [build] Error parsing /workspaces/new524/.clang-tidy: Invalid argument [build] 2 errors generated. [build] Error while processing /workspaces/new524/Tasks/DataTypeTask/src/DataTypeTask.cpp. [build] Found compiler error(s). [build] ninja: build stopped: subcommand failed.

carlosgalvezp commented 3 months ago

Hmm I cannot reproduce on trunk, clang-tidy errors as expected. Do note: you need to enable -warnings-as-errors to exit with a non-zero error code.

$ cat .clang-tidy
AnalyzeTemporaryDtors: False

$ clang-tidy -checks=* --warnings-as-errors=* foo.cpp --
/tmp/.clang-tidy:1:1: error: unknown key 'AnalyzeTemporaryDtors'
AnalyzeTemporaryDtors: False
^~~~~~~~~~~~~~~~~~~~~
Error parsing /tmp/.clang-tidy: Invalid argument
/tmp/.clang-tidy:1:1: error: unknown key 'AnalyzeTemporaryDtors'
AnalyzeTemporaryDtors: False
^~~~~~~~~~~~~~~~~~~~~
Error parsing /tmp/.clang-tidy: Invalid argument
/tmp/.clang-tidy:1:1: error: unknown key 'AnalyzeTemporaryDtors'
AnalyzeTemporaryDtors: False
^~~~~~~~~~~~~~~~~~~~~
Error parsing /tmp/.clang-tidy: Invalid argument
/tmp/.clang-tidy:1:1: error: unknown key 'AnalyzeTemporaryDtors'
AnalyzeTemporaryDtors: False
^~~~~~~~~~~~~~~~~~~~~
Error parsing /tmp/.clang-tidy: Invalid argument
5 warnings generated.
/tmp/foo.cpp:1:7: error: declaration must be enclosed within the 'LIBC_NAMESPACE_DECL' namespace [llvmlibc-implementation-in-namespace,-warnings-as-errors]
    1 | class A
      |       ^
/tmp/foo.cpp:3:2: error: single-argument constructors must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor,hicpp-explicit-conversions,-warnings-as-errors]
    3 |         A(int){}
      |         ^
      |         explicit 
/tmp/foo.cpp:3:7: error: all parameters should be named in a function [hicpp-named-parameter,readability-named-parameter,-warnings-as-errors]
    3 |         A(int){}
      |              ^
      |               /*unused*/
3 warnings treated as errors
$ echo $?
1
PiotrZSL commented 3 months ago

Issue is correct, if there is an error in config, then exit code is still 0 if there are no any other errors. Same with --verify-config:

root@dev-server:~# clang-tidy-20 1.cpp --checks="*" --verify-config --
/root/.clang-tidy:1:1: error: unknown key 'AnalyzeTemporaryDtors'
AnalyzeTemporaryDtors: False
^~~~~~~~~~~~~~~~~~~~~
Error parsing /root/.clang-tidy: Invalid argument
/root/.clang-tidy:1:1: error: unknown key 'AnalyzeTemporaryDtors'
AnalyzeTemporaryDtors: False
^~~~~~~~~~~~~~~~~~~~~
Error parsing /root/.clang-tidy: Invalid argument
No config errors detected.
root@dev-server:~# echo $?
0