News for hackers. Stuff that matters.
Re:GCC undefined behaviors are getting wild by sokoloff on Monday November 28, 2022 @07:12AM (#33772634)
It is probably more precise to say “if the pointer is null, then it doesn’t matter what I do here, so I am permitted to eliminate this” than to say that it can’t be null here. (It can’t be both null and defined behavior.)
Re:GCC undefined behaviors are getting wild by joosters on Monday November 28, 2022 @08:02AM (#33773083)
I'm not sure that's right. The compiler isn't tracking undefined behaviour, it is tracking possible values. It just happens that one specific input into determining these values is the fact "a valid program can't dereference a null pointer", so if the source code ever dereferences a pointer, the compiler is free to reason that the pointer cannot therefore be null.

In essence, the compiler is allowed to assume that your code is valid and will only do valid things.