2 ms·
No, I mean the behavior is undefined in that case when the function returns the indeterminate value, which was initialized anyway. Look, GCC (what I have here:
by kazinator 8y ago
No, I mean the behavior is undefined in that case when the function returns the indeterminate value, which was initialized anyway.
Look, GCC (what I have here: 7.3.0) is doing this even for the following trivial function:
int undef(void)
{
int ret;
return ret;
}
With -O2 this turns out:
xorl %eax, %eax
ret
do we still know until run-time that this has UB?
- tux3 8y ago>Look, GCC (what I have here: 7.3.0) is doing this even for the following trivial function: You're absolutely right that in this case, it's wasteful. In fact, if you try Clang you will see that it only emits a ret. Maybe GCC is doing you a courtesy (or maybe nobody taught it to completely omit an Undef return value, so it just picks zero!). Either way, it's unconditionally UB, GCC can do whatever it likes. >do we still know until run-time that this has UB? Well, there is no branch here, is there? I'm clearly not going to disagree with you on this one =] To be clear: UB is still a property of the execution of the program, but here it's not hard to statically determine that all executions of this program are Undefined Behavior.
- kazinator 8y agoMoreover, it still does it with "-m32 -mtune=i386". :)