4 ms·
Actually, yes, I do want that code to crash if x is NULL.
by bewaretheirs 5y ago
Actually, yes, I do want that code to crash if x is NULL.
- pcwalton 5y agoThen you should logically be OK with deleting the null pointer check, as that check is unreachable.
- bewaretheirs 5y agoThe compiler can't know if page 0 is mapped.
- mpweiher 5y agoNope.
- nkurz 5y agoAre you familiar with this classic example? http://blog.llvm.org/2011/05/what-every-c-programmer-should-know_14.html http://blog.llvm.org/2011/05/what-every-c-programmer-should-... The problem (if I understand it right) is that "Redundant Null Check Elimination" might be run first, and will get rid of the safety return. But then the "Dead Code Elimination" can be run, which gets rid of the unused read, and thus removes the crash. Which means that rather than being logically equivalent, you can end up with a situation where /* do real stuff */ (aka /* launch missiles */) can be run despite the programmer's clear intentions.
- Dylan16807 5y agoRight, each optimization is fine on its own but the combination is dangerous.
- saagarjha 5y agoNot really. My understanding of the opinion (which I don't share, FWIW, and you probably know this) is that the null dereference should not be deleted, and it should be marked as an undeleteable trap similar to what an out-of-bounds access might be in Rust. That is, not unreachable in the sense of "code can never reach here", but unreachable in the sense that if it is hit then no other code executes.
- deleted 5y ago[deleted]