Bug 28864 - Integer arithmetic error
Integer arithmetic error
Status: CLOSED RAWHIDE
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
7.0
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2001-02-22 10:03 EST by Bert Schellekens
Modified: 2007-04-18 12:31 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2001-02-23 07:30:22 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Bert Schellekens 2001-02-22 10:03:46 EST
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 13:18:08 EST
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 07:30:18 EST
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.