https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108770
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Last reconfirmed|2023-02-13 00:00:00 |2025-08-21 Status|UNCONFIRMED |WAITING --- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Andrew Teylu from comment #11) > (In reply to Andrew Pinski from comment #10) > > Ok, with const maybe the compiler could see that but then it needs to record > > that somehow but there is no way currently. > > > > Sure, and, to me, it isn't a problem that it isn't currently > fixable/resolvable, I just didn't think it was correct to close this case as > "FIXED" when actually it isn't. > > In fact, you could argue that, when you turn on `diagnostics-show-context`, > gcc is a "worse" because it "doubling down" on a false positive ... But it is only a false positive because you the programmer has knowledge of arr. > > Is it obvious to anyone what changed between 11.x and 12.1 to make this > appear? Just better optimization and jump threading. If you had: ``` extern void put(int i); int check_idx(int i) { if (i > 1) put(i); return i; } extern const char *arr[2]; void init() { int i = 0; while (arr[check_idx(i)] != 0) { if (arr[check_idx(i)]) {} i++; } } ``` There would be no way for GCC to know that arr has a nullptr. Do you have the original source where this is extracted from instead of a simpler example? Because I suspect this simplified example might be reduced way too much in the first place.