我正在为基于ARM Cortex-M的MCU开发“裸机”C / C ++应用程序。 我想将Clang静态分析器整合到我的构建系统中。
所以而不是
arm-none-eabi-g++ ....
我现在用
scan-build arm-none-eabi-g++ ...
这似乎工作正常,但我得到了一堆关于CMSIS头文件和我从芯片制造商那里得到的东西的消息:
我同意他们应该使用uintptr_t
而不是int32_t
,但不能重写整个代码库和CMSIS标头。我可以告诉scan-build
这个平台上的指针实际上是32位,所以不会丢失信息吗?
我试图告诉它考虑我使用的是哪个平台。但如果我使用scan-build --analyzer-target=arm-none-eabi
,我会得到:
再次,在CMSIS标题中。
我的问题是:
cstring
时,为什么分析器找不到--analyzer-target=arm-none-eabi
标题?或者:
修改
我也尝试了以下建议,但它没有用,导致了相同的错误:
scan-build
--use-cc=/usr/bin/arm-none-eabi-gcc
--use-c++=/usr/bin/arm-none-eabi-g++
--analyzer-target=arm-none-eabi
arm-none-eabi-g++ ...
注意:我使用 qbs 构建系统,并使用scan-build
文件中的cpp.compilerWrapper
属性生成.qbs
次调用。< / p>
典型的命令如下所示:
/usr/bin/scan-build --use-cc=/usr/bin/arm-none-eabi-gcc --use-c++=/usr/bin/arm-none-eabi-g++ --analyzer-target=arm-none-eabi /usr/bin/arm-none-eabi-g++ -g -O0 -Wall -Wextra -mcpu=cortex-m4 -mfloat-abi=hard -mthumb -mabi=aapcs -mno-sched-prolog -mabort-on-noreturn -fdata-sections -ffunction-sections -fno-strict-aliasing -fno-builtin -specs=nosys.specs -specs=nano.specs -static -nodefaultlibs -Wdouble-promotion -ggdb -g3 -mfpu=fpv4-sp-d16 -pipe -frandom-seed=0x633bf14c -Wdate-time -fno-exceptions -fno-rtti -fvisibility=default -Wall -Wextra -Wpedantic -Wno-unused-function -DS1_USE_SEGGER_RTT -DEFM32WG940F256 -D__HEAP_SIZE=0 -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/common/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/config -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/dmadrv/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/dmadrv/config -I/home/Timur/Projects/MyProject/my-software/dependencies/hardware/kit/common/drivers -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/gpiointerrupt/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/nvm/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/nvm/config -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/rtcdrv/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/rtcdrv/config -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/sleep/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/spidrv/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/spidrv/config -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/uartdrv/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/uartdrv/config -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/ustimer/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emdrv/ustimer/config -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/emlib/inc -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/CMSIS/Include -I/home/Timur/Projects/MyProject/my-software/dependencies/platform/Device/SiliconLabs/EFM32WG/Include -I/home/Timur/Projects/MyProject/my-software/dependencies/RTT -std=c++0x -o /home/Timur/Projects/MyProject/build-myproject-my-software-arm_none_eabi-Debug/qtc_arm_none_a793425c-debug/myproject-my-software.qtc-arm-none-a793425c.7e216384/.obj/e6c416981c959a66/efm32-serial-port.cpp.o -c /home/Timur/Projects/MyProject/my-software/source/utilities/hal/efm32-serial-port.cpp
In file included from /home/Timur/Projects/MyProject/my-software/source/utilities/hal/efm32-serial-port.cpp:24:
In file included from /home/Timur/Projects/MyProject/my-software/source/utilities/hal/efm32-serial-port.h:27:
In file included from /home/Timur/Projects/MyProject/my-software/source/utilities/hal/abstract-serial-port.h:32:
/home/Timur/Projects/MyProject/my-software/source/utilities/hal/../core/callback.h:32:10: fatal error: 'cstddef' file not found
#include <cstddef>
^~~~~~~~~
1 error generated.
scan-build: Using '/usr/bin/clang-4.0' for static analysis
scan-build: 0 bugs found.
scan-build: The analyzer encountered problems on some source files.
scan-build: Preprocessed versions of these sources were deposited in '/tmp/scan-build-2017-07-27-194505-8969-1/failures'.
scan-build: Please consider submitting a bug report using these files:
scan-build: http://clang-analyzer.llvm.org/filing_bugs.html
答案 0 :(得分:1)
您似乎也需要指定use-cc=/usr/bin/arm-none-eabi-gcc
标记:http://blog.canyonbliss.net/static-code-analysis-with-scan-build-while-cross-compiling/
答案 1 :(得分:0)
缺少“cstring”是因为clang不包含STL标头。我遇到了同样的问题并添加-I<path_to_st_includes>
修复了它。
所以在我的QBS中我有类似的东西:
property string repoDir: "C:/Program Files (x86)/Atmel/Studio/7.0/packs"
cpp.includePaths: [
repoDir + "/arm/CMSIS/4.2.0/CMSIS/Include",
"C:/Program Files (x86)/Atmel/Studio/7.0/toolchain/arm/arm-gnu-toolchain/arm-none-eabi/include/c++/6.3.1",
"C:/Program Files (x86)/Atmel/Studio/7.0/toolchain/arm/arm-gnu-toolchain/arm-none-eabi/include"
]
对于vfpcc
来说,这似乎是clang的一个问题。 Chromium项目甚至已修复删除vfpcc
:https://codereview.chromium.org/411803002/
到目前为止,我发现的唯一解决方案是禁用静态分析的硬件FPU。
一种方法是在clang上使用-mfpu=none
。但是gcc会抱怨none
无效......而且由于Qt Creator在分析之前构建项目,构建将失败并且分析将无法启动。
另一种方法是定义__SOFTFP__
。这会强制__FPU_USED
为0
并禁用所有使用vfpcc
的函数。