|
|
|
|
|
by vintermann
1306 days ago
|
|
The compiler made a dangerous assumption that the standard permits ("the author surely has guaranteed, through means I can't analyze, that this pointer will never be null"). Then it encountered evidence explicitly contradicting that assumption (a meaningless null check), and it handled it not by changing its assumption, but by quietly removing the evidence. > For example you would you not expect a compiler to remove a redundant bound check if it can infer that an index can't be out of range? If it can infer it from actually good evidence, sure. But using "a pointer was dereferenced" as evidence "this pointer is safe to dereference" is comically bad evidence that only the C standard could come up with. |
|
Do you think the compiler would be right to remove the second check here?
What about changing std::abort with the following? How's that different form a check after dereferencing a pointer? In both cases the check can be removed because dataflow or control flow analysis.What if my_abort returns instead? Or another thread changes x after the fact?