Compile the following C program for x86 (mingw, i686) using "gcc -ftrapv -S -O0
<filename>" (Note: Includes omitted for brevity; GCC will warn. Including
stdio.h or stdlib.h does not fix the bug):

int main(void)
{
        int a,b;
        printf("Enter two signed int values: ");
        scanf("%d %d",&a,&b);
        printf("\na + b = %d, a * b = %d, a - b = %d\n",a+b,a*b,a-b);
        exit(0);
}

The assembly listing produced does not include a call to __addvsi3. It does,
however, contain calls to __subvsi3 and __mulvsi3. This occurs at all
optimisation levels with GCC 4.0.2.

I also tested this with GCC 3.4.0 (RedHat Linux 9, i686). The call to __addvsi3
is correctly done at -O0 and -O1, but not at any higher optimisation levels,
where it is replaced by an explicit "addl".


-- 
           Summary: ftrapv sometimes does not emit checking for addition
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: someone42 at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25418

Reply via email to