This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[commit, spu] Re: [BUILDROBOT] spu: left shift of negative value
- From: "Ulrich Weigand" <uweigand at de dot ibm dot com>
- To: jbglaw at lug-owl dot de (Jan-Benedict Glaw)
- Cc: trevor_smigiel at playstation dot sony dot com (Trevor Smigiel), dje dot gcc at gmail dot com (David Edelsohn), gcc at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Mon, 21 Sep 2015 16:43:00 +0200 (CEST)
- Subject: [commit, spu] Re: [BUILDROBOT] spu: left shift of negative value
- Authentication-results: sourceware.org; auth=none
Jan-Benedict Glaw wrote:
> I just noticed that (for config_list.mk builds), current GCC errors
> out at spu.c, see eg. build
> http://toolchain.lug-owl.de/buildbot/show_build_details.php?id=3D469639 :
>
> g++ -fno-PIE -c -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -fno-excep=
> tions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrit=
> e-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -peda=
> ntic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -Werror -f=
> no-common -DHAVE_CONFIG_H -I. -I. -I../../../gcc/gcc -I../../../gcc/gcc/. =
> -I../../../gcc/gcc/../include -I../../../gcc/gcc/../libcpp/include -I/opt/c=
> farm/mpc/include -I../../../gcc/gcc/../libdecnumber -I../../../gcc/gcc/../=
> libdecnumber/dpd -I../libdecnumber -I../../../gcc/gcc/../libbacktrace -o =
> spu.o -MT spu.o -MMD -MP -MF ./.deps/spu.TPo ../../../gcc/gcc/config/spu/sp=
> u.c
> ../../../gcc/gcc/config/spu/spu.c: In function =E2=80=98void spu_expand_ins=
> v(rtx_def**)=E2=80=99:
> ../../../gcc/gcc/config/spu/spu.c:530:46: error: left shift of negative val=
> ue [-Werror=3Dshift-negative-value]
> maskbits =3D (-1ll << (32 - width - start));
> ^
> ../../../gcc/gcc/config/spu/spu.c:536:46: error: left shift of negative val=
> ue [-Werror=3Dshift-negative-value]
> maskbits =3D (-1ll << (64 - width - start));
> ^
> cc1plus: all warnings being treated as errors
> Makefile:2092: recipe for target 'spu.o' failed
> make[2]: *** [spu.o] Error 1
> make[2]: Leaving directory '/home/jbglaw/build-configlist_mk/spu-elf/build-=
> gcc/mk/spu-elf/gcc'
I've now checked in the following fix.
Thanks,
Ulrich
ChangeLog:
* config/spu/spu.c (spu_expand_insv): Avoid undefined behavior.
Index: gcc/config/spu/spu.c
===================================================================
*** gcc/config/spu/spu.c (revision 227968)
--- gcc/config/spu/spu.c (working copy)
*************** spu_expand_insv (rtx ops[])
*** 472,478 ****
{
HOST_WIDE_INT width = INTVAL (ops[1]);
HOST_WIDE_INT start = INTVAL (ops[2]);
! HOST_WIDE_INT maskbits;
machine_mode dst_mode;
rtx dst = ops[0], src = ops[3];
int dst_size;
--- 472,478 ----
{
HOST_WIDE_INT width = INTVAL (ops[1]);
HOST_WIDE_INT start = INTVAL (ops[2]);
! unsigned HOST_WIDE_INT maskbits;
machine_mode dst_mode;
rtx dst = ops[0], src = ops[3];
int dst_size;
*************** spu_expand_insv (rtx ops[])
*** 527,541 ****
switch (dst_size)
{
case 32:
! maskbits = (-1ll << (32 - width - start));
if (start)
! maskbits += (1ll << (32 - start));
emit_move_insn (mask, GEN_INT (maskbits));
break;
case 64:
! maskbits = (-1ll << (64 - width - start));
if (start)
! maskbits += (1ll << (64 - start));
emit_move_insn (mask, GEN_INT (maskbits));
break;
case 128:
--- 527,541 ----
switch (dst_size)
{
case 32:
! maskbits = (~(unsigned HOST_WIDE_INT)0 << (32 - width - start));
if (start)
! maskbits += ((unsigned HOST_WIDE_INT)1 << (32 - start));
emit_move_insn (mask, GEN_INT (maskbits));
break;
case 64:
! maskbits = (~(unsigned HOST_WIDE_INT)0 << (64 - width - start));
if (start)
! maskbits += ((unsigned HOST_WIDE_INT)1 << (64 - start));
emit_move_insn (mask, GEN_INT (maskbits));
break;
case 128:
--
Dr. Ulrich Weigand
GNU/Linux compilers and toolchain
Ulrich.Weigand@de.ibm.com