简体   繁体   中英

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

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

GCC和Clang都具有-fsyntax-only选项,该选项使编译器仅执行语法检查,而没有任何实际的编译。

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 eg 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).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM