https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96317

            Bug ID: 96317
           Summary: [8/9/10/11] Int compare optimizations make some errors
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 570070308 at qq dot com
  Target Milestone: ---

for the code:

    signed int a=2147483647;
    if( (signed int)( (signed int)a + (signed int)1 ) < (signed int)2147483647
)
    {
        printf("111\n");
    }
    if( (signed int)( (signed int)a + (signed int)1 ) < (signed int)2147483646
)
    {
        printf("222\n");
    }
    signed int b=2147483646;
    if( (signed int)( (signed int)a + (signed int)1 ) < (signed int)b )
    {
        printf("333\n");
    }

The result is:
111
333

I have checked the assembly files. It seems that the compiler optimize the
a+1<2147483646 to a<=2147483644. There are some other similar situations in
compartion of <=,>,>=. I think it is better to change the ways or give out a
warning.

Reply via email to