如何使Clang Static Analyzer从命令行输出其工作? [英] How to make the Clang Static Analyzer output its working from command line?

查看:220
本文介绍了如何使Clang Static Analyzer从命令行输出其工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Ubuntu 12.10上运行Clang 3.4(来自 http://llvm.org/apt/ ).我对某些代码运行了分析器(clang --analyze),发现了两个问题:

I'm running Clang 3.4 on Ubuntu 12.10 (from http://llvm.org/apt/). I ran the analyzer (clang --analyze) over some code, and it found a couple of issues:

Blah.C:429:9: warning: Declared variable-length array (VLA) has zero size
        unsigned char separatedData[groupDataLength];
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~

但是具体问题并不重要.我想知道得出该结论的步骤(代码很复杂,我无法在15分钟内看到它.)

But the specific issue isn't important. I want to know the steps of how it came to that conclusion (the code is complex enough for me not to see it within 15 mins).

我看到了Clang网站的屏幕截图,其中显示了在网络浏览器中查看的工作步骤:

I see a screenshot from the Clang site that shows steps of working viewed in a web browser:

这可能是从Xcode获得的.

That's probably obtained from Xcode.

问题是:如何让Clang从命令行输出这样的工作步骤?甚至可以将结果输出到浏览器?这将使分析仪更加有用,并且可以更快地修复问题.

The question is: how do I get Clang to output such steps of working from the command line? Or even output results to a browser if it so wishes? This would make the analyzer significantly more useful, and make fixing things much quicker.

((我注意到GCC的文档非常出色,但是Clang/LLVM的文档却很差.我曾尝试过使用"clang --analyze -Xanalyzer'-v'"作为暗中的刺探告诉分析仪更详细些--Xanalyzer开关来自手册页.)

(I have noticed that GCC's documentation is very excellent, but Clang/LLVM's documentation is very poor. I've tried "clang --analyze -Xanalyzer '-v'" as a stab in the dark to tell the analyzer to be more verbose -- the -Xanalyzer switch was from the man pages.)

推荐答案

除了控制台上的文本输出:

In addition to text output on the console:

clang++ --analyze -Xanalyzer -analyzer-output=text main.cpp

您可以获得完整的html输出:

You can get the full html output:

clang++ --analyze -Xanalyzer -analyzer-output=html -o html-dir main.cpp

此外,您可以选择要启用的特定检查器. 此页面列出了可用的支票.例如,您可以使用以下标志启用alpha组中的所有C ++检查:

Additionally, you can select specific checkers to enable. This page lists available checks. For example, you can enable all of the C++ checks in the alpha group using the flags:

-Xanalyzer -analyzer-checker=alpha.cplusplus

http://coliru.stacked-crooked.com/a/7746c4004704d4a7

main.cpp:5:1: warning: Potential leak of memory pointed to by 'x'
}
^
main.cpp:4:12: note: Memory is allocated
  int *x = new int;
           ^~~~~~~
main.cpp:5:1: note: Potential leak of memory pointed to by 'x'
}
^


显然前端暴露了


Apparently the front end exposes

-analyzer-config<选项名称> =<值>

-analyzer-config <Option Name>=<Value>

例如

-analyzer-config -analyzer-checker=alpha.cplusplus

可能比-Xanalyzer更受支持,并且可能会扩展为支持单个检查器的选项:http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-October/039552.html

which might be better supported than -Xanalyzer and may be getting extended to support options to individual checkers: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2014-October/039552.html

这篇关于如何使Clang Static Analyzer从命令行输出其工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆