https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87059

--- Comment #10 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #7)

> So the fix is presumably to change len3 to
> 
>     len3 = fold_convert_loc (loc, ssizetype, arg3);
> 
> Given the difference between sizetype and ssizetype is just one 's' it seems
> like an easy mistake to make.  If MIN_EXPR does, in fact, require arguments
> of the same type then adding an assertion to fold_binary_loc() to verify it
> would help expose these mistakes early.  I'm not sure what the right
> predicate is to use in the assertion.  Just compare TYPE_MAIN_VARIANT of the
> two argument types for equality?

Martin, sorry to drag you into this.  I didn't notice your change was just an
indentation change.

Also, thanks for the hint above.

I'm testing the following which seems to fix them problem:

gcc/

        PR 87059/tree-optimization
        * builtins.c (expand_builtin_strncmp): Pass signed sizetype to
        fold_convert_loc.

diff --git a/gcc/builtins.c b/gcc/builtins.c
index b1a79f3f33f..7113d19aadf 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -4727,7 +4727,7 @@ expand_builtin_strncmp (tree exp, ATTRIBUTE_UNUSED rtx
target,
   if (len2)
     len2 = size_binop_loc (loc, PLUS_EXPR, ssize_int (1), len2);

-  tree len3 = fold_convert_loc (loc, sizetype, arg3);
+  tree len3 = fold_convert_loc (loc, ssizetype, arg3);

   /* If we don't have a constant length for the first, use the length
      of the second, if we know it.  If neither string is constant length,

Reply via email to