Optimization levels for getting all warnings (was: [BUG] missing warning for pointer arithmetic out of bounds)

Alejandro Colomar alx.manpages@gmail.com
Sun Dec 18 12:48:16 GMT 2022

Hi Andrew

On 12/13/22 20:18, Andrew Pinski wrote:

> GCC only warns during VRP which is only enabled at -O2:
> <source>:8:12: warning: array subscript 6 is outside array bounds of
> 'char[5]' [-Warray-bounds=]
>      8 |          p = buf + 6;
>        |          ~~^~~~~~~~~
> <source>:6:19: note: at offset 6 into object 'buf' of size 5
>      6 |          char *p, buf[5];
>        |                   ^~~
> Thanks,
> Andrew

Makes sense.  I've seen some warnings that are disabled by optimization, and 
others that are enabled by it.

So, if I want to get all warnings that GCC can emit for any given software, is 
there a list of optimization levels on which I should compile?  Is -O0 and -O3 
enough for everything?  Or should I also build with all intermediate 
optimization levels?



-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20221218/aef93adc/attachment.sig>

More information about the Gcc mailing list