如何打开icc/icpc警告? [英] how to turn on icc/icpc warnings?

查看:365
本文介绍了如何打开icc/icpc警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Linux上安装了Intel Compiler composer_xe_2013_sp1.3.174.我对icc警告感到困惑.用简单的main.c程序向icc馈入,如下所示:

I installed Intel Compiler composer_xe_2013_sp1.3.174 on Linux. I am confused about the icc warnings. Feed icc with a simple program main.c as below:

int main(int argc, char **argv) {
  int a = 1;
  unsigned int b = -22;
  if (b = a) {

  }
}

我用命令icc -Wall main.c编译了文件.令人惊讶的是,该命令在没有任何警告的情况下以静默方式工作.我是否必须打开icc上的警告开关?谢谢

I compiled the file with the command: icc -Wall main.c. Surprisingly, the command works silently without any warnings. Do I have to turn on the warnings switch on icc? Thanks

推荐答案

Intel编译器实际上并没有很好的预设来警告gcc的运行方式(至少在Linux上如此).主要警告选项是-wn,其中n可以是0到5.默认值是1,并且4& amp;可以设置为0. 5在Linux上没有意义.它还支持某些gcc选项,例如-Wall-Wextra.但是:

The Intel compiler doesn't really have good presets for warnings the way that gcc does (at least on Linux). The main warning option is -wn where n can be 0 to 5. The default is 1, and 4 & 5 have no meaning on Linux. It also supports some gcc options like -Wall and -Wextra. However:

    如您所见,
  • -Wall与gcc相比非常简约
  • -w2-w3启用了一些有用的诊断功能,但也提供了许多垃圾邮件注释
  • -diag-disable:remark删除了该垃圾邮件,但也删除了许多有用的诊断信息
  • -Wall is very minimalistic compared to gcc, as you found
  • -w2 and -w3 enable some useful diagnostics, but also a lot of spam remarks
  • -diag-disable:remark removes that spam but also a lot of useful diagnostics

最后,-w3 -diag-disable:remark是icc拥有的最佳预设,但比gcc -Wall更简约.相反,您需要从最少的警告集开始,然后建立自己的警告,或者从最大化的诊断信息开始,并禁用任何使用-wd烦人的警告.

In the end -w3 -diag-disable:remark is the best preset that icc has but it is still more minimalistic than gcc -Wall. Instead you need to either start with a minimal set of warnings and build up your own, or start with maximum diagnostics and disable any that get annoying using -wd.

第一种方法的主要缺点是英特尔并未真正记录其大部分警告,因此很难知道可以启用哪些功能.但是,它确实支持许多GCC命令行标志,因此GCC文档是一个不错的起点.例如,以下是相对接近g++ -Wall的设置,如果您要使用其中一个进行开发并且很可能与另一个进行干净的构建,这将很方便:

The main downside to the first approach is that Intel doesn't really document most of its warnings, so it is hard to know what is available to enable. However, it does support many of the GCC command line flags, so the GCC documentation is a good place to start. For example, here are settings that are relatively close to g++ -Wall, which is convenient if you want to develop with one and have a good chance of a clean build with the other:

icpc -Wall -Warray-bounds -Wchar-subscripts -Wcomment -Wenum-compare -Wformat -Wuninitialized -Wmaybe-uninitialized -Wmain -Wnarrowing -Wnonnull -Wparentheses -Wpointer-sign -Wreorder -Wreturn-type -Wsign-compare -Wsequence-point -Wtrigraphs -Wunused-function -Wunused-but-set-variable -Wunused-variable -Wwrite-strings

这不是gcc -Wall的完全匹配. GCC和ICC对以上警告的实施方式有所不同.我也找不到与这些GCC警告相匹配的ICC选项:

This isn't an exact match for gcc -Wall. There are differences between GCC's and ICC's implementation of the above warnings. I was also unable to find ICC options to match these GCC warnings:

-Wformat-contains-nul
-Wunused-label
-Wstrict-overflow
-Wvolatile-register-var

我故意将其排除在外,因为ICC版本比GCC更加垃圾:

And I intentionally left these out, because the ICC version was much more spammy than GCC:

-Wstrict-aliasing   So broad that any use of polymophism will cause this warning
-Wswitch            Requires a default even if you have cases for all enumeration values

修整

如果不关心GCC奇偶校验,那么了解ICC所具有的警告的最简单方法是启用所有警告,然后决定是否喜欢它们.如果您不喜欢警告,则可以使用其诊断号将其禁用,该诊断号通常比GCC的选项具有更高的粒度.

Trim Down

If GCC parity isn't a concern then the easiest way to learn what warnings ICC has is to enable them all, and then decide whether you like them or not. If you don't like a warning, you can disable it using it's diagnostics number, which often has more granularity that GCC's options do.

icpc -w3 -wd1418,2259

以下是一些我过去禁用过的诊断程序:

Here are some diagnostics that I have seen disabled in the past:

  • 383:将值复制到临时文件,引用临时文件
  • 869:参数"*"从未被引用
  • 981:以未指定的顺序评估操作数
  • 1418:没有事先声明的外部函数定义
  • 1572:浮点相等和不相等比较不可靠
  • 2259:非指针转换可能会丢失重要的位
  • 11074:内联受到限制的最大尺寸(或最大总尺寸)的抑制
  • 11076:要获取完整的报告,请使用-qopt-report = 4 -qopt-report-phase ipo
  • 161:对无法识别的编译指示禁用警告

但是我鼓励您从所有内容入手,并减少那些对您的代码库有问题的内容.

But I encourage you to start with them all on and pare down just the ones that are problematic for your code base.

这篇关于如何打开icc/icpc警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆