🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Peter Magnusson Wed, 29 Jul 1992 23:10
gcc 2.2.2: "unsigned preserving" rule of "-traditional" causes problem
#328
Author: Peter Magnusson
Date: Wed, 29 Jul 1992 23:10
85 lines
2155 bytes
Comparing an "int" with a 32-bit constant generates strange code when the
"traditional" flag is selected.

Gcc version 2.2.2 (running on SPARCstation ELC 4/25 SunOS 4.1.2).

The following bit of code:

   int
     main()
   {
     int a,b;
     b = 0x80000000;
     if (b >= 0x80000000)
       a = 0;
     else
       a = 1;
   }

Generates the following code with "gcc -S":

.text
        .align 4
        .global _main
        .proc   04
_main:
        !#PROLOGUE# 0
        save %sp,-144,%sp
        !#PROLOGUE# 1
        call ___main,0
        nop
        sethi %hi(-2147483648),%o0
        st %o0,[%fp-24]
        ld [%fp-24],%o0
        sethi %hi(2147483647),%o2
        or %o2,%lo(2147483647),%o1
        cmp %o0,%o1
        bleu L2                      <========
        nop
        st %g0,[%fp-20]
        b,a L3
L2:
        mov 1,%o0
        st %o0,[%fp-20]
L3:
L1:
        ret
        restore

When compiled with "gcc -S -traditional", the code is:

.text
        .align 4
        .global _main
        .proc   04
_main:
        !#PROLOGUE# 0
        save %sp,-144,%sp
        !#PROLOGUE# 1
        call ___main,0
        nop
        sethi %hi(-2147483648),%o0
        st %o0,[%fp-24]
        ld [%fp-24],%o0
        sethi %hi(2147483647),%o2
        or %o2,%lo(2147483647),%o1
        cmp %o0,%o1
        ble L2                         <======= !!!!
        nop
        st %g0,[%fp-20]
        b,a L3
L2:
        mov 1,%o0
        st %o0,[%fp-20]
L3:
L1:
        ret
   

Notice the change. The constant is decremented but the comparison is such that
the expression evaluates to false!


Peter Magnusson
Swedish Institute of Computer Science
psm@sics.se
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads