[英]How can I run GCC/Clang for static analysis? (warnings only)
Without compiling code, I would like GCC or Clang to report warnings. 如果不编译代码,我希望GCC或Clang报告警告。
Is it possible to run the compiler for static analysis only? 是否可以仅运行编译器进行静态分析?
I can't find a way to pass the compiler warning flags and tell it not to compile. 我找不到通过编译器警告标志并告诉它不要编译的方法。
edit: just found that clang has a static analyser 编辑:刚发现c具有静态分析器
GCC和Clang都具有-fsyntax-only
选项,该选项使编译器仅执行语法检查,而没有任何实际的编译。
In addition to the other replies, gcc
is doing some analysis during compilation (and even during some optimization passes). 除了其他答复外,
gcc
还在编译过程中(甚至在一些优化过程中)进行了一些分析。 So you could discard the generated code and still get all the warnings with eg gcc -Wall -O -c code.c -o /dev/null
因此,您可以丢弃生成的代码,并仍然使用
gcc -Wall -O -c code.c -o /dev/null
获得所有警告。
Notice that you could extend GCC with your additional passes doing some additional, application specific, checks and warnings, eg with MELT (a high level domain specific language to extend GCC). 请注意,您可以使用其他通行证来扩展GCC,以执行一些特定于应用程序的附加检查和警告,例如,使用MELT (扩展GCC的高级领域特定语言)。
If you want strong static analysis and are willing to give additional annotations for that purpose consider also Frama C . 如果您需要强大的静态分析并愿意为此提供其他注释,请考虑Frama C。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.