> I don't get what you or the comment you're responding to are wishing for.
Quoting from another of my comments:
> > [What are you objecting to?]
> Inferring any propositional statement about the program (eg "this pointer is not null") from the fact that its negation would imply undefined behaviour.
That is what the problem is. Undefined behaviour is a licence to implement operations without regard for unusual corner cases, not to infer the absence of said corner cases from those operations and then apply that 'knowledge' elsewhere.
> I fail to see why one would consider a compiler evolving while conforming to language specification defective or malicious
> Inferring any propositional statement about the program (eg "this pointer is not null") from the fact that its negation would imply undefined behaviour.
I'm not completely sure I understand that correctly, but do you mean that statements that are constant unless considering a possible (and "credible"?) implementation of UB shouldn't be fair-game for the compiler to optimize out?
EDIT: I think I see a more tricky case that may be one of those you're referring to. Dereferencing a pointer further in the code shouldn't be a valid justification for optimizing out previous tests of it being null. I can relate with that but I suspect that it would prevent many classes of branch pruning.
I get what you suggest while describing malicious compliance but I can imagine that it could be a false impression resulting from trade-offs that favor optimization opportunities to "out-of-spec but canonical/natural" implementations.
> Dereferencing a pointer further in the code shouldn't be a valid justification for optimizing out previous tests of it being null.
Not further. Anywhere. If the implementation wishes to rewrite pointer dereferences from `use(*p)` to:
if(!p) abort();
use(*p);
it may do so (undefined behaviour!), but if it chooses not to do so, it may not later pretend that it did, and remove a explict `if(!p)` that the programmer wrote. Given:
use(*p);
if(!p) return NOPE;
this is fine:
if(!p) abort();
use(*p);
//if(!p) return NOPE; // unreachable because of if, not because of use
but not:
use(*p);
//if(!p) return NOPE; // CVE-20XX-XXXXX
The implementation can optimize based on information (like "p is not null") that is actually true (even if that's because it made it true), but not based on information it assumed was true on the basis that it counterfactually could have made it true (but didn't).
> it would prevent many classes of branch pruning.
In all of the examples above it will emit a machine instruction to dereference p. What your grandparent is complaining about is that it will later remove an "if (!p)" test.
Quoting from another of my comments:
> > [What are you objecting to?]
> Inferring any propositional statement about the program (eg "this pointer is not null") from the fact that its negation would imply undefined behaviour.
That is what the problem is. Undefined behaviour is a licence to implement operations without regard for unusual corner cases, not to infer the absence of said corner cases from those operations and then apply that 'knowledge' elsewhere.
> I fail to see why one would consider a compiler evolving while conforming to language specification defective or malicious
It's https://en.wikipedia.org/wiki/Malicious_compliance in near-textbook form.