Open Quuxplusone opened 5 years ago
Attached small.bc
(3200 bytes, application/octet-stream): .bc file of the source code
Attached small-opt1.bc
(3872 bytes, application/octet-stream): small-opt1.bc
int d;
if (d)
goto c;
Isn't this UB due to reading uninitialized local variable? I.e., the testcase
is bad?
(In reply to Mikael Holmén from comment #2)
> int d;
> if (d)
> goto c;
>
> Isn't this UB due to reading uninitialized local variable? I.e., the
> testcase is bad?
Thank you for pointing out this problem! I test it again with "int d=0", this
bug has gone. I do not realize this undefined behavior of c program. Thank you!
(In reply to Mikael Holmén from comment #2)
> int d;
> if (d)
> goto c;
>
> Isn't this UB due to reading uninitialized local variable? I.e., the
> testcase is bad?
It's strange that this bug is reproduced with "int d=1".
In addition, for "clang -O3", this program also can output the right result.
So, if this bug is introduced by UB, for "int d=0" or "int d=1", it should be
fixed.
In case d=0
, a
will be incremented until a<=1
is false, which means that a=2
is sufficient.
In case d=1
, the for
loop will never reach the evaluation of a++
which comes right after the the goto
. This means we will have an infinite loop.
In case d
is not initialized, it may be treated as zero, for which we will get the first case, and 2 will be printed. And it may also have a value other than zero, for which we will get the second case - an infinite loop.
This test-case seems to work correctly according to spec.
I think this bug may be closed, as non-issue.
small.bc
(3200 bytes, application/octet-stream)small-opt1.bc
(3872 bytes, application/octet-stream)