home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / gnu / gcc / bug / 2018 < prev    next >
Encoding:
Text File  |  1992-07-29  |  2.0 KB  |  99 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!sics.se!psm
  3. From: psm@sics.se (Peter Magnusson)
  4. Subject: gcc 2.2.2: "unsigned preserving" rule of "-traditional" causes problem
  5. Message-ID: <9207291910.AA16575@nut.sics.se>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Wed, 29 Jul 1992 23:10:25 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 86
  12.  
  13. Comparing an "int" with a 32-bit constant generates strange code when the
  14. "traditional" flag is selected.
  15.  
  16. Gcc version 2.2.2 (running on SPARCstation ELC 4/25 SunOS 4.1.2).
  17.  
  18. The following bit of code:
  19.  
  20.    int
  21.      main()
  22.    {
  23.      int a,b;
  24.      b = 0x80000000;
  25.      if (b >= 0x80000000)
  26.        a = 0;
  27.      else
  28.        a = 1;
  29.    }
  30.  
  31. Generates the following code with "gcc -S":
  32.  
  33. .text
  34.         .align 4
  35.         .global _main
  36.         .proc   04
  37. _main:
  38.         !#PROLOGUE# 0
  39.         save %sp,-144,%sp
  40.         !#PROLOGUE# 1
  41.         call ___main,0
  42.         nop
  43.         sethi %hi(-2147483648),%o0
  44.         st %o0,[%fp-24]
  45.         ld [%fp-24],%o0
  46.         sethi %hi(2147483647),%o2
  47.         or %o2,%lo(2147483647),%o1
  48.         cmp %o0,%o1
  49.         bleu L2                      <========
  50.         nop
  51.         st %g0,[%fp-20]
  52.         b,a L3
  53. L2:
  54.         mov 1,%o0
  55.         st %o0,[%fp-20]
  56. L3:
  57. L1:
  58.         ret
  59.         restore
  60.  
  61. When compiled with "gcc -S -traditional", the code is:
  62.  
  63. .text
  64.         .align 4
  65.         .global _main
  66.         .proc   04
  67. _main:
  68.         !#PROLOGUE# 0
  69.         save %sp,-144,%sp
  70.         !#PROLOGUE# 1
  71.         call ___main,0
  72.         nop
  73.         sethi %hi(-2147483648),%o0
  74.         st %o0,[%fp-24]
  75.         ld [%fp-24],%o0
  76.         sethi %hi(2147483647),%o2
  77.         or %o2,%lo(2147483647),%o1
  78.         cmp %o0,%o1
  79.         ble L2                         <======= !!!!
  80.         nop
  81.         st %g0,[%fp-20]
  82.         b,a L3
  83. L2:
  84.         mov 1,%o0
  85.         st %o0,[%fp-20]
  86. L3:
  87. L1:
  88.         ret
  89.    
  90.  
  91. Notice the change. The constant is decremented but the comparison is such that
  92. the expression evaluates to false!
  93.  
  94.  
  95. Peter Magnusson
  96. Swedish Institute of Computer Science
  97. psm@sics.se
  98.  
  99.