From d7b00a16de70d84dce94a1f760265497f3408a7b Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Mon, 21 Sep 2015 11:09:53 -0600 Subject: [PATCH] [PATCH] Fix undefined behavior in h8300 backend * config/h8300/h8300.md (andsi3_ashift_n_lower): Avoid undefined behavior. * gcc.target/h8300/andsi3_ashift_n_lower.c: New test. From-SVN: r227978 --- gcc/ChangeLog | 5 +++++ gcc/config/h8300/h8300.md | 3 ++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.target/h8300/andsi3_ashift_n_lower.c | 7 +++++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/h8300/andsi3_ashift_n_lower.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c25888aa09b..b6527de27b3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2015-09-21 Jeff Law + + * config/h8300/h8300.md (andsi3_ashift_n_lower): Avoid undefined + behavior. + 2015-09-21 Ulrich Weigand * config/spu/spu.c (spu_expand_insv): Avoid undefined behavior. diff --git a/gcc/config/h8300/h8300.md b/gcc/config/h8300/h8300.md index 4079b306d5c..52213ace20f 100644 --- a/gcc/config/h8300/h8300.md +++ b/gcc/config/h8300/h8300.md @@ -3914,7 +3914,8 @@ (clobber (match_scratch:QI 4 "=X,&r"))] "(TARGET_H8300H || TARGET_H8300S) && INTVAL (operands[2]) <= 15 - && INTVAL (operands[3]) == ((-1 << INTVAL (operands[2])) & 0xffff)" + && UINTVAL (operands[3]) == ((HOST_WIDE_INT_M1U << INTVAL (operands[2])) + & 0xffff)" "#" "&& reload_completed" [(parallel [(set (match_dup 5) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c65469fef03..7afd523d80a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-09-21 Jeff Law + + * gcc.target/h8300/andsi3_ashift_n_lower.c: New test. + 2015-09-21 Ville Voutilainen Complete the implementation of N4230, Nested namespace definition. diff --git a/gcc/testsuite/gcc.target/h8300/andsi3_ashift_n_lower.c b/gcc/testsuite/gcc.target/h8300/andsi3_ashift_n_lower.c new file mode 100644 index 00000000000..8cacc52a409 --- /dev/null +++ b/gcc/testsuite/gcc.target/h8300/andsi3_ashift_n_lower.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-mh -O2 -fomit-frame-pointer" } */ +/* { dg-final { scan-assembler-times "extu" 1 } } */ + +unsigned long foo(unsigned long a) + { return (a << 4) & 0xffff; } + -- 2.30.2