c/780: bad code generation on i386

lucier@math.purdue.edu lucier@math.purdue.edu
Sun Nov 12 10:56:00 GMT 2000


>Number:         780
>Category:       c
>Synopsis:       bad code generation on i386
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Sun Nov 12 10:56:00 PST 2000
>Closed-Date:
>Last-Modified:
>Originator:     Bradley Lucier
>Release:        gcc version 2.97 20001111 (experimental)
>Organization:
>Environment:
GNU ld 2.10.1
GNU assembler 2.10.1
>Description:
It seems to be just bad code generation; I'm not a
i386 assembley guru.
>How-To-Repeat:
[lucier@curie ~]$ cat bug.c
#include <stdio.h>

#define N -0x80000000L

int main ()
{
  int x, y, z;
  x = N;
  y = (N < 0) ? -1 : 0;
  z = (x < 0) ? -1 : 0;
  printf ("%d %d\n", y, z);
  return 0;
}
[lucier@curie ~]$ gcc bug.c
[lucier@curie ~]$ ./a.out
0 -1
[lucier@curie ~]$ gcc -save-temps bug.c
[lucier@curie ~]$ cat bug.s
        .file   "bug.i"
        .version        "01.01"
gcc2_compiled.:
        .section        .rodata
.LC0:
        .string "%d %d\n"
        .text
        .align 16
.globl main
        .type   main,@function
main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $24, %esp
        movl    $-2147483648, -4(%ebp)
        movl    $0, -8(%ebp)
        cmpl    $0, -4(%ebp)
        jns     .L3
        movl    $-1, -16(%ebp)
        jmp     .L4
        .p2align 4,,7
.L3:
        movl    $0, -16(%ebp)
.L4:
        movl    -16(%ebp), %eax
        movl    %eax, -12(%ebp)
        subl    $4, %esp
        pushl   -12(%ebp)
        pushl   -8(%ebp)
        pushl   $.LC0
        call    printf
        addl    $16, %esp
        movl    $0, %eax
        movl    %ebp, %esp
        popl    %ebp
        ret
.Lfe1:
        .size   main,.Lfe1-main
        .ident  "GCC: (GNU) 2.97 20001111 (experimental)"
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the Gcc-bugs mailing list