[gnu.gcc.bug] GCC bitfield optimization bug

mike@APOLLO.COM (01/13/90)

The following routine will cause GCC(1.36) to seg fault
when compiled with '-O'.

                struct csr {
                                char  x;
                                unsigned int   y : 1;
                } *csr;
                
                tst()
                {
                        do {
                                if (csr->x & 1)
                                        foo();
                        } while (csr->y);
                }
                
on another note, here is a suggested bug fix for another problem :

        volatile struct  x { int y : 24; } *z;
        
        main()
        {
                tst(z->y);
        }

This causes the compiler to abort() ???


*** expmed.c.ORIG	Tue Sep 12 15:46:21 1989
--- expmed.c	Thu Nov  2 16:25:38 1989
***************
*** 708,714 ****
  	  /* If op0 is a register, we need it in SImode
  	     to make it acceptable to the format of extzv.  */
  	  if (GET_CODE (xop0) == SUBREG && GET_MODE (xop0) != SImode)
! 	    abort ();
  	  if (GET_CODE (xop0) == REG && GET_MODE (xop0) != SImode)
  	    xop0 = gen_rtx (SUBREG, SImode, xop0, 0);
  
--- 708,714 ----
  	  /* If op0 is a register, we need it in SImode
  	     to make it acceptable to the format of extzv.  */
  	  if (GET_CODE (xop0) == SUBREG && GET_MODE (xop0) != SImode)
! 	    xop0 = convert_to_mode (SImode, xop0, 1);
  	  if (GET_CODE (xop0) == REG && GET_MODE (xop0) != SImode)
  	    xop0 = gen_rtx (SUBREG, SImode, xop0, 0);
  
***************
*** 818,824 ****
  	  /* If op0 is a register, we need it in SImode
  	     to make it acceptable to the format of extv.  */
  	  if (GET_CODE (xop0) == SUBREG && GET_MODE (xop0) != SImode)
! 	    abort ();
  	  if (GET_CODE (xop0) == REG && GET_MODE (xop0) != SImode)
  	    xop0 = gen_rtx (SUBREG, SImode, xop0, 0);
  
--- 818,824 ----
  	  /* If op0 is a register, we need it in SImode
  	     to make it acceptable to the format of extv.  */
  	  if (GET_CODE (xop0) == SUBREG && GET_MODE (xop0) != SImode)
! 	    xop0 = convert_to_mode (SImode, xop0, 0);
  	  if (GET_CODE (xop0) == REG && GET_MODE (xop0) != SImode)
  	    xop0 = gen_rtx (SUBREG, SImode, xop0, 0);

-------

Kudos to Rob Stanzel (rps@apollo.hp.com) for this one.

Mike Schloss
mike@apollo.hp.com
508-256-6600 x-6751