From a55f0871f40837404e4837bd75aa6d2dfc9a9ccf Mon Sep 17 00:00:00 2001 From: law Date: Sat, 25 Aug 2018 19:12:36 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@263855 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 7 +++++++ gcc/builtins.c | 5 ++++- gcc/fold-const.c | 8 ++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1816d48528c..b183818918e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2018-08-25 Martin Sebor + + 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 * config/darwin.c (machopic_legitimize_pic_address): Clean up diff --git a/gcc/builtins.c b/gcc/builtins.c index b1a79f3f33f..6a992bd939b 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 b318fc7705f..1e44a2454ad 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); } -- 2.11.4.GIT