Hacker News new | ask | show | jobs
by afdbcreid 54 days ago
Indeed. No UB is something no mainstream C/C++ compiler does (and maybe ever did). Benchmarking the performance impact will require basically rewriting GCC or LLVM, an insurmountable task, because the assumptions are so ingrained.

Though it might be possible to have more "sensible" UB. For example, assuming daemonic non-determinism for allocation address it is possible to turn stack storage into registers, without the need for an aliasing model. Benchmarking it has the same difficulty.

1 comments

The problem is really surprising UB. I don't think that an experienced C programmer blames the compiler if some pointer offset trick to manipulate variables on the stack stops working. Compilers used to be "less smart", so they didn't get too clever about UB neither. Now they do and it surprises developers. That is a real problem.
A challenge is that it doesn't seem like people agree on what "surprising" UB is. I don't think it would be totally unreasonable to have a compiler mode that specifically assumes that all arithmetic operations are total functions, which covers many of the scenarios that show up in blog posts. But there is somebody in this comment thread who is upset that you can't read from an uninitialized heap address to obtain unpredictable data.

My personal observation is also that it only surprises developers when they read blog posts about it and that this actually comes up quite rarely in practice.