* [PATCH] gimple-fold: Fix up fputs -> fwrite folding [PR108988]
@ 2023-03-03 9:46 Jakub Jelinek
2023-03-03 9:59 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2023-03-03 9:46 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
Hi!
gimple_fold_builtin_fputs when folding fputs into fwrite emits the third
argument (INTEGER_CST) with incorrect type - get_maxval_strlen or c_strlen
return ssizetype, while fwrite argument is size_type_node.
The following patch fixes that, I've skimmed through the rest of
gimple-fold.cc and in all other places get_maxval_strlen/c_strlen result
was fold_converted to size_type_node already (or GIMPLE cast stmt has been
emitted directly etc.).
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2023-03-03 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/108988
* gimple-fold.cc (gimple_fold_builtin_fputs): Fold len to
size_type_node before passing it as argument to fwrite. Formatting
fixes.
--- gcc/gimple-fold.cc.jj 2023-02-28 11:38:28.957868160 +0100
+++ gcc/gimple-fold.cc 2023-03-02 10:34:42.791504589 +0100
@@ -2954,8 +2954,7 @@ gimple_fold_builtin_fputs (gimple_stmt_i
/* Get the length of the string passed to fputs. If the length
can't be determined, punt. */
tree len = get_maxval_strlen (arg0, SRK_STRLEN);
- if (!len
- || TREE_CODE (len) != INTEGER_CST)
+ if (!len || TREE_CODE (len) != INTEGER_CST)
return false;
switch (compare_tree_int (len, 1))
@@ -2972,9 +2971,10 @@ gimple_fold_builtin_fputs (gimple_stmt_i
if (!fn_fputc)
return false;
- gimple *repl = gimple_build_call (fn_fputc, 2,
- build_int_cst
- (integer_type_node, p[0]), arg1);
+ gimple *repl
+ = gimple_build_call (fn_fputc, 2,
+ build_int_cst (integer_type_node, p[0]),
+ arg1);
replace_call_with_call_and_fold (gsi, repl);
return true;
}
@@ -2990,8 +2990,9 @@ gimple_fold_builtin_fputs (gimple_stmt_i
if (!fn_fwrite)
return false;
- gimple *repl = gimple_build_call (fn_fwrite, 4, arg0,
- size_one_node, len, arg1);
+ gimple *repl
+ = gimple_build_call (fn_fwrite, 4, arg0, size_one_node,
+ fold_convert (size_type_node, len), arg1);
replace_call_with_call_and_fold (gsi, repl);
return true;
}
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] gimple-fold: Fix up fputs -> fwrite folding [PR108988]
2023-03-03 9:46 [PATCH] gimple-fold: Fix up fputs -> fwrite folding [PR108988] Jakub Jelinek
@ 2023-03-03 9:59 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2023-03-03 9:59 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On Fri, 3 Mar 2023, Jakub Jelinek wrote:
> Hi!
>
> gimple_fold_builtin_fputs when folding fputs into fwrite emits the third
> argument (INTEGER_CST) with incorrect type - get_maxval_strlen or c_strlen
> return ssizetype, while fwrite argument is size_type_node.
> The following patch fixes that, I've skimmed through the rest of
> gimple-fold.cc and in all other places get_maxval_strlen/c_strlen result
> was fold_converted to size_type_node already (or GIMPLE cast stmt has been
> emitted directly etc.).
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
> 2023-03-03 Jakub Jelinek <jakub@redhat.com>
>
> PR tree-optimization/108988
> * gimple-fold.cc (gimple_fold_builtin_fputs): Fold len to
> size_type_node before passing it as argument to fwrite. Formatting
> fixes.
>
> --- gcc/gimple-fold.cc.jj 2023-02-28 11:38:28.957868160 +0100
> +++ gcc/gimple-fold.cc 2023-03-02 10:34:42.791504589 +0100
> @@ -2954,8 +2954,7 @@ gimple_fold_builtin_fputs (gimple_stmt_i
> /* Get the length of the string passed to fputs. If the length
> can't be determined, punt. */
> tree len = get_maxval_strlen (arg0, SRK_STRLEN);
> - if (!len
> - || TREE_CODE (len) != INTEGER_CST)
> + if (!len || TREE_CODE (len) != INTEGER_CST)
> return false;
>
> switch (compare_tree_int (len, 1))
> @@ -2972,9 +2971,10 @@ gimple_fold_builtin_fputs (gimple_stmt_i
> if (!fn_fputc)
> return false;
>
> - gimple *repl = gimple_build_call (fn_fputc, 2,
> - build_int_cst
> - (integer_type_node, p[0]), arg1);
> + gimple *repl
> + = gimple_build_call (fn_fputc, 2,
> + build_int_cst (integer_type_node, p[0]),
> + arg1);
> replace_call_with_call_and_fold (gsi, repl);
> return true;
> }
> @@ -2990,8 +2990,9 @@ gimple_fold_builtin_fputs (gimple_stmt_i
> if (!fn_fwrite)
> return false;
>
> - gimple *repl = gimple_build_call (fn_fwrite, 4, arg0,
> - size_one_node, len, arg1);
> + gimple *repl
> + = gimple_build_call (fn_fwrite, 4, arg0, size_one_node,
> + fold_convert (size_type_node, len), arg1);
> replace_call_with_call_and_fold (gsi, repl);
> return true;
> }
>
> Jakub
>
>
--
Richard Biener <rguenther@suse.de>
SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg,
Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman;
HRB 36809 (AG Nuernberg)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-03 9:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-03 9:46 [PATCH] gimple-fold: Fix up fputs -> fwrite folding [PR108988] Jakub Jelinek
2023-03-03 9:59 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).