clang-tidy (from 3.9 to 6.0.0-svn315197 at least) runs analyzer checks by default when they're disabled with '-*' in the .clang-tidy file. Specifying the same checks line via the -checks or -config command-line option behaves correctly - it looks like maybe the checks specified in .clang-tidy have lower priority than the default rules? $ cat test.c int f() { int x; x = 1; x = 2; return x; } $ cat .clang-tidy Checks: '-*,cert-dcl03-c' $ bear make test.o $ clang-tidy-6.0 -list-checks Enabled checks: cert-dcl03-c $ clang-tidy-6.0 test.c 1 warning generated. test.c:3:3: warning: Value stored to 'x' is never read [clang-analyzer- deadcode.DeadStores] x = 1; ^ test.c:3:3: note: Value stored to 'x' is never read $ clang-tidy-6.0 -checks='-*,cert-dcl03-c' test.c $ clang-tidy-6.0 -config="$(cat .clang-tidy)" test.c $
Can you reproduce the same with a fixed compilations database (`clang-tidy file.cc -- -command -line -arguments ...`)?
Also, what does `clang-tidy-6.0 -list-checks test.c` output?
The issue isn't reproducible without using a compilation database: $ clang-tidy-6.0 test.c 1 warning generated. test.c:3:3: warning: Value stored to 'x' is never read [clang-analyzer- deadcode.DeadStores] x = 1; ^ test.c:3:3: note: Value stored to 'x' is never read $ clang-tidy-6.0 test.c -- $ In all cases (with or without a compilation database, with or without a filename, and with checks specified in any of the three possible ways), the -list-checks output remains the same (and doesn't mention analyzer checks): $ clang-tidy-6.0 -list-checks test.c Enabled checks: cert-dcl03-c $
Could you post the contents of the compilations database and the output of `clang-tidy test.c -extra-arg=-v`?
$ cat compile_commands.json [ { "command": "cc -c -o test.o test.c", "directory": "/tmp/tmp.6gurIYkMom", "file": "/tmp/tmp.6gurIYkMom/test.c" } ] $ clang-tidy-6.0 test.c -extra-arg=-v clang version 6.0.0-svn315197-1~exp1 (trunk) Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/6 Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/6.3.0 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7.4 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.5 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.4 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.1 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6 Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.3.0 Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.3.0 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Candidate multilib: x32;@mx32 Selected multilib: .;@m64 clang Invocation: "cc" "-cc1" "-triple" "x86_64-pc-linux-gnu" "-fsyntax-only" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "test.c" "-mrelocation-model" "static" "-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "x86-64" "-dwarf-column-info" "-debugger-tuning=gdb" "-v" "-resource-dir" "/usr/lib/llvm-6.0/bin/../lib/clang/6.0.0" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/usr/lib/llvm-6.0/bin/../lib/clang/6.0.0/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-fdebug-compilation-dir" "/tmp/tmp.6gurIYkMom" "-ferror-limit" "19" "-fmessage-length" "184" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-x" "c" "test.c" clang -cc1 version 6.0.0 based upon LLVM 6.0.0 default target x86_64-pc-linux-gnu ignoring nonexistent directory "/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/lib/llvm-6.0/bin/../lib/clang/6.0.0/include /usr/include/x86_64-linux-gnu /usr/include End of search list. 1 warning generated. test.c:3:3: warning: Value stored to 'x' is never read [clang-analyzer-deadcode.DeadStores] x = 1; ^ test.c:3:3: note: Value stored to 'x' is never read $
I can reproduce the bug on a recently build clang-tidy: /tmp/tmp.y6H8uOgIXl$ cat test.c void f() { int x; x = 1; } /tmp/tmp.y6H8uOgIXl$ cat .clang-tidy Checks: '-*,cert-dcl03-c' /tmp/tmp.y6H8uOgIXl$ cat compile_commands.json [ { "command": "cc -c -o test.o test.c", "directory": "/tmp/tmp.y6H8uOgIXl", "file": "/tmp/tmp.y6H8uOgIXl/test.c" } ] /tmp/tmp.y6H8uOgIXl$ clang_tidy test.c -list-checks Enabled checks: cert-dcl03-c /tmp/tmp.y6H8uOgIXl$ clang_tidy test.c 1 warning generated. test.c:3:3: warning: Value stored to 'x' is never read [clang-analyzer-deadcode.DeadStores] x = 1; ^ test.c:3:3: note: Value stored to 'x' is never read I'll try to look at this soon.
Haojian, you were looking at a similar issue recently. Could you investigate this as well?
Yeah, this is the similar issue, sending out https://reviews.llvm.org/D45697 for review.
Should have been fixed in https://reviews.llvm.org/rL330245