简体   繁体   English

如何运行GCC / Clang进行静态分析? (仅警告)

[英]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.

相关问题 如何在没有清晰警告的情况下使用工会? - How can I use unions without clang-tidy warnings? 使用MPI进行Clang静态分析 - Clang static analysis with MPI 如何在GCC中弃用已弃用的函数中删除已弃用的警告? - How can I get rid of deprecated warnings in deprecated functions in GCC? 我怎样才能打开(字面上)GCC的所有警告? - How can I turn on (literally) ALL of GCC's warnings? Qt 5.1 for OSX安装仅包含clang_64目录,如何使用macports gcc进行编译? - Qt 5.1 for OSX installation only includes clang_64 directory, how do I compile with macports gcc? 如何在gcc或clang中启用从int到int64_t转换的警告 - How to enable warnings on conversion from int to int64_t in gcc or clang 就嵌入式系统的大小而言,我能得到clang或gcc之类的成熟编译器有多小? - How small can I get full fledged compiler like clang or gcc in terms of size for an embedded system? 如何使GCC / Clang警告未初始化成员的使用? - How can I make GCC/Clang warn about the use of uninitialized members? 如何使用类似于gcc-xml的clang生成元数据输出? - How can I generate metadata output with clang similar to that of gcc-xml? 如何让 CMake 在 Mac OS X 上使用 GCC 而不是 Clang? - How can I make CMake use GCC instead of Clang on Mac OS X?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM