re PR tree-optimization/87059 (internal compiler error: in set_value_range, at tree...
authorMartin Sebor <msebor@redhat.com>
Sat, 25 Aug 2018 19:12:36 +0000 (19:12 +0000)
committerJeff Law <law@gcc.gnu.org>
Sat, 25 Aug 2018 19:12:36 +0000 (13:12 -0600)
PR tree-optimization/87059
* builtins.c (expand_builtin_strncmp): Convert MIN_EXPR operand
to the same type as the other.
* fold-const.c (fold_binary_loc): Assert expectation.

From-SVN: r263855

gcc/ChangeLog
gcc/builtins.c
gcc/fold-const.c

index 1816d48..b183818 100644 (file)
@@ -1,3 +1,10 @@
+2018-08-25  Martin Sebor  <msebor@redhat.com>
+
+       PR tree-optimization/87059
+       * builtins.c (expand_builtin_strncmp): Convert MIN_EXPR operand
+       to the same type as the other.
+       * fold-const.c (fold_binary_loc): Assert expectation.
+
 2018-08-25  Iain Sandoe  <iain@sandoe.co.uk>
 
        * config/darwin.c (machopic_legitimize_pic_address): Clean up
index b1a79f3..6a992bd 100644 (file)
@@ -4759,7 +4759,10 @@ expand_builtin_strncmp (tree exp, ATTRIBUTE_UNUSED rtx target,
   /* If we are not using the given length, we must incorporate it here.
      The actual new length parameter will be MIN(len,arg3) in this case.  */
   if (len != len3)
-    len = fold_build2_loc (loc, MIN_EXPR, TREE_TYPE (len), len, len3);
+    {
+      len = fold_convert_loc (loc, sizetype, len);
+      len = fold_build2_loc (loc, MIN_EXPR, TREE_TYPE (len), len, len3);
+    }
   rtx arg1_rtx = get_memory_rtx (arg1, len);
   rtx arg2_rtx = get_memory_rtx (arg2, len);
   rtx arg3_rtx = expand_normal (len);
index b318fc7..1e44a24 100644 (file)
@@ -9326,6 +9326,14 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
 
   if (kind == tcc_comparison || code == MIN_EXPR || code == MAX_EXPR)
     {
+      if (code == MIN_EXPR || code == MAX_EXPR)
+       {
+         tree typ0 = TREE_TYPE (arg0);
+         tree typ1 = TREE_TYPE (arg1);
+         gcc_assert (TYPE_SIGN (typ0) == TYPE_SIGN (typ1)
+                     && TYPE_MODE (typ0) == TYPE_MODE (typ1));
+       }
+
       STRIP_SIGN_NOPS (arg0);
       STRIP_SIGN_NOPS (arg1);
     }