如何使用scan-build

时间:2016-09-14 13:40:33

标签: clang static-analysis

我想在不同的目标上运行clang静态分析器。这是makefile snip:

CC = <path to clang folder>/build/bin/clang
.
.
.    
src/%.o: ../src/%.c
    ${CC} --target=powerpc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@)" -o "$@" "$<"

我正在尝试编译为powerpc。这是命令行和输出:

>> <path_to_llvm_folder>/llvm/tools/clang/tools/scan-build/scan-build --use-analyzer=<path_to_llvm_folder>/build/bin/clang make
scan-build: Using '<path_to_llvm_folder>/build/bin/clang' for static analysis
Building file: ../src/testing.c
Invoking: GCC C Compiler
<path to clang folder>/llvm/tools/clang/tools/scan-build/ccc-analyzer --target=powerpc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/testing.d" -MT"src/testing.o" -o "src/testing.o" "../src/testing.c"
cc1: warning: command line option "-ftarget=powerpc" is valid for Java but not for C

请注意,尽管makefile正在调用clang - 我正在收到gcc警告...那么如何使用clang编译代码并对不同的目标进行静态分析呢?

1 个答案:

答案 0 :(得分:0)

找到了解决方案。我认为下一个参数中的ccc-analyzer脚本中存在一个错误:

my %CompilerLinkerOptionMap = (
  '-Wwrite-strings' => 0,
  '-ftrapv-handler' => 1, # specifically call out separated -f flag
  '-mios-simulator-version-min' => 0, # This really has 1 argument, but always has '='
  '-isysroot' => 1,
  '-arch' => 1,
  '-m32' => 0,
  '-m64' => 0,
  '-stdlib' => 0, # This is really a 1 argument, but always has '='
  '--sysroot' => 1,
  '-target' => 1,
  '-v' => 0,
  '-mmacosx-version-min' => 0, # This is really a 1 argument, but always has '='
  '-miphoneos-version-min' => 0 # This is really a 1 argument, but always has '='
);

'-target' => 1,

需要

'--target' => 1,

(使用双&#39; - &#39;)...