[PATCH] Fix undefined behavior in h8300 backend
authorJeff Law <law@redhat.com>
Mon, 21 Sep 2015 17:09:53 +0000 (11:09 -0600)
committerJeff Law <law@gcc.gnu.org>
Mon, 21 Sep 2015 17:09:53 +0000 (11:09 -0600)
* 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
gcc/config/h8300/h8300.md
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/h8300/andsi3_ashift_n_lower.c [new file with mode: 0644]

index c25888aa09bb2c0e834c1da1f1ab9db141d41855..b6527de27b3a4eb5f69a3614330d7d5ac4facc32 100644 (file)
@@ -1,3 +1,8 @@
+2015-09-21  Jeff Law  <law@redhat.com>
+
+       * config/h8300/h8300.md (andsi3_ashift_n_lower): Avoid undefined
+       behavior. 
+
 2015-09-21  Ulrich Weigand  <Ulrich.Weigand@de.ibm.com>
 
        * config/spu/spu.c (spu_expand_insv): Avoid undefined behavior.
index 4079b306d5cbdfe0a206d1be99a8c20cd4b9ec67..52213ace20f3309f59383822b4f4e9efba5c63db 100644 (file)
    (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)
index c65469fef03b257a4977852662717418757993ef..7afd523d80af75323949889993f88d1dce3797bd 100644 (file)
@@ -1,3 +1,7 @@
+2015-09-21  Jeff Law  <law@redhat.com>
+
+       * gcc.target/h8300/andsi3_ashift_n_lower.c: New test.
+
 2015-09-21  Ville Voutilainen  <ville.voutilainen@gmail.com>
 
        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 (file)
index 0000000..8cacc52
--- /dev/null
@@ -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; }
+