rizsotto / scan-build

Clang's scan-build re-implementation in python
Other
362 stars 34 forks source link

analyze-build fail with pool.imap_unordered #117

Closed jedichen121 closed 5 years ago

jedichen121 commented 5 years ago

I was trying to use scan-build to analyze a compilation commands database. I generated the json file following this guide. However, the command analyze-build --cdb compile_commands.json failed with the following output:

analyze-build: Removing directory '/tmp/scan-build-2019-09-10-22-22-48-613760-B5hcc6' because it contains no report.
Traceback (most recent call last):
  File "/usr/local/bin/analyze-build", line 11, in <module>
    sys.exit(analyze_build())
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/__init__.py", line 129, in wrapper
    return function()
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/analyze.py", line 85, in analyze_build
    run_analyzer_parallel(compilations, args)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/analyze.py", line 181, in run_analyzer_parallel
    for current in pool.imap_unordered(run, parameters):
  File "/usr/lib/python2.7/multiprocessing/pool.py", line 668, in next
    raise value
ValueError: Expecting property name: line 5 column 7 (char 1025)

I'm using Ubuntu 16.04 with python 2.7. I also tried it again on an aarch64 with Ubuntu 18.04 and python 3.6. The result is similar:

analyze-build: Removing directory '/tmp/scan-build-2019-09-10-22-22-20-177346-7xpb6j44' because it contains no report.
Traceback (most recent call last):
  File "/usr/local/bin/analyze-build", line 10, in <module>
    sys.exit(analyze_build())
  File "/usr/local/lib/python3.6/dist-packages/libscanbuild/__init__.py", line 129, in wrapper
    return function()
  File "/usr/local/lib/python3.6/dist-packages/libscanbuild/analyze.py", line 85, in analyze_build
    run_analyzer_parallel(compilations, args)
  File "/usr/local/lib/python3.6/dist-packages/libscanbuild/analyze.py", line 181, in run_analyzer_parallel
    for current in pool.imap_unordered(run, parameters):
  File "/usr/lib/python3.6/multiprocessing/pool.py", line 735, in next
    raise value
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 5 column 7 (char 1025)

Any help would be appreciated. Thank you.

jedichen121 commented 5 years ago

I tried using a database generated by this tool and this time it reports different errors.

analyze-build: analysis failed
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/analyze.py", line 403, in run_analyzer
    cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/clang.py", line 46, in get_arguments
    output = run_command(cmd, cwd=cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/__init__.py", line 81, in run_command
    raise ex
CalledProcessError: Command '['clang', '-###', '--analyze', '-Xclang', '-analyzer-output=html', '-x', 'c++', '-U_FORTIFY_SOURCE', '-fstack-protector', '-Wno-free-nonheap-object', '-fno-omit-frame-pointer', '-std=c++0x', '-fno-canonical-system-headers', '-Wno-builtin-macro-redefined', '-D__DATE__=redacted', '-D__TIMESTAMP__=redacted', '-D__TIME__=redacted', '-iquote', '.', '-iquote', 'bazel-out/k8-fastbuild/bin', '-iquote', 'external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/bin/external/bazel_tools', u'/home/jiyangchen/.cache/bazel/_bazel_jiyangchen/3f7a264a28e299764f33b15a9c73d122/execroot/__main__/main/hello-world.cc', '-o', '/home/jiyangchen/bazel_examples/cpp-tutorial/stage1/bazel-compilation-database-0.3.5/clang-analysis/scan-build-2019-09-11-11-31-13-064029-JXCNZD']' returned non-zero exit status 1
analyze-build: failed to report failure
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/analyze.py", line 360, in report_failure
    opts['flags'] + [opts['source'], '-o', name], cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/clang.py", line 46, in get_arguments
    output = run_command(cmd, cwd=cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/__init__.py", line 81, in run_command
    raise ex
CalledProcessError: Command '['clang', '-###', '-fsyntax-only', '-E', '-x', 'c++', '-U_FORTIFY_SOURCE', '-fstack-protector', '-Wno-free-nonheap-object', '-fno-omit-frame-pointer', '-std=c++0x', '-fno-canonical-system-headers', '-Wno-builtin-macro-redefined', '-D__DATE__=redacted', '-D__TIMESTAMP__=redacted', '-D__TIME__=redacted', '-iquote', '.', '-iquote', 'bazel-out/k8-fastbuild/bin', '-iquote', 'external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/bin/external/bazel_tools', u'/home/jiyangchen/.cache/bazel/_bazel_jiyangchen/3f7a264a28e299764f33b15a9c73d122/execroot/__main__/main/hello-world.cc', '-o', '/home/jiyangchen/bazel_examples/cpp-tutorial/stage1/bazel-compilation-database-0.3.5/clang-analysis/scan-build-2019-09-11-11-31-13-064029-JXCNZD/failures/clang_other_error_LXDTK6.ii']' returned non-zero exit status 1
analyze-build: Run 'scan-view /home/jiyangchen/bazel_examples/cpp-tutorial/stage1/bazel-compilation-database-0.3.5/clang-analysis/scan-build-2019-09-11-11-31-13-064029-JXCNZD' to examine bug reports.

Are there any requirements on the compilation database itself? Thank you.

rizsotto commented 5 years ago

Hey @jedichen121 , thanks for the report.

Are you using bazel? This case it will be hard to help, mainly because

  1. I have little experience with bazel. :)
  2. Bazel compiles each file in a chroot like environment to avoid picking up the wrong header file, or linking against the wrong library (if you have multiple versions of the same on your computer).
  3. The second might implies that the JSON compilation database has relative paths to the modules you are compiling. This case if you feed that with a tool like scan-build might not find the files.

Can you validate that the JSON compilation database is actually a good one? You can try that out with clang-format or clang-tidy. If those tools are also failing, then scan-build will too. If the tools are going well with it, then it's a bug on scan-build.

jedichen121 commented 5 years ago

Hi @rizsotto , thank you for the reply. Previously, there is indeed some problems with the json file. But after fixing that, there is still problem in running scan-build with it.

First of all, the file I'm testing is very simple, only a single cc file. I'm expecting there should at least be some warnings of unused variables.

#include <iostream>       // std::cout
#include <atomic>         // std::atomic, std::memory_order_relaxed

std::atomic_int foo (0);
std::atomic<bool> shutdown_flag{false};

int main ()
{
  int x, y, z;
  foo.store(10);
  shutdown_flag.store(true);
  x = foo.load();

  return 0;
}

Unfortunately, yes I'm using bazel. bazel 0.18.0 to be more specific. But I also tried newer version, like 0.25.3, 0.27.2, 0.29.1. They didn't work either. Below is the compile_commands.json file generated. I feed it to clang-format and it didn't complain anything. But using the file formatted by clang, analyze-build will report different problem, so I'm sticking with the default generated version.

[{
        "directory": "/home/jedi/.cache/bazel/_bazel_jedi/6a26d649b48fe4d01fa9ba08a45b33cb/execroot/doraecv",
        "command": "/usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -B/usr/bin -B/usr/bin -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -std=c++0x -MD -MF bazel-out/k8-fastbuild/bin/_objs/atomic/atomic.pic.d -frandom-seed=bazel-out/k8-fastbuild/bin/_objs/atomic/atomic.pic.o -fPIC -iquote . -iquote bazel-out/k8-fastbuild/genfiles -iquote bazel-out/k8-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/k8-fastbuild/genfiles/external/bazel_tools -iquote bazel-out/k8-fastbuild/bin/external/bazel_tools -fdiagnostics-color -pthread -std=c++11 -fno-canonical-system-headers -Wno-builtin-macro-redefined -D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\" -c atomic.cc -o bazel-out/k8-fastbuild/bin/_objs/atomic/atomic.pic.o -c atomic.cc -o bazel-out/k8-fastbuild/bin/_objs/atomic/atomic.pic.o",
        "file": "atomic.cc"
      },{
        "directory": "/home/jedi/.cache/bazel/_bazel_jedi/6a26d649b48fe4d01fa9ba08a45b33cb/execroot/doraecv",
        "command": "/usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -B/usr/bin -B/usr/bin -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -std=c++0x -MD -MF bazel-out/k8-fastbuild/bin/_objs/atomic/atomic.pic.d -frandom-seed=bazel-out/k8-fastbuild/bin/_objs/atomic/atomic.pic.o -fPIC -iquote . -iquote bazel-out/k8-fastbuild/genfiles -iquote bazel-out/k8-fastbuild/bin -iquote external/bazel_tools -iquote bazel-out/k8-fastbuild/genfiles/external/bazel_tools -iquote bazel-out/k8-fastbuild/bin/external/bazel_tools -fdiagnostics-color -pthread -std=c++11 -fno-canonical-system-headers -Wno-builtin-macro-redefined -D__DATE__=\"redacted\" -D__TIMESTAMP__=\"redacted\" -D__TIME__=\"redacted\" -c atomic.cc -o bazel-out/k8-fastbuild/bin/_objs/atomic/atomic.pic.o -c atomic.cc -o bazel-out/k8-fastbuild/bin/_objs/atomic/atomic.pic.o",
        "file": "atomic.cc"
      }]

Then running analyze-build --cdb compile_commands.json, here's the output.

analyze-build: analysis failed
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/analyze.py", line 403, in run_analyzer
    cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/clang.py", line 46, in get_arguments
    output = run_command(cmd, cwd=cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/__init__.py", line 81, in run_command
    raise ex
CalledProcessError: Command '['clang', '-###', '--analyze', '-Xclang', '-analyzer-output=html', '-x', 'c++', '-U_FORTIFY_SOURCE', '-fstack-protector', '-B/usr/bin', '-B/usr/bin', '-Wno-free-nonheap-object', '-fno-omit-frame-pointer', '-std=c++0x', '-frandom-seed=bazel-out/k8-fastbuild/bin/_objs/atomic/atomic.pic.o', '-fPIC', '-iquote', '.', '-iquote', 'bazel-out/k8-fastbuild/genfiles', '-iquote', 'bazel-out/k8-fastbuild/bin', '-iquote', 'external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/genfiles/external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/bin/external/bazel_tools', '-fdiagnostics-color', '-pthread', '-std=c++11', '-fno-canonical-system-headers', '-Wno-builtin-macro-redefined', '-D__DATE__=redacted', '-D__TIMESTAMP__=redacted', '-D__TIME__=redacted', u'/home/jedi/.cache/bazel/_bazel_jedi/6a26d649b48fe4d01fa9ba08a45b33cb/execroot/doraecv/atomic.cc', '-o', '/tmp/scan-build-2019-09-12-16-37-27-062530-urMNGF']' returned non-zero exit status 1
analyze-build: analysis failed
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/analyze.py", line 403, in run_analyzer
    cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/clang.py", line 46, in get_arguments
    output = run_command(cmd, cwd=cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/__init__.py", line 81, in run_command
    raise ex
CalledProcessError: Command '['clang', '-###', '--analyze', '-Xclang', '-analyzer-output=html', '-x', 'c++', '-U_FORTIFY_SOURCE', '-fstack-protector', '-B/usr/bin', '-B/usr/bin', '-Wno-free-nonheap-object', '-fno-omit-frame-pointer', '-std=c++0x', '-frandom-seed=bazel-out/k8-fastbuild/bin/_objs/atomic/atomic.pic.o', '-fPIC', '-iquote', '.', '-iquote', 'bazel-out/k8-fastbuild/genfiles', '-iquote', 'bazel-out/k8-fastbuild/bin', '-iquote', 'external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/genfiles/external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/bin/external/bazel_tools', '-fdiagnostics-color', '-pthread', '-std=c++11', '-fno-canonical-system-headers', '-Wno-builtin-macro-redefined', '-D__DATE__=redacted', '-D__TIMESTAMP__=redacted', '-D__TIME__=redacted', u'/home/jedi/.cache/bazel/_bazel_jedi/6a26d649b48fe4d01fa9ba08a45b33cb/execroot/doraecv/atomic.cc', '-o', '/tmp/scan-build-2019-09-12-16-37-27-062530-urMNGF']' returned non-zero exit status 1
analyze-build: analysis failed
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/analyze.py", line 403, in run_analyzer
    cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/clang.py", line 46, in get_arguments
    output = run_command(cmd, cwd=cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/__init__.py", line 81, in run_command
    raise ex
CalledProcessError: Command '['clang', '-###', '--analyze', '-Xclang', '-analyzer-output=html', '-x', 'c++', '-U_FORTIFY_SOURCE', '-fstack-protector', '-B/usr/bin', '-B/usr/bin', '-Wno-free-nonheap-object', '-fno-omit-frame-pointer', '-std=c++0x', '-frandom-seed=bazel-out/k8-fastbuild/bin/_objs/atomic/atomic.pic.o', '-fPIC', '-iquote', '.', '-iquote', 'bazel-out/k8-fastbuild/genfiles', '-iquote', 'bazel-out/k8-fastbuild/bin', '-iquote', 'external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/genfiles/external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/bin/external/bazel_tools', '-fdiagnostics-color', '-pthread', '-std=c++11', '-fno-canonical-system-headers', '-Wno-builtin-macro-redefined', '-D__DATE__=redacted', '-D__TIMESTAMP__=redacted', '-D__TIME__=redacted', u'/home/jedi/.cache/bazel/_bazel_jedi/6a26d649b48fe4d01fa9ba08a45b33cb/execroot/doraecv/atomic.cc', '-o', '/tmp/scan-build-2019-09-12-16-37-27-062530-urMNGF']' returned non-zero exit status 1
analyze-build: analysis failed
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/analyze.py", line 403, in run_analyzer
    cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/clang.py", line 46, in get_arguments
    output = run_command(cmd, cwd=cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/__init__.py", line 81, in run_command
    raise ex
CalledProcessError: Command '['clang', '-###', '--analyze', '-Xclang', '-analyzer-output=html', '-x', 'c++', '-U_FORTIFY_SOURCE', '-fstack-protector', '-B/usr/bin', '-B/usr/bin', '-Wno-free-nonheap-object', '-fno-omit-frame-pointer', '-std=c++0x', '-frandom-seed=bazel-out/k8-fastbuild/bin/_objs/atomic/atomic.pic.o', '-fPIC', '-iquote', '.', '-iquote', 'bazel-out/k8-fastbuild/genfiles', '-iquote', 'bazel-out/k8-fastbuild/bin', '-iquote', 'external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/genfiles/external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/bin/external/bazel_tools', '-fdiagnostics-color', '-pthread', '-std=c++11', '-fno-canonical-system-headers', '-Wno-builtin-macro-redefined', '-D__DATE__=redacted', '-D__TIMESTAMP__=redacted', '-D__TIME__=redacted', u'/home/jedi/.cache/bazel/_bazel_jedi/6a26d649b48fe4d01fa9ba08a45b33cb/execroot/doraecv/atomic.cc', '-o', '/tmp/scan-build-2019-09-12-16-37-27-062530-urMNGF']' returned non-zero exit status 1
analyze-build: failed to report failure
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/analyze.py", line 360, in report_failure
    opts['flags'] + [opts['source'], '-o', name], cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/clang.py", line 46, in get_arguments
    output = run_command(cmd, cwd=cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/__init__.py", line 81, in run_command
    raise ex
CalledProcessError: Command '['clang', '-###', '-fsyntax-only', '-E', '-x', 'c++', '-U_FORTIFY_SOURCE', '-fstack-protector', '-B/usr/bin', '-B/usr/bin', '-Wno-free-nonheap-object', '-fno-omit-frame-pointer', '-std=c++0x', '-frandom-seed=bazel-out/k8-fastbuild/bin/_objs/atomic/atomic.pic.o', '-fPIC', '-iquote', '.', '-iquote', 'bazel-out/k8-fastbuild/genfiles', '-iquote', 'bazel-out/k8-fastbuild/bin', '-iquote', 'external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/genfiles/external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/bin/external/bazel_tools', '-fdiagnostics-color', '-pthread', '-std=c++11', '-fno-canonical-system-headers', '-Wno-builtin-macro-redefined', '-D__DATE__=redacted', '-D__TIMESTAMP__=redacted', '-D__TIME__=redacted', u'/home/jedi/.cache/bazel/_bazel_jedi/6a26d649b48fe4d01fa9ba08a45b33cb/execroot/doraecv/atomic.cc', '-o', '/tmp/scan-build-2019-09-12-16-37-27-062530-urMNGF/failures/clang_other_error_QVcIEb.ii']' returned non-zero exit status 1
analyze-build: failed to report failure
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/analyze.py", line 360, in report_failure
    opts['flags'] + [opts['source'], '-o', name], cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/clang.py", line 46, in get_arguments
    output = run_command(cmd, cwd=cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/__init__.py", line 81, in run_command
    raise ex
CalledProcessError: Command '['clang', '-###', '-fsyntax-only', '-E', '-x', 'c++', '-U_FORTIFY_SOURCE', '-fstack-protector', '-B/usr/bin', '-B/usr/bin', '-Wno-free-nonheap-object', '-fno-omit-frame-pointer', '-std=c++0x', '-frandom-seed=bazel-out/k8-fastbuild/bin/_objs/atomic/atomic.pic.o', '-fPIC', '-iquote', '.', '-iquote', 'bazel-out/k8-fastbuild/genfiles', '-iquote', 'bazel-out/k8-fastbuild/bin', '-iquote', 'external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/genfiles/external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/bin/external/bazel_tools', '-fdiagnostics-color', '-pthread', '-std=c++11', '-fno-canonical-system-headers', '-Wno-builtin-macro-redefined', '-D__DATE__=redacted', '-D__TIMESTAMP__=redacted', '-D__TIME__=redacted', u'/home/jedi/.cache/bazel/_bazel_jedi/6a26d649b48fe4d01fa9ba08a45b33cb/execroot/doraecv/atomic.cc', '-o', '/tmp/scan-build-2019-09-12-16-37-27-062530-urMNGF/failures/clang_other_error_kRs9p0.ii']' returned non-zero exit status 1
analyze-build: failed to report failure
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/analyze.py", line 360, in report_failure
    opts['flags'] + [opts['source'], '-o', name], cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/clang.py", line 46, in get_arguments
    output = run_command(cmd, cwd=cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/__init__.py", line 81, in run_command
    raise ex
CalledProcessError: Command '['clang', '-###', '-fsyntax-only', '-E', '-x', 'c++', '-U_FORTIFY_SOURCE', '-fstack-protector', '-B/usr/bin', '-B/usr/bin', '-Wno-free-nonheap-object', '-fno-omit-frame-pointer', '-std=c++0x', '-frandom-seed=bazel-out/k8-fastbuild/bin/_objs/atomic/atomic.pic.o', '-fPIC', '-iquote', '.', '-iquote', 'bazel-out/k8-fastbuild/genfiles', '-iquote', 'bazel-out/k8-fastbuild/bin', '-iquote', 'external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/genfiles/external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/bin/external/bazel_tools', '-fdiagnostics-color', '-pthread', '-std=c++11', '-fno-canonical-system-headers', '-Wno-builtin-macro-redefined', '-D__DATE__=redacted', '-D__TIMESTAMP__=redacted', '-D__TIME__=redacted', u'/home/jedi/.cache/bazel/_bazel_jedi/6a26d649b48fe4d01fa9ba08a45b33cb/execroot/doraecv/atomic.cc', '-o', '/tmp/scan-build-2019-09-12-16-37-27-062530-urMNGF/failures/clang_other_error_gmE3dh.ii']' returned non-zero exit status 1
analyze-build: failed to report failure
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/analyze.py", line 360, in report_failure
    opts['flags'] + [opts['source'], '-o', name], cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/clang.py", line 46, in get_arguments
    output = run_command(cmd, cwd=cwd)
  File "/usr/local/lib/python2.7/dist-packages/libscanbuild/__init__.py", line 81, in run_command
    raise ex
CalledProcessError: Command '['clang', '-###', '-fsyntax-only', '-E', '-x', 'c++', '-U_FORTIFY_SOURCE', '-fstack-protector', '-B/usr/bin', '-B/usr/bin', '-Wno-free-nonheap-object', '-fno-omit-frame-pointer', '-std=c++0x', '-frandom-seed=bazel-out/k8-fastbuild/bin/_objs/atomic/atomic.pic.o', '-fPIC', '-iquote', '.', '-iquote', 'bazel-out/k8-fastbuild/genfiles', '-iquote', 'bazel-out/k8-fastbuild/bin', '-iquote', 'external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/genfiles/external/bazel_tools', '-iquote', 'bazel-out/k8-fastbuild/bin/external/bazel_tools', '-fdiagnostics-color', '-pthread', '-std=c++11', '-fno-canonical-system-headers', '-Wno-builtin-macro-redefined', '-D__DATE__=redacted', '-D__TIMESTAMP__=redacted', '-D__TIME__=redacted', u'/home/jedi/.cache/bazel/_bazel_jedi/6a26d649b48fe4d01fa9ba08a45b33cb/execroot/doraecv/atomic.cc', '-o', '/tmp/scan-build-2019-09-12-16-37-27-062530-urMNGF/failures/clang_other_error_PdC_g5.ii']' returned non-zero exit status 1
analyze-build: Run 'scan-view /tmp/scan-build-2019-09-12-16-37-27-062530-urMNGF' to examine bug reports.

This is the result on x86-64. The scan-build is installed in python 2.7. However, on an ARM platform where scan-build is installed in python 3.6. When I use the same command the output is

analyze-build: Removing directory '/tmp/scan-build-2019-09-12-16-52-31-840993-99zxig0z' because it contains no report.

But still I couldn't see any report. Please let me know if this can help you pin down the problem. Thank you.

rizsotto commented 5 years ago

Hey @jedichen121 , thanks to come back with these details.

I think it aligns with what I was experiencing with bazel. The JSON compilation database points to source files in the bazel cache directory (/home/jedi/.cache/bazel/...). This is not ideal. :) I guess your source files suppose to be somewhere else. I'm not sure if the bazel cache directory will follow the original source directory structure at all. (I doubt it does.)

As I mentioned, the trick with bazel is: when it compiles a single source file, it creates a chroot envoironment. It mount only those files you are depending on. (This is very clever and makes your build realible and behaving the same way in every possible environment.) It does it for all source file compilation and for all linking too. The down side is, if you want to replay the command that bazel was doing, it will fail because files are not available.

That's why no tools will work with JSON compilation database, produced by bazel.

You might want to ask bazel to do these things for you. It probably has some "plug-in" for Clang static analyzer or for clang-format.

jedichen121 commented 5 years ago

Hi @rizsotto , thank you for the reply.

There doesn't seem to be any plug-in from bazel for clang right now and we have to abandon using scan-build to analyze our project.

However, I tried pvs-studio and it actually worked with the compilation database from bazel. Just FYI.

rizsotto commented 5 years ago

@jedichen121 closing this ticket now. Will create a more generic one for bazel. Thanks for your feedbacks. (The PVS-Studio thing is noted, will try to look at their solution.)