diff options
author | Jakub Jelinek <jakub@redhat.com> | 2019-04-09 12:26:13 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2019-04-09 12:26:13 +0200 |
commit | a73468e8c724fa76eccdf33835e9705a37e21381 (patch) | |
tree | c3c993e2eb3474b5c54bb81a3cc2a3e1f059865d /gcc/gimple-fold.c | |
parent | 1c67e69c0dea67fab1ef32e8b78bf24cc1b3f06a (diff) | |
download | gcc-a73468e8c724fa76eccdf33835e9705a37e21381.zip gcc-a73468e8c724fa76eccdf33835e9705a37e21381.tar.gz gcc-a73468e8c724fa76eccdf33835e9705a37e21381.tar.bz2 |
re PR middle-end/89998 (ICE: verify_gimple failed in printf-return-value)
PR tree-optimization/89998
* gimple-ssa-sprintf.c (try_substitute_return_value): Use lhs type
instead of integer_type_node if possible, don't add ranges if return
type is not compatible with int.
* gimple-fold.c (gimple_fold_builtin_sprintf,
gimple_fold_builtin_snprintf): Use lhs type instead of hardcoded
integer_type_node.
* gcc.c-torture/compile/pr89998-1.c: New test.
* gcc.c-torture/compile/pr89998-2.c: New test.
From-SVN: r270224
Diffstat (limited to 'gcc/gimple-fold.c')
-rw-r--r-- | gcc/gimple-fold.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 62d2e0a..a9afc4b 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -3231,11 +3231,10 @@ gimple_fold_builtin_sprintf (gimple_stmt_iterator *gsi) gimple_set_no_warning (repl, true); gimple_seq_add_stmt_without_update (&stmts, repl); - if (gimple_call_lhs (stmt)) + if (tree lhs = gimple_call_lhs (stmt)) { - repl = gimple_build_assign (gimple_call_lhs (stmt), - build_int_cst (integer_type_node, - strlen (fmt_str))); + repl = gimple_build_assign (lhs, build_int_cst (TREE_TYPE (lhs), + strlen (fmt_str))); gimple_seq_add_stmt_without_update (&stmts, repl); gsi_replace_with_seq_vops (gsi, stmts); /* gsi now points at the assignment to the lhs, get a @@ -3285,12 +3284,12 @@ gimple_fold_builtin_sprintf (gimple_stmt_iterator *gsi) gimple_set_no_warning (repl, true); gimple_seq_add_stmt_without_update (&stmts, repl); - if (gimple_call_lhs (stmt)) + if (tree lhs = gimple_call_lhs (stmt)) { - if (!useless_type_conversion_p (integer_type_node, + if (!useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (orig_len))) - orig_len = fold_convert (integer_type_node, orig_len); - repl = gimple_build_assign (gimple_call_lhs (stmt), orig_len); + orig_len = fold_convert (TREE_TYPE (lhs), orig_len); + repl = gimple_build_assign (lhs, orig_len); gimple_seq_add_stmt_without_update (&stmts, repl); gsi_replace_with_seq_vops (gsi, stmts); /* gsi now points at the assignment to the lhs, get a @@ -3370,10 +3369,10 @@ gimple_fold_builtin_snprintf (gimple_stmt_iterator *gsi) gimple_seq stmts = NULL; gimple *repl = gimple_build_call (fn, 2, dest, fmt); gimple_seq_add_stmt_without_update (&stmts, repl); - if (gimple_call_lhs (stmt)) + if (tree lhs = gimple_call_lhs (stmt)) { - repl = gimple_build_assign (gimple_call_lhs (stmt), - build_int_cst (integer_type_node, len)); + repl = gimple_build_assign (lhs, + build_int_cst (TREE_TYPE (lhs), len)); gimple_seq_add_stmt_without_update (&stmts, repl); gsi_replace_with_seq_vops (gsi, stmts); /* gsi now points at the assignment to the lhs, get a @@ -3422,12 +3421,12 @@ gimple_fold_builtin_snprintf (gimple_stmt_iterator *gsi) gimple_seq stmts = NULL; gimple *repl = gimple_build_call (fn, 2, dest, orig); gimple_seq_add_stmt_without_update (&stmts, repl); - if (gimple_call_lhs (stmt)) + if (tree lhs = gimple_call_lhs (stmt)) { - if (!useless_type_conversion_p (integer_type_node, + if (!useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (orig_len))) - orig_len = fold_convert (integer_type_node, orig_len); - repl = gimple_build_assign (gimple_call_lhs (stmt), orig_len); + orig_len = fold_convert (TREE_TYPE (lhs), orig_len); + repl = gimple_build_assign (lhs, orig_len); gimple_seq_add_stmt_without_update (&stmts, repl); gsi_replace_with_seq_vops (gsi, stmts); /* gsi now points at the assignment to the lhs, get a |