This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: invalid shifts in stor-layout.c (fixup_unsigned_type)
- To: Matt Thomas <matt at 3am-software dot com>
- Subject: Re: invalid shifts in stor-layout.c (fixup_unsigned_type)
- From: Jeffrey A Law <law at cygnus dot com>
- Date: Fri, 12 May 2000 15:52:43 -0600
- cc: gcc-patches at gcc dot gnu dot org
- Reply-To: law at cygnus dot com
In message <4.3.1.2.20000507102344.00bfc1d0@3am-software.com>you write:
> fix_unsigned_type in stor-layout.c will try to shift ~0 by
> an amount >= the word size of the machine. A shift of that
> amount is undefined behavior. In fact, it causes a reserved
> operand fault on VAX. On i386, the only low 5 bits are used
> for the shift. This happens when doing (in tree.c):
>
> unsigned_intTI_type_node = make_unsigned_type (GET_MODE_BITSIZE (TImode
> ));
>
> I'm not even sure that the original code generated the right
> value for TImode.
Actually, TImode is only supposed to be available when HOST_BITS_PER_WIDE_INT
is 64bits or larger.
I suspect the better fix is to put suitable ifdef around the call to
make_unsigned_type. Look at how other uses of unsigned_intTI_type_mode are
protected.
>
> Index: stor-layout.c
> ===================================================================
> RCS file: /cvs/gcc/egcs/gcc/stor-layout.c,v
> retrieving revision 1.69
> diff -u -r1.69 stor-layout.c
> --- stor-layout.c 2000/04/25 12:15:25 1.69
> +++ stor-layout.c 2000/05/03 23:15:40
> @@ -1680,9 +1680,11 @@
> = build_int_2 (precision - HOST_BITS_PER_WIDE_INT >= 0
> ? -1 : ((HOST_WIDE_INT) 1 << precision) - 1,
> precision - HOST_BITS_PER_WIDE_INT > 0
> - ? ((unsigned HOST_WIDE_INT) ~0
> - >> (HOST_BITS_PER_WIDE_INT
> - - (precision - HOST_BITS_PER_WIDE_INT)))
> + ? (precision - HOST_BITS_PER_WIDE_INT >= HOST_BITS_PER_
> WIDE_INT
> + ? (unsigned HOST_WIDE_INT) ~0
> + : ((unsigned HOST_WIDE_INT) ~0
> + >> (HOST_BITS_PER_WIDE_INT
> + - (precision - HOST_BITS_PER_WIDE_INT))))
> : 0);
> TREE_TYPE (TYPE_MIN_VALUE (type)) = type;
> TREE_TYPE (TYPE_MAX_VALUE (type)) = type;
> --
> Matt Thomas Internet: matt@3am-software.com
> 3am Software Foundry WWW URL: http://www.3am-software.com/bio/matt/
> Cupertino, CA Disclaimer: I avow all knowledge of this message
>
>