https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83133
--- Comment #3 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Maxim Egorushkin from comment #2)
> Could you provide an example where that "dangerous optimization" would break
> well-formed code please?
--cut here--
#include <stdio.h>
void positive (int a) { printf ("positive: %i\n", a); }
void nonpositive (int a) { printf ("nonpositive: %i\n", a); }
void
__attribute__((noinline))
g (int a, int b)
{
int diff = a - b;
if (diff > 0)
return positive (diff);
else
return nonpositive (diff);
}
int
main ()
{
int a = -0x80000000;
int b = 0x01;
g (a, b);
return 0;
}
--cut here--
$ gcc -O2 ttt.c
$ ./a.out
positive: 2147483647
$ gcc -O0 ttt.c
$ ./a.out
positive: 2147483647
$ clang -O2 ttt.c
$ ./a.out
nonpositive: 2147483647 <--------- HERE!
$ clang -O0 ttt.c
$ ./a.out
positive: 2147483647