我想使用来分析并行代码,即需要MPI编译器包装器的代码。但是,在使用CMake进行配置时,我总是得到
$ scan-build cmake /path/to/source
-- Check for working CXX compiler: /usr/share/clang/scan-build/c++-analyzer
-- Check for working CXX compiler: /usr/share/clang/scan-build/c++-analyzer -- works
随后的编译(make)将失败,并显示
/usr/include/some/header.hpp:56:17
我从命令行使用scan-build (checker-258)对我的iOS项目进行静态分析,发现它比xcode发现的问题要少得多(大约少60% )。如果我将Xcode4.2设置为使用checker 258中的scan-build,它会找到所有问题(甚至更多)。这可能是因为命令行版本使用旧的(而不是现代的)运行时,因为它发现了如下问题:
error: synthesized property 'foo' must either be named the same as a compatible ivar or must explicitly name an ivar
@synth
我在C中有一个简单的brainfuck解释器,它在scan-build中生成以下警告
$ scan-build gcc -Wall -g -std=c99 main.c
scan-build: Using '/usr/bin/clang' for static analysis
main.c:14:11: warning: Assigned value is garbage or undefined
c = *(program + instruction_index);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1
我想试一试clang静态分析仪。我在Windows上,用Visual构建了clang。它似乎很有效,但同时它似乎是极其无用的。
我做了一个示例文件
example.c
int main(void)
{
int h = 0;
return 1/h;
}
调用scan-build gcc -c example.c没有发现错误。
example.c
int main(void)
{
int h;
return 1/h;
}
调用scan-build gcc -c example.c没有发现错误。
example.c
int main(void)
{
re
我想使用clang静态分析器命令行工具 在方便的情况下 ..。 最多 的 资源 我在网上发现,似乎你需要一个分两步走的过程: scan-build cmake .
scan-build make 例如,对于这个带有错误的小示例程序, 捕获: #include
int fun() {
int x;
return x; # main.cpp:5:5: warning: Undefined or garbage value returned to caller
}
int main() {
int a = fun();
std::cout <<
我想知道是否可以让clang分析器直接工作在bitcode (***.bc**)文件上?跟踪关于识别只能具有0或1值的整数变量,我已经开始探索clang分析器,它给了我很好的结果。例如,当我使用以下C代码时:
$ scan-build clang -O3 ./main.c
研究发现,除以零是不可行的。
int should_expand(char *s)
{
int tmp = 0;
int ret = 0;
char *p;
for (p = s; p && *p; p++)
{
if (*p == '\\
我无法让clang的c++-analyzer在玩具C++文件上工作。
#include <iostream>
using namespace std;
int main()
{
int t[4];
int x,y;
t[5]=1;
if(x)
y = 5;
x = t[y];
}
makefile只是
all: t.cpp
$(CXX) t.cpp
scan-build make输出:
scan-build: 'clang' executable not found in
我在应用程序中的多个地方使用了单例模式,并且在分析代码时从clang获得了内存泄漏错误。
static MyClass *_sharedMyClass;
+ (MyClass *)sharedMyClass {
@synchronized(self) {
if (_sharedMyClass == nil)
[[self alloc] init];
}
return _sharedMyClass;
}
// clang error: Object allocated on line 5 is no longer referenced after this po
有没有人在Windows上成功地运行clang静态分析器?
我已经成功地构建了llvm和clang (使用VS 2008)。运行扫描-生成将导致以下错误:
The getpwuid function is unimplemented at scan-build line 35.
一些研究表明,平台上不支持getpwuid。
遵循主clang静态分析器网页()的指示.
我有一个小的C文件,它充满了严重的bug (badcode.c):
int main(int argc, char ** argv)
{
int j;
int a[4];
puts(a[j]);
return 'a';
}
为了了解clang静态分析器(扫描构建)单词的基本原理,我运行:
scan-build -v clang badcode.c
它的产出如下:
scan-build: Emitting reports for this run to '/tmp/scan-build-2012-
我正在尝试在其文档()中显示的一些示例上执行clang静态分析器(版本3.8)。
我创建了一个小型C程序,如下所示:
// note: requires alpha.security.taint check turned on.
void test() {
char s[] = "abc";
int x = getchar();
char c = s[x]; // warn: index is tainted
}
我正在执行以下命令来分析上面的代码:
/usr/lib/llvm-3.8/bin/scan-build -enable-checker alp
简单的错误代码文件 $ python --version
Python 3.8.5
$ gcc --version
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
我已经在Ubuntu桌面上安装了扫描构建/clang版本2.9。我使用make构建了我的C++源代码。就像上面说的,扫描构建将分析一个使用make构建的项目,如果您给出
scan-build make
至
但做完这件事后我看到一条信息
scan-build: Removing '/tmp/scan-build-2013-10-16-1' because it contains no reports.
也试过
scan-build --use-c++=/use/bin/clang++ make
Q1 -我在这里做错了什么?如何使用扫描构建来分析所有源文件。
Q2 -是否有任何选
我使用的是XCode 4.4.1,我想通过CLang手动执行静态分析。
我下载了Clang checker build 267。
使用xcodebuild我可以构建我的项目,但是当使用scan-build xcodebuild时,我得到了错误。
Details: Unable to get message category info for tool '/Users/vinay/checker-267/libexec/ccc-analyzer'.
Reason: Can't execute "clang": No such file or directo
我已经在Windows上设置了Clang和CMake,当在OpenSceneGraph项目源代码上运行cmake-gui时(配置步骤),该过程失败并返回Check for working C compiler: C:/Program Files (x86)/LLVM/bin/clang.exe -- broken。
下面是整个输出:
The C compiler identification is unknown
The CXX compiler identification is unknown
Found Eclipse version 4.3 ()
Check for working C
首先输入命令:
clang -cc1 -analyzer-checker-help
列出所有可用的检查程序如下。
alpha.core.BoolAssignment Warn about assigning non-{0,1} values to Boolean variables
alpha.core.CastSize Check when casting a malloc'ed type T, whether the size is a multiple of the size of T
alpha.core.CastToStruct
我想运行一个简单的可执行文件,当我从亚行shell执行它时,应该打印"Hello“。为此,我使用c++文件创建了一个简单的CMakeLists.txt文件,如下所示:
hello.cpp
#include <iostream>
int main(int, char**) {
std::cout << "Hello, CMake!\n";
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.4.1)
add_library( # Sets the name of the library.
嗨,我发现非常有用的帖子,他描述了如何实现扫描-构建一个比xcode自带的更好的分析工具。
以下是入门说明:
1. Download scan-build
2. Just unpack it into any directory and add that directory to your PATH
3. Open a Terminal and cd to your project’s root directory
4. Run scan-build and view results
但是我不明白第二点,“把那个目录添加到你的路径”是什么意思,我该怎么做呢?
感谢您的帮助