Bug 28864 - Integer arithmetic error
Summary: Integer arithmetic error
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 7.0
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-02-22 15:03 UTC by Bert Schellekens
Modified: 2007-04-18 16:31 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2001-02-23 12:30:22 UTC
Embargoed:


Attachments (Terms of Use)

Description Bert Schellekens 2001-02-22 15:03:46 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.75 [en] (X11; U; Linux 2.2.16-22 i686)


A simple purely integer computation yields
the wrong answer.

Reproducible: Always
Steps to Reproduce:
1. Compile the following sample program (no special options,
   no optimization, just gcc program.c)
 
main()
{
int vec[6],sum;
vec[0]=24;
vec[1]=18;
vec[2]=12;
vec[3]=6;
vec[4]=0;
vec[5]=-24;
printf("%d %d %d %d %d %d\n",vec[0],vec[1],vec[2],vec[3],vec[4],vec[5]);
sum=( -3 * vec[0] -3 * vec[1] -3 * vec[2] -3 * vec[3] -3 * vec[4]+ 3 *
vec[5])/12;
  printf("%d\n",sum);
}

2. run it


	

Actual Results:  The result of the computation, printed on the last line,
is -20

Expected Results:  The correct answer is -21. 

This is the output I obtained
[t58@lion t58]$ gcc CBUG2.c
[t58@lion t58]$ a.out
24 18 12 6 0 -24
-20                                                                             

Using kgcc yields this correct result
[t58@lion t58]$ kgcc CBUG2.c
[t58@lion t58]$ a.out
24 18 12 6 0 -24
-21

Comment 1 Jakub Jelinek 2001-02-22 18:18:08 UTC
Oops, looks like a bug in extract_muldiv (present on gcc-3.0-branch as well).
Looking into...

Comment 2 Jakub Jelinek 2001-02-23 12:30:18 UTC
I've fixed this in http://gcc.gnu.org/ml/gcc-patches/2001-02/msg01419.html,
the patch will appear in gcc-2.96-77.


Note You need to log in before you can comment on or make changes to this bug.