Similar to the fixes from the weekend. Avoiding left shifts of negative signed values in the obvious way.

Tested by building msp430 targets from config-all.mk.

Installed on the trunk.

Jeff
commit 679cec5bd2f9ca9c6dabff89d0103790d560c0cb
Author: Jeff Law <l...@tor.usersys.redhat.com>
Date:   Mon Sep 28 19:24:56 2015 -0400

    [PATCH] Fix undefined behaviour in msp430 port
    
           * config/msp430/msp430.c (msp430_legitimate_constant): Fix undefined
            left shift behaviour.
            * config/msp430/constraints.md ('L' constraint): Similarly.
            ('Ys' constraint): Similarly.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 03f566c..1b9985a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2015-09-29  Jeff Law  <l...@redhat.com>
+
+       * config/msp430/msp430.c (msp430_legitimate_constant): Fix undefined
+       left shift behaviour.
+       * config/msp430/constraints.md ('L' constraint): Similarly.
+       ('Ys' constraint): Similarly.
+
 2015-09-29  Richard Biener  <rguent...@suse.de>
 
        PR tree-optimization/67170
diff --git a/gcc/config/msp430/constraints.md b/gcc/config/msp430/constraints.md
index 30f944c..dfda152 100644
--- a/gcc/config/msp430/constraints.md
+++ b/gcc/config/msp430/constraints.md
@@ -32,7 +32,7 @@
 (define_constraint "L"
   "Integer constant -1^20..1^19."
   (and (match_code "const_int")
-       (match_test "IN_RANGE (ival, -1 << 20, 1 << 19)")))
+       (match_test "IN_RANGE (ival, HOST_WIDE_INT_M1U << 20, 1 << 19)")))
 
 (define_constraint "M"
   "Integer constant 1-4."
@@ -77,7 +77,7 @@
        (and (match_code "plus" "0")
             (and (match_code "reg" "00")
                  (match_test ("CONST_INT_P (XEXP (XEXP (op, 0), 1))"))
-                 (match_test ("IN_RANGE (INTVAL (XEXP (XEXP (op, 0), 1)), -1 
<< 15, (1 << 15)-1)"))))
+                 (match_test ("IN_RANGE (INTVAL (XEXP (XEXP (op, 0), 1)), 
HOST_WIDE_INT_M1U << 15, (1 << 15)-1)"))))
        (match_code "reg" "0")
        )))
 
diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c
index d2308cb..ba8d862 100644
--- a/gcc/config/msp430/msp430.c
+++ b/gcc/config/msp430/msp430.c
@@ -998,7 +998,7 @@ msp430_legitimate_constant (machine_mode mode, rtx x)
     /* GCC does not know the width of the PSImode, so make
        sure that it does not try to use a constant value that
        is out of range.  */
-    || (INTVAL (x) < (1 << 20) && INTVAL (x) >= (-1 << 20));
+    || (INTVAL (x) < (1 << 20) && INTVAL (x) >= 
(HOST_WIDE_INT)(HOST_WIDE_INT_M1U << 20));
 }
 
 

Reply via email to