Oh, sorry for the noise, there is an integer overflow that may cause
undefined behavior.

Haoxin Tu <haoxi...@gmail.com> 于2022年8月2日周二 11:23写道:

> Dear developers,
>
> May I seek your confirmation to check whether the following program
> triggers a true wrong-code issue in GCC? The following piece of code looks
> too simple and I am not quite sure whether it's a bug or not.
>
> Here is the test program (s.c):
> ```
> int a = 0, b = 0;
> int main() {
> for (; a <= 6; a++) {
> c:
> b++;
> if (b) {
> goto c;
> }
> }
> return 0;
> }
>
> ```
> $ gcc-trunk  -O1 s.c ; ./a.out
> (infinite loop)
> $ gcc-trunk -O2 s.c ;./a.out
>
> Godbolt: https://godbolt.org/z/dx6efvv7x
>
> I guess the behavior of -O2 is normal as the if statement inside the
> for-loop will be 0 after certain iterations. It's worth noting that almost
> all versions of GCC behave the same in this case. Also, note that LLVM
> behaves the same under the two optimization options; they all terminate the
> execution in seconds.
>
> So, before I make any noise in the GCC bug repo, may I quickly check with
> you and see whether the `s.c` is a potential wrong code bug in GCC, or
> did I miss any important information here? I will file a new bug report
> for this issue if it is a true bug.
>
> Thank you so much and looking forward to your reply!
>
>
> Best regards,
> Haoxin
>

Reply via email to