This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] convert MIN_EXPR operands to the same type (PR 87059)


PR 87059 points out an ICE in the recently enhanced VRP code
that was traced back to a MIN_EXPR built out of operands of
types with different sign by expand_builtin_strncmp().

The attached patch adjusts the function to make sure both
operands have the same type, and to make these mismatches
easier to detect, also adds an assertion to fold_binary_loc()
for these expressions.

Bootstrapped on x86_64-linux.

Martin

PS Aldy, I have not tested this on powerpc64le.
PR tree-optimization/87059 - internal compiler error: in set_value_range

gcc/ChangeLog:

	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.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index b1a79f3..6a992bd 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -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);
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index b318fc77..1e44a24 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -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);
     }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]