How to enable icc / icpc warnings?

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

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

I compiled the file using the command: icc -Wall main.c Surprisingly, the team works without warning. Should I enable the alert switch on icc? Thanks

+5
source share
2 answers

The Intel compiler really does not have good warning presets like gcc does (at least on Linux). The main warning option is -wn where n can be from 0 to 5. By default, 1, and 4 and 5 do not matter for Linux. It also supports some gcc options, such as -Wall and -Wextra . However:

  • -Wall very minimal compared to gcc, as you found
  • -w2 and -w3 allow you to use some useful diagnostic tools, as well as a lot of spam notes
  • -diag-disable:remark removes this spam, but also a lot of useful diagnostics

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

Create

The main drawback of the first approach is that Intel does not document most of its warnings, so it’s hard to understand what is available for inclusion. However, it supports many 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 good chances 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 is not an exact match for gcc -Wall . There are differences between the GCC and the ICC regarding the above warnings. I also could not find ICC options to match these GCC warnings:

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

And I deliberately left them because the ICC version was much more spam 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 the parity of GCC is not a concern, then the easiest way to find out which warnings are ICCs is to turn them all on and then decide whether you like it or not. If you don't like the warning, you can turn it off using its diagnostic number, which often has a great deal of granularity that the GCC settings do.

 icpc -w3 -wd1418,2259 

Here are some diagnostic data I've seen in the past:

  • 383: value copied to temporary, reference to temporary use
  • 869: parameter "*" was never mentioned
  • 981: operands evaluated in unspecified order
  • 1418: definition of an external function without prior declaration
  • 1572: Floating-point equality and comparison of inequalities are unreliable.
  • 2259: conversion without a pointer may lose significant bits
  • 11074: Invalidation is prohibited by the maximum size limit (or maximum total size)
  • 11076: to get full use of the report -qopt-report = 4 -qopt-report-phase ipo

But I recommend that you start with them all and drop only those that are problematic for your code base.

+7
source

Generally speaking, the best compilation options for the small program you are developing are -Wall -Wextra -std = c11 -pedantic

Unlike the alert switch name, Wall does not actually activate all alerts; you use both Wall and Wextra to get most of the important warnings.

-std sets the standard used by the code; the most recent is C11, so std = c11. Pedantic is a way to tell the compiler that you want to write a program that does not use extensions for the compiler. Pedantic requires a std switch and will issue warnings for any syntax, ect. which does not comply with the standard specified by std. Finally, if you need errors instead of warnings to use the compiler extension, use -patent errors instead. *

(* - pedantic does not warn about the use of non-standard libraries such as conio.h)

Now, if you compile the program using Wall Wextra std = c11 pedantic, you should get 1 warning:

Warning: line 4 - Suggest Parenthesis around the true value (9 out of 10, that means you used = instead of == in the context of the comparison).

If you correct this warning, you will receive another warning: Warning: Line 4 - Comparison between signed and unsigned integer without translation.

Adding explicit actuation or changing b to the normal int will solve this warning.

0
source

Source: https://habr.com/ru/post/1208527/


All Articles