aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2019-04-09 12:26:13 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2019-04-09 12:26:13 +0200
commita73468e8c724fa76eccdf33835e9705a37e21381 (patch)
treec3c993e2eb3474b5c54bb81a3cc2a3e1f059865d
parent1c67e69c0dea67fab1ef32e8b78bf24cc1b3f06a (diff)
downloadgcc-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
-rw-r--r--gcc/ChangeLog10
-rw-r--r--gcc/gimple-fold.c29
-rw-r--r--gcc/gimple-ssa-sprintf.c8
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.c-torture/compile/pr89998-1.c42
-rw-r--r--gcc/testsuite/gcc.c-torture/compile/pr89998-2.c4
6 files changed, 78 insertions, 19 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index fc013a6..d0d6abc7 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,13 @@
+2019-04-09 Jakub Jelinek <jakub@redhat.com>
+
+ 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.
+
2019-04-09 Martin Liska <mliska@suse.cz>
* Makefile.in: Use GENERATOR_CFLAGS for all generators.
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
diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c
index ced1c4c..de60241 100644
--- a/gcc/gimple-ssa-sprintf.c
+++ b/gcc/gimple-ssa-sprintf.c
@@ -3692,10 +3692,10 @@ try_substitute_return_value (gimple_stmt_iterator *gsi,
are badly declared. */
&& !stmt_ends_bb_p (info.callstmt))
{
- tree cst = build_int_cst (integer_type_node, retval[0]);
+ tree cst = build_int_cst (lhs ? TREE_TYPE (lhs) : integer_type_node,
+ retval[0]);
- if (lhs == NULL_TREE
- && info.nowrite)
+ if (lhs == NULL_TREE && info.nowrite)
{
/* Remove the call to the bounded function with a zero size
(e.g., snprintf(0, 0, "%i", 123)) if there is no lhs. */
@@ -3736,7 +3736,7 @@ try_substitute_return_value (gimple_stmt_iterator *gsi,
}
}
}
- else if (lhs)
+ else if (lhs && types_compatible_p (TREE_TYPE (lhs), integer_type_node))
{
bool setrange = false;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a91b447..29d1a81 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2019-04-09 Jakub Jelinek <jakub@redhat.com>
+ PR tree-optimization/89998
+ * gcc.c-torture/compile/pr89998-1.c: New test.
+ * gcc.c-torture/compile/pr89998-2.c: New test.
+
PR target/90015
* gcc.target/riscv/interrupt-conflict-mode.c (foo): Adjust expected
diagnostics.
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr89998-1.c b/gcc/testsuite/gcc.c-torture/compile/pr89998-1.c
new file mode 100644
index 0000000..87be00c
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr89998-1.c
@@ -0,0 +1,42 @@
+/* PR tree-optimization/89998 */
+
+unsigned int sprintf (char *str, const char *fmt, ...);
+unsigned int snprintf (char *str, __SIZE_TYPE__ len, const char *fmt, ...);
+
+int
+f1 (char *s)
+{
+ return sprintf (s, "foo");
+}
+
+int
+f2 (char *s)
+{
+ return sprintf (s, "%d", 123);
+}
+
+int
+f3 (int *p, char *s)
+{
+ const char *t = "bar";
+ return sprintf (s, "%s", t);
+}
+
+int
+f4 (char *s)
+{
+ return snprintf (s, 8, "foo");
+}
+
+int
+f5 (char *s)
+{
+ return snprintf (s, 8, "%d", 123);
+}
+
+int
+f6 (int *p, char *s)
+{
+ const char *t = "bar";
+ return snprintf (s, 8, "%s", t);
+}
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr89998-2.c b/gcc/testsuite/gcc.c-torture/compile/pr89998-2.c
new file mode 100644
index 0000000..19e318b
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr89998-2.c
@@ -0,0 +1,4 @@
+/* PR tree-optimization/89998 */
+/* { dg-additional-options "-fno-printf-return-value" } */
+
+#include "pr89998-1.c"