Oh, I see.

But this is kind of like punting the problem to the user :(
The compiler should really generate code that raises an exception
(just like in the case of 1/0).


On Saturday, January 30, 2021 at 7:04:22 PM UTC-5 Elronnd _ wrote:

> On Sat, 30 Jan 2021, gmhwxi wrote:
>
> > Without -O2, the executable generated by gcc returns 32. With -O2, it is 
> > a non-terminating loop. Clearly, gcc assumes (with -O2) that the sum of 
> > two positive integers is also positive (but it is obviously false when 
> > modulo arithmetic is involved). BTW, clang does NOT have this issue.
>
> It's actually not a bug!
>
> In c, signed integer overflow is considered undefined behaviour, so the 
> compiler is free to treat is as nonterminating instead of wrapping. And 
> in fact, my version of clang (11.0.1) returns 33 for that function.
>
> If you want the compiler to treat integer overflow as wrapping, you have 
> to pass it -fwrapv.
>
> -E
>

-- 
You received this message because you are subscribed to the Google Groups 
"ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ats-lang-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/685bc21f-43b5-4915-b3c7-9b05deef910cn%40googlegroups.com.

Reply via email to