How can I run GCC/Clang for static analysis? (warnings only)

别来无恙 提交于 2019-12-03 12:30:14

问题


Without compiling code, I would like GCC or Clang to report warnings.
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


回答1:


Both GCC and Clang have an option -fsyntax-only that makes the compiler only perform syntax checking without any actual compilation.




回答2:


In addition to the other replies, gcc is doing some analysis during compilation (and even during some optimization passes). So you could discard the generated code and still get all the warnings with e.g. 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, e.g. with MELT (a high level domain specific language to extend GCC).

If you want strong static analysis and are willing to give additional annotations for that purpose consider also Frama C.



来源:https://stackoverflow.com/questions/14072779/how-can-i-run-gcc-clang-for-static-analysis-warnings-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!