Bug 25418 - ftrapv sometimes does not emit checking for addition
Summary: ftrapv sometimes does not emit checking for addition
Status: RESOLVED DUPLICATE of bug 19020
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-14 18:20 UTC by Christopher Chua
Modified: 2023-10-27 17:53 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Christopher Chua 2005-12-14 18:20:05 UTC
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".
Comment 1 Andrew Pinski 2005-12-14 18:32:28 UTC

*** This bug has been marked as a duplicate of 19020 ***