4 ms·
I've been playing around with Clang and I can't find any flags that avoid this problem, other than -O0. Oh, but if you add a second "NeverCalled" function that
by iainmerrick 9y ago
I've been playing around with Clang and I can't find any flags that avoid this problem, other than -O0.
Oh, but if you add a second "NeverCalled" function that sets the pointer to something else, the optimization is skipped and you get a bus error at runtime.
No flags I can find, not -Wall -Wextra -Werror, warn me at compile time that anything unusual might be going on.
This is weird. I understand the explanation of the optimization, but a) isn't this rather unreasonable behavior? and b) couldn't there at least be a flag that skips this optimization, without having to disable all optimizations?
Maybe this UB propagation / dead code elimination idea is so deeply ingrained in Clang's design that it would simply be impossible to selectively remove it. If so, that seems very unfortunate.