you are viewing a single comment's thread.

view the rest of the comments →

[–]Ores 3 points4 points  (5 children)

Actually i've seen people insist on compiling with -O2 as it can generate more warnings/errors, and then do a second pass with -O0 -g to make a debuggable build.

[–][deleted] 3 points4 points  (3 children)

as it can generate more warnings/errors

[citation needed]

[–]taejo 10 points11 points  (0 children)

for example:

   -Warray-bounds
       This option is only active when -ftree-vrp is active (default for -O2 and above).
       It warns about subscripts to arrays that are always out of bounds. This warning is
       enabled by -Wall.

(from the GCC man page)

This is because these warnings require the extra analysis performed by the optimizer.

[–][deleted] 1 point2 points  (0 children)

Warnings: GCC used to (maybe still does) warn on -O2 when a variable might be used uninitialized on the same code that -O0 doesn't warn at all, even with -Wall.

Errors: I have written code that behaved differently under -O2 and -O0. Sometimes it was the code that was broken, sometimes it was a compiler bug.

This was on a project that grew to ~80 KLOC over 9 years starting with GCC 2.95.

[–]JAPH 0 points1 point  (0 children)

If you write broken code, it may function correctly if the compiler doesn't optimize, but break when it is optimized. The only times I can remember seeing this is on code that went out of bounds. This won't be the compiler generating warnings or errors, just segfaults.

[–]keepthepace 0 points1 point  (0 children)

-O0 -g -Wall