public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6441] gimple-fold: Fix up fputs -> fwrite folding [PR108988] Date: Fri, 3 Mar 2023 10:20:32 +0000 (GMT) [thread overview] Message-ID: <20230303102032.620ED3858D33@sourceware.org> (raw) https://gcc.gnu.org/g:dbeccab7a1f5dcc1876c854f17816047ba1ef137 commit r13-6441-gdbeccab7a1f5dcc1876c854f17816047ba1ef137 Author: Jakub Jelinek <jakub@redhat.com> Date: Fri Mar 3 11:13:40 2023 +0100 gimple-fold: Fix up fputs -> fwrite folding [PR108988] 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.). 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. Diff: --- gcc/gimple-fold.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index f2b3e4bebc3..2b6855d1205 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -2954,8 +2954,7 @@ gimple_fold_builtin_fputs (gimple_stmt_iterator *gsi, /* 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_iterator *gsi, 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_iterator *gsi, 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; }
reply other threads:[~2023-03-03 10:20 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230303102032.620ED3858D33@sourceware.org \ --to=jakub@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).