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

前端 未结 2 531
遇见更好的自我
遇见更好的自我 2021-02-05 11:26

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 compi

2条回答
  •  南方客
    南方客 (楼主)
    2021-02-05 12:21

    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.

提交回复
热议问题