On 2023-12-18 05:27, Bruno Haible wrote:
I would be willing to 1) open a bug report with the Clang ASAN people, asking them to move the (char *) NULL + 0 detection to a separate, "pedantic" category. ... We would thus also need to 2) ask the clang people whether they can promise that they will never make this optimization, 3) ask the GCC people the same thing.Do you think there's a chance they will say "yes, we promise"?
Yes, of course, that's the point. Lots of real code makes this assumption, and the clang folks need to know about that (if they don't know already) so that they don't put in optimizations that would break real code. This sort of tradeoff is routine for compiler-writers.
This is what makes it different from the example 2 in <https://mohitmv.github.io/blog/Shocking-Undefined-Behaviour-In-Action/>. That's a contrived example, where the application writer "wants" the program to dump core via dereferencing a null pointer, which is obviously bogus behavior.
In contrast, adding 0 to a null pointer is not obviously bogus behavior; it works on all non-pedantic platforms and it's realistic to expect it to work.
