diff options
author | Jakub Jelinek <jakub@redhat.com> | 2017-01-03 08:23:11 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2017-01-03 08:23:11 +0100 |
commit | 51ad5d5ba376c1eaf76fee8e2457b8bfb9b000c1 (patch) | |
tree | 92fdd2f4310da70779ccbcbc42c0affad3c6ab51 /gcc/gimple-ssa-sprintf.c | |
parent | cd123354c511316c020bf7ff7e4527989b440223 (diff) | |
download | gcc-51ad5d5ba376c1eaf76fee8e2457b8bfb9b000c1.zip gcc-51ad5d5ba376c1eaf76fee8e2457b8bfb9b000c1.tar.gz gcc-51ad5d5ba376c1eaf76fee8e2457b8bfb9b000c1.tar.bz2 |
re PR tree-optimization/78965 (Invalid -fprintf-return-value optimization)
PR tree-optimization/78965
* gimple-ssa-sprintf.c (pass_sprintf_length::compute_format_length):
Change first argument from const call_info & to call_info &. For %n
set info.nowrite to false.
* gcc.dg/pr78965.c: New test.
From-SVN: r244014
Diffstat (limited to 'gcc/gimple-ssa-sprintf.c')
-rw-r--r-- | gcc/gimple-ssa-sprintf.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c index ecd2267..5bf0215 100644 --- a/gcc/gimple-ssa-sprintf.c +++ b/gcc/gimple-ssa-sprintf.c @@ -131,7 +131,7 @@ public: void handle_gimple_call (gimple_stmt_iterator*); struct call_info; - bool compute_format_length (const call_info &, format_result *); + bool compute_format_length (call_info &, format_result *); }; bool @@ -710,7 +710,8 @@ struct pass_sprintf_length::call_info /* True for bounded functions like snprintf that specify a zero-size buffer as a request to compute the size of output without actually - writing any. */ + writing any. NOWRITE is cleared in response to the %n directive + which has side-effects similar to writing output. */ bool nowrite; }; @@ -2357,7 +2358,7 @@ add_bytes (const pass_sprintf_length::call_info &info, that caused the processing to be terminated early). */ bool -pass_sprintf_length::compute_format_length (const call_info &info, +pass_sprintf_length::compute_format_length (call_info &info, format_result *res) { /* The variadic argument counter. */ @@ -2624,6 +2625,9 @@ pass_sprintf_length::compute_format_length (const call_info &info, return false; case 'n': + /* %n has side-effects even when nothing is actually printed to + any buffer. */ + info.nowrite = false; break; case 'c': |