🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Andreas Schwab Tue, 08 Sep 1992 13:24
Bug in bitfield operations
#1085
Author: Andreas Schwab
Date: Tue, 08 Sep 1992 13:24
87 lines
2378 bytes
Version: GCC 2.2.2 (m68k, sun3)

There is a bug in the optimizer for bitfield operations.


bug.c:
--------------------
struct term
{
  unsigned state: 1;
  unsigned info: 7;
  unsigned content: 24;
};

f (struct term t)
{
  struct term t1[1], t2[1]; /* force into memory */
  t1[0] = t;
  g ((char) t1->content);
  t2[0] = t;
  g ((short) t2->content);
}
--------------------

Compile with: gcc -O -S bug.c

bug.s:
--------------------
#NO_APP
gcc2_compiled.:
.text
	.even
.globl _f
_f:
	link a6,#-8
	movel a2,sp@-
	movel d2,sp@-
	movel a6@(8),d2
	movel d2,a6@(-4)
	moveb a6@(-2),d1	| <--- wrong
	extbl d1
	movel d1,sp@-
	lea _g,a2
	jbsr a2@
	addqw #4,sp
	movel d2,a6@(-8)
	bfexts a6@(-6){#0:#16},d1
	movel d1,sp@-
	jbsr a2@
	movel a6@(-16),d2
	movel a6@(-12),a2
	unlk a6
	rts
--------------------

The bug occurs in the combine pass, where these insns

-------------------- (bug.c.flow)
(insn 13 11 14 (set (reg:SI 31)
       (zero_extract:SI (mem/s:QI (plus:SI (reg:SI 14)
                   (const_int -3)))
           (const_int 24)
           (const_int 0))) 233 {extzv} (nil)
   (nil))

(insn 14 13 16 (set (reg:SI 32)
       (sign_extend:SI (subreg:QI (reg:SI 31) 0))) 49 {extendqisi2} (insn_list 13 (nil))
   (expr_list:REG_DEAD (reg:SI 31)
       (nil)))

(insn 16 14 18 (set (mem:SI (pre_dec:SI (reg:SI 15)))
       (reg:SI 32)) 29 {movsi+1} (insn_list 14 (nil))
   (expr_list:REG_DEAD (reg:SI 32)
       (nil)))
--------------------

are combined into ((const_int -2) is wrong)

-------------------- (bug.c.combine)
(insn 16 14 18 (set (mem:SI (pre_dec:SI (reg:SI 15)))
       (sign_extend:SI (mem/s:QI (plus:SI (reg:SI 14)
                   (const_int -2))))) 49 {extendqisi2} (nil)
   (nil))
--------------------
--
Andreas Schwab
schwab@ls5.informatik.uni-dortmund.de
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