[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#96099: gcc bug(s)



package: gcc
version: 2.95.4-0.01042

running on intel based system (old pentium 133Mhz)


first
        dpkg --list | grep gcc
yeilds
        ii  gcc            2.95.3-7       The GNU C compiler.
        ii  gcc-2.95       2.95.4-0.01042 The GNU C compiler.

I'm not 100% sure why my system thinks both "gcc" and "gcc-2.95"
are installed.  Suggestions on how to fix this would be appreciated.
I upgraded from a "stable" debian release to "testing" a month or
so ago.

The command
        gcc --version
yields
        gcc version 2.95.4 20010319 (Debian prerelease)
so I really think "gcc-2.95" is installed but I'll do any other
verification needed.

>From a really bad piece of code I was looking at that had a bug
in the code, leads me to believe there is also a compiler bug.

        {
          int
              arr[10][10],
              x,
              y;

          for (x = 0; x < 10; x++) {
              for (y = 0; y < 10; y++) {
                  arr[x][y] = ((x = y) ? 1 : 0);
                  printf("%d\n", arr[x][y]);
              }
          }
        }

Don't ask where the code comes from, its not mine.  The bug in
the code is the "(x = y)" was susppose to be "(x == y)".  But
theoretically with the bug still in place I would expect arr[0][0],
arr[1][1], ..., arr[9][9] to be the only elements filled in and
arr[0][0] will contain 0 and the other arr[i][i] would contain 1.
I tossed in the printf() to show what is happenning.

compiled with "gcc T.c -o T" the output is

        0
        179931522
        -1073745196
        1073914572
        126767887
        1073833580
        0
        1073833240
        1074870958
        -1073744904

(the "funky numbers" are just values on the stack that are in the positions
for arr[i][i]) where I would have expected

        0
        1
        1
        1
        1
        1
        1
        1
        1
        1

Just for giggles, if one changes

              arr[10][10],
to
              arr[10][10] = { { 10 } },

the output is

        0
        0
        0
        0
        0
        0
        0
        0
        0
        0

which enforces my suspecition that for i > 0 arr[i][i] is _NOT_ being
written/stored to.  Its unclear whether arr[0][0] is being stored or
not from the above output.

I recompiled as "gcc -g3 T.c -o T" and the output remains consistent
but here's the assembly language statements if that helps.  I'm really
not up on my x86 assembly anymore so I won't make any comments on it.

        0x8048828 <t33>:        push   %ebp
        0x8048829 <t33+1>:      mov    %esp,%ebp
        0x804882b <t33+3>:      sub    $0x1a4,%esp
        0x8048831 <t33+9>:      push   %ebx
        0x8048832 <t33+10>:     nop
        0x8048833 <t33+11>:     movl   $0x0,0xfffffe6c(%ebp)
        0x804883d <t33+21>:     lea    0x0(%esi),%esi
        0x8048840 <t33+24>:     cmpl   $0x9,0xfffffe6c(%ebp)
        0x8048847 <t33+31>:     jle    0x8048850 <t33+40>
        0x8048849 <t33+33>:     jmp    0x8048910 <t33+232>
        0x804884e <t33+38>:     mov    %esi,%esi
        0x8048850 <t33+40>:     movl   $0x0,0xfffffe68(%ebp)
        0x804885a <t33+50>:     lea    0x0(%esi),%esi
        0x8048860 <t33+56>:     cmpl   $0x9,0xfffffe68(%ebp)
        0x8048867 <t33+63>:     jle    0x8048870 <t33+72>
        0x8048869 <t33+65>:     jmp    0x8048900 <t33+216>
        0x804886e <t33+70>:     mov    %esi,%esi
        0x8048870 <t33+72>:     mov    0xfffffe68(%ebp),%eax
        0x8048876 <t33+78>:     mov    %eax,%edx
        0x8048878 <t33+80>:     lea    0x0(,%edx,4),%eax
        0x804887f <t33+87>:     mov    0xfffffe6c(%ebp),%ecx
        0x8048885 <t33+93>:     mov    %ecx,%edx
        0x8048887 <t33+95>:     shl    $0x2,%edx
        0x804888a <t33+98>:     add    %ecx,%edx
        0x804888c <t33+100>:    lea    0x0(,%edx,8),%ecx
        0x8048893 <t33+107>:    add    %ecx,%eax
        0x8048895 <t33+109>:    lea    0xfffffe70(%ebp),%edx
        0x804889b <t33+115>:    mov    0xfffffe68(%ebp),%ecx
        0x80488a1 <t33+121>:    mov    %ecx,0xfffffe6c(%ebp)
        0x80488a7 <t33+127>:    test   %ecx,%ecx
        0x80488a9 <t33+129>:    setne  %cl
        0x80488ac <t33+132>:    movzbl %cl,%ebx
        0x80488af <t33+135>:    mov    %ebx,(%eax,%edx,1)
        0x80488b2 <t33+138>:    add    $0xfffffff8,%esp
        0x80488b5 <t33+141>:    mov    0xfffffe68(%ebp),%eax
        0x80488bb <t33+147>:    mov    %eax,%edx
        0x80488bd <t33+149>:    lea    0x0(,%edx,4),%eax
        0x80488c4 <t33+156>:    mov    0xfffffe6c(%ebp),%ecx
        0x80488ca <t33+162>:    mov    %ecx,%edx
        0x80488cc <t33+164>:    shl    $0x2,%edx
        0x80488cf <t33+167>:    add    %ecx,%edx
        0x80488d1 <t33+169>:    lea    0x0(,%edx,8),%ecx
        0x80488d8 <t33+176>:    add    %ecx,%eax
        0x80488da <t33+178>:    lea    0xfffffe70(%ebp),%edx
        0x80488e0 <t33+184>:    mov    (%eax,%edx,1),%eax
        0x80488e3 <t33+187>:    push   %eax
        0x80488e4 <t33+188>:    push   $0x80489d4
        0x80488e9 <t33+193>:    call   0x8048434 <printf>
        0x80488ee <t33+198>:    add    $0x10,%esp
        0x80488f1 <t33+201>:    incl   0xfffffe68(%ebp)
        0x80488f7 <t33+207>:    jmp    0x8048860 <t33+56>
        0x80488fc <t33+212>:    lea    0x0(%esi,1),%esi
        0x8048900 <t33+216>:    incl   0xfffffe6c(%ebp)
        0x8048906 <t33+222>:    jmp    0x8048840 <t33+24>
        0x804890b <t33+227>:    nop
        0x804890c <t33+228>:    lea    0x0(%esi,1),%esi
        0x8048910 <t33+232>:    add    $0xfffffff8,%esp
        0x8048913 <t33+235>:    mov    0xfffffe9c(%ebp),%eax
        0x8048919 <t33+241>:    push   %eax
        0x804891a <t33+242>:    push   $0x80489d4
        0x804891f <t33+247>:    call   0x8048434 <printf>
        0x8048924 <t33+252>:    add    $0x10,%esp
        0x8048927 <t33+255>:    mov    0xfffffe58(%ebp),%ebx
        0x804892d <t33+261>:    leave
        0x804892e <t33+262>:    ret
        0x804892f <t33+263>:    nop


Have fun.  If you need anymore information, please feel free to email.





Reply to: