LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 34900 - clang-tidy incorrectly enables static analyzer tools when disabled in .clang-tidy
Summary: clang-tidy incorrectly enables static analyzer tools when disabled in .clang-...
Status: RESOLVED FIXED
Alias: None
Product: clang-tools-extra
Classification: Unclassified
Component: clang-tidy (show other bugs)
Version: unspecified
Hardware: PC Linux
: P enhancement
Assignee: hokein
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-10 03:34 PDT by Abigail
Modified: 2018-06-20 08:36 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Abigail 2017-10-10 03:34:38 PDT
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
  $
Comment 1 Alexander Kornienko 2017-10-10 04:56:31 PDT
Can you reproduce the same with a fixed compilations database (`clang-tidy file.cc -- -command -line -arguments ...`)?
Comment 2 Alexander Kornienko 2017-10-10 04:57:04 PDT
Also, what does `clang-tidy-6.0 -list-checks test.c` output?
Comment 3 Abigail 2017-10-10 07:50:38 PDT
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
  
  $
Comment 4 Alexander Kornienko 2017-10-13 10:09:14 PDT
Could you post the contents of the compilations database and the output of `clang-tidy test.c -extra-arg=-v`?
Comment 5 Abigail 2017-10-16 07:33:22 PDT
$ 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
$
Comment 6 Alexander Kornienko 2017-10-16 08:17:45 PDT
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.
Comment 7 Alexander Kornienko 2018-04-13 09:15:47 PDT
Haojian, you were looking at a similar issue recently. Could you investigate this as well?
Comment 8 hokein 2018-04-16 11:52:14 PDT
Yeah, this is the similar issue, sending out https://reviews.llvm.org/D45697 for review.
Comment 9 Alexander Kornienko 2018-06-20 08:36:44 PDT
Should have been fixed in https://reviews.llvm.org/rL330245