Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to turn on icc/icpc warnings?

Tags:

c++

c

intel

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) {

  }
}

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

like image 350
Conghui He Avatar asked Dec 07 '14 13:12

Conghui He


1 Answers

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 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

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.

Build Up

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

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

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

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: value copied to temporary, reference to temporary used
  • 869: parameter "*" was never referenced
  • 981: operands are evaluated in unspecified order
  • 1418: external function definition with no prior declaration
  • 1572: floating-point equality and inequality comparisons are unreliable
  • 2259: non-pointer conversion may loose significant bits
  • 11074: Inlining inhibited by limit max-size (or max-total-size)
  • 11076: To get full report use -qopt-report=4 -qopt-report-phase ipo
  • 161: disable warning for unrecognized pragmas

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

like image 151
pavon Avatar answered Sep 30 '22 17:09

pavon