GCC 12.1 Released
GCC 12.1 Released
Posted May 9, 2022 10:44 UTC (Mon) by atnot (subscriber, #124910)In reply to: GCC 12.1 Released by excors
Parent article: GCC 12.1 Released
Wait wait what, the warnings change depending on optimization level? Am I the only one for whom this is surprising news?
Posted May 9, 2022 11:40 UTC (Mon)
by anselm (subscriber, #2796)
[Link]
That's not new. I seem to remember from back when I was programming in C more that some GCC warnings about unreachable code or uninitialised variables were only output under optimisation, because otherwise the analysis on which these warnings were based would not have been performed.
Posted May 9, 2022 11:43 UTC (Mon)
by pizza (subscriber, #46)
[Link]
This would appear to be an obvious conclusion from different optimization levels producing different sets of warnings.
I don't know when I first became aware of this, but it's been at least a decade.
Posted May 9, 2022 11:49 UTC (Mon)
by excors (subscriber, #95769)
[Link]
In this case, if the variables are declared as char* then the compiler has no idea of their probable length and doesn't warn. It's only because they're declared as char[MAXPATHLEN] that it becomes reasonably confident in its guess that the string might actually be MAXPATHLEN-1 in length, which is enough confidence to emit the (incorrect) warning. More sophisticated optimisation passes let it make a better guess of the string's length, reducing the false positives.
Posted May 9, 2022 12:22 UTC (Mon)
by tzafrir (subscriber, #11501)
[Link] (1 responses)
Posted May 9, 2022 19:25 UTC (Mon)
by wtarreau (subscriber, #51152)
[Link]
In a sense, that's a way to see it... But 4.7 never got it wrong at all and used to provide meaningful warnings if you go in that direction :-) Plus it was 3 times faster.
GCC 12.1 Released
Wait wait what, the warnings change depending on optimization level?
GCC 12.1 Released
GCC 12.1 Released
GCC 12.1 Released
GCC 12.1 Released
