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
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
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
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
--- /dev/null
+/* 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);
+}