Bug 140890 - unaccountable output from abs() function
unaccountable output from abs() function
Status: CLOSED RAWHIDE
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: gcc (Show other bugs)
4.0
ia64 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2004-11-26 00:40 EST by L3support
Modified: 2007-11-30 17:07 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2005-01-14 06:13:17 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 L3support 2004-11-26 00:40:31 EST
Description of problem:
The result of the test program(see below) is abnormal.
It seems that the output from abs() function is abnormal.
The program can correctly works on 32bit architecture.

Version-Release number of selected component (if applicable):
glibc-2.3.3-73.ia64.rpm

How reproducible:
always

Steps to Reproduce:
1. execute following program.

#include       <stdio.h>
#include       <stdlib.h>

main() {
    int    ia[10] = {1,2,3,4,5,6,7,8,9,10},
           ib[16] ,
           ic[10] = {1,2,3,4,5,6,7,8,9,10};
    int    i,j,k;

    for (i= -5; i<0; i++) {
        ic[ abs(i-10)-11 ]  = 0;
        for (j=0; j<6; j++) { printf("ia[%d]=%d ",j,ia[j]); }
        printf(":");
        for (j=4; j>=0; j--) { printf(" ic[%d]=%d",j,ic[j]); }
        printf("\n");
    }
}

  
Actual results:
ia[0]=1 ia[1]=2 ia[2]=0 ia[3]=4 ia[4]=5 ia[5]=6 : ic[4]=5 ic[3]=4
ic[2]=3 ic[1]=2 ic[0]=1
ia[0]=1 ia[1]=2 ia[2]=0 ia[3]=0 ia[4]=5 ia[5]=6 : ic[4]=5 ic[3]=4
ic[2]=3 ic[1]=2 ic[0]=1
ia[0]=1 ia[1]=2 ia[2]=0 ia[3]=0 ia[4]=0 ia[5]=6 : ic[4]=5 ic[3]=4
ic[2]=3 ic[1]=2 ic[0]=1
ia[0]=1 ia[1]=2 ia[2]=0 ia[3]=0 ia[4]=0 ia[5]=0 : ic[4]=5 ic[3]=4
ic[2]=3 ic[1]=2 ic[0]=1
ia[0]=1 ia[1]=2 ia[2]=0 ia[3]=0 ia[4]=0 ia[5]=0 : ic[4]=5 ic[3]=4
ic[2]=3 ic[1]=2 ic[0]=1

note: The value of ia[n] is corrupted.

Expected results:
ia[0]=1 ia[1]=2 ia[2]=3 ia[3]=4 ia[4]=5 ia[5]=6 : ic[4]=0 ic[3]=4
ic[2]=3 ic[1]=2 ic[0]=1
ia[0]=1 ia[1]=2 ia[2]=3 ia[3]=4 ia[4]=5 ia[5]=6 : ic[4]=0 ic[3]=0
ic[2]=3 ic[1]=2 ic[0]=1
ia[0]=1 ia[1]=2 ia[2]=3 ia[3]=4 ia[4]=5 ia[5]=6 : ic[4]=0 ic[3]=0
ic[2]=0 ic[1]=2 ic[0]=1
ia[0]=1 ia[1]=2 ia[2]=3 ia[3]=4 ia[4]=5 ia[5]=6 : ic[4]=0 ic[3]=0
ic[2]=0 ic[1]=0 ic[0]=1
ia[0]=1 ia[1]=2 ia[2]=3 ia[3]=4 ia[4]=5 ia[5]=6 : ic[4]=0 ic[3]=0
ic[2]=0 ic[1]=0 ic[0]=0

note: This is a result on 32bit architecture.


Additional info:
When I change the program below, it can works normally.

#include       <stdio.h>
#include       <stdlib.h>

main() {
    int    ia[10] = {1,2,3,4,5,6,7,8,9,10},
           ib[16] ,
           ic[10] = {1,2,3,4,5,6,7,8,9,10};
    int    i,j,k;

    for (i= -5; i<0; i++) {
        k = i-10;                        // <<-- changed
        ic[ abs(k)-11 ]  = 0;            // <<-- changed
        for (j=0; j<6; j++) { printf("ia[%d]=%d ",j,ia[j]); }
        printf(":");
        for (j=4; j>=0; j--) { printf(" ic[%d]=%d",j,ic[j]); }
        printf("\n");
    }
}

When I confirmed output value of abs() function below, it seems to
correct.

#include       <stdio.h>
#include       <stdlib.h>

main() {
    int    ia[10] = {1,2,3,4,5,6,7,8,9,10},
           ib[16] ,
           ic[10] = {1,2,3,4,5,6,7,8,9,10};
    int    i,j,k;

    for (i= -5; i<0; i++) {
        printf("x=%d\n",abs(i-10)-11);
    }
}

$ ./a.out
x=4
x=3
x=2
x=1
x=0
Comment 1 Jakub Jelinek 2004-11-26 01:22:44 EST
This is a GCC bug.  Try to rebuild the failing program with -fno-builtin-abs
and it will work just fine.
Comment 3 Jakub Jelinek 2004-11-30 05:38:04 EST
Fixed in gcc-3.4.3-6.EL4 (as well as 3.4.3-7 in rawhide).
Comment 4 L3support 2004-12-02 23:26:58 EST
Which release do you implement the fixed gcc?
Is it implemented in RHEL4 RC?
Comment 5 Jakub Jelinek 2004-12-03 01:50:21 EST
3.4.3-6.EL4 is to be included in RHEL4 RC (or some later version if other bugs
show up).
Comment 6 Jay Turner 2005-01-14 06:13:17 EST
gcc-3.4.3-9.EL4 included in latest builds.  Closing out.  Please reopen if
problems occurs with the latest code.

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