PR tree-optimization/83431 - -Wformat-truncation may incorrectly report truncation
authorMartin Sebor <msebor@redhat.com>
Mon, 26 Aug 2019 18:29:45 +0000 (18:29 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Mon, 26 Aug 2019 18:29:45 +0000 (12:29 -0600)
commit22fca489eaf98f2691772b51773a1e4eb7bb4ef2
tree268157065335369b092a662c434f7753bb19eb7e
parent59bce4ad03e438e81dcaa8ed956fbad6461c7d75
PR tree-optimization/83431 - -Wformat-truncation may incorrectly report truncation

gcc/ChangeLog:

PR c++/83431
* gimple-ssa-sprintf.c (pass_data_sprintf_length): Remove object.
(sprintf_dom_walker): Remove class.
(get_int_range): Make argument const.
(directive::fmtfunc, directive::set_precision): Same.
(format_none): Same.
(build_intmax_type_nodes): Same.
(adjust_range_for_overflow): Same.
(format_floating): Same.
(format_character): Same.
(format_string): Same.
(format_plain): Same.
(get_int_range): Cast away constness.
(format_integer): Same.
(get_string_length): Call get_range_strlen_dynamic.  Handle
null lendata.maxbound.
(should_warn_p): Adjust argument scope qualifier.
(maybe_warn): Same.
(format_directive): Same.
(parse_directive): Same.
(is_call_safe): Same.
(try_substitute_return_value): Same.
(sprintf_dom_walker::handle_printf_call): Rename...
(handle_printf_call): ...to this.  Initialize target to host charmap
here instead of in pass_sprintf_length::execute.
(struct call_info): Make global.
(sprintf_dom_walker::compute_format_length): Make global.
(sprintf_dom_walker::handle_gimple_call): Same.
* passes.def (pass_sprintf_length): Replace with pass_strlen.
* print-rtl.c (print_pattern): Reduce the number of spaces to
avoid -Wformat-truncation.
* tree-pass.h (make_pass_warn_printf): New function.
* tree-ssa-strlen.c (strlen_optimize): New variable.
(get_string_length): Add comments.
(get_range_strlen_dynamic): New function.
(check_and_optimize_call): New function.
(handle_integral_assign): New function.
(strlen_check_and_optimize_stmt): Factor code out into
strlen_check_and_optimize_call and handle_integral_assign.
(strlen_dom_walker::evrp): New member.
(strlen_dom_walker::before_dom_children): Use evrp member.
(strlen_dom_walker::after_dom_children): Use evrp member.
(printf_strlen_execute): New function.
(pass_strlen::gate): Update to handle printf calls.
(dump_strlen_info): New function.
(pass_data_warn_printf): New variable.
(pass_warn_printf): New class.
* tree-ssa-strlen.h (get_range_strlen_dynamic): Declare.
(handle_printf_call): Same.
* tree-vrp.c (value_range_base::type): Adjust assertion.
* vr-values.c (vr_values::update_value_range): Use type of the first
argument rather than the second.

gcc/testsuite/ChangeLog:

PR c++/83431
* gcc.dg/strlenopt-63.c: New test.
* gcc.dg/pr79538.c: Adjust text of expected warning.
* gcc.dg/pr81292-1.c: Adjust pass name.
* gcc.dg/pr81292-2.c: Same.
* gcc.dg/pr81703.c: Same.
* gcc.dg/strcmpopt_2.c: Same.
* gcc.dg/strcmpopt_3.c: Same.
* gcc.dg/strcmpopt_4.c: Same.
* gcc.dg/strlenopt-1.c: Same.
* gcc.dg/strlenopt-10.c: Same.
* gcc.dg/strlenopt-11.c: Same.
* gcc.dg/strlenopt-13.c: Same.
* gcc.dg/strlenopt-14g.c: Same.
* gcc.dg/strlenopt-14gf.c: Same.
* gcc.dg/strlenopt-15.c: Same.
* gcc.dg/strlenopt-16g.c: Same.
* gcc.dg/strlenopt-17g.c: Same.
* gcc.dg/strlenopt-18g.c: Same.
* gcc.dg/strlenopt-19.c: Same.
* gcc.dg/strlenopt-1f.c: Same.
* gcc.dg/strlenopt-2.c: Same.
* gcc.dg/strlenopt-20.c: Same.
* gcc.dg/strlenopt-21.c: Same.
* gcc.dg/strlenopt-22.c: Same.
* gcc.dg/strlenopt-22g.c: Same.
* gcc.dg/strlenopt-24.c: Same.
* gcc.dg/strlenopt-25.c: Same.
* gcc.dg/strlenopt-26.c: Same.
* gcc.dg/strlenopt-27.c: Same.
* gcc.dg/strlenopt-28.c: Same.
* gcc.dg/strlenopt-29.c: Same.
* gcc.dg/strlenopt-2f.c: Same.
* gcc.dg/strlenopt-3.c: Same.
* gcc.dg/strlenopt-30.c: Same.
* gcc.dg/strlenopt-31g.c: Same.
* gcc.dg/strlenopt-32.c: Same.
* gcc.dg/strlenopt-33.c: Same.
* gcc.dg/strlenopt-33g.c: Same.
* gcc.dg/strlenopt-34.c: Same.
* gcc.dg/strlenopt-35.c: Same.
* gcc.dg/strlenopt-4.c: Same.
* gcc.dg/strlenopt-48.c: Same.
* gcc.dg/strlenopt-49.c: Same.
* gcc.dg/strlenopt-4g.c: Same.
* gcc.dg/strlenopt-4gf.c: Same.
* gcc.dg/strlenopt-5.c: Same.
* gcc.dg/strlenopt-50.c: Same.
* gcc.dg/strlenopt-51.c: Same.
* gcc.dg/strlenopt-52.c: Same.
* gcc.dg/strlenopt-53.c: Same.
* gcc.dg/strlenopt-54.c: Same.
* gcc.dg/strlenopt-55.c: Same.
* gcc.dg/strlenopt-56.c: Same.
* gcc.dg/strlenopt-6.c: Same.
* gcc.dg/strlenopt-61.c: Same.
* gcc.dg/strlenopt-7.c: Same.
* gcc.dg/strlenopt-8.c: Same.
* gcc.dg/strlenopt-9.c: Same.
* gcc.dg/strlenopt.h (snprintf, snprintf): Declare.
* gcc.dg/tree-ssa/builtin-snprintf-6.c: New test.
* gcc.dg/tree-ssa/builtin-snprintf-7.c: New test.
* gcc.dg/tree-ssa/builtin-snprintf-8.c: New test.
* gcc.dg/tree-ssa/builtin-snprintf-9.c: New test.
* gcc.dg/tree-ssa/builtin-sprintf-warn-21.c: New test.
* gcc.dg/tree-ssa/dump-4.c: New test.
* gcc.dg/tree-ssa/pr83501.c: Adjust pass name.

From-SVN: r274933
77 files changed:
gcc/ChangeLog
gcc/gimple-ssa-sprintf.c
gcc/passes.def
gcc/print-rtl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr79538.c
gcc/testsuite/gcc.dg/pr81292-1.c
gcc/testsuite/gcc.dg/pr81292-2.c
gcc/testsuite/gcc.dg/pr81703.c
gcc/testsuite/gcc.dg/strcmpopt_2.c
gcc/testsuite/gcc.dg/strcmpopt_3.c
gcc/testsuite/gcc.dg/strcmpopt_4.c
gcc/testsuite/gcc.dg/strlenopt-1.c
gcc/testsuite/gcc.dg/strlenopt-10.c
gcc/testsuite/gcc.dg/strlenopt-11.c
gcc/testsuite/gcc.dg/strlenopt-13.c
gcc/testsuite/gcc.dg/strlenopt-14g.c
gcc/testsuite/gcc.dg/strlenopt-14gf.c
gcc/testsuite/gcc.dg/strlenopt-15.c
gcc/testsuite/gcc.dg/strlenopt-16g.c
gcc/testsuite/gcc.dg/strlenopt-17g.c
gcc/testsuite/gcc.dg/strlenopt-18g.c
gcc/testsuite/gcc.dg/strlenopt-19.c
gcc/testsuite/gcc.dg/strlenopt-1f.c
gcc/testsuite/gcc.dg/strlenopt-2.c
gcc/testsuite/gcc.dg/strlenopt-20.c
gcc/testsuite/gcc.dg/strlenopt-21.c
gcc/testsuite/gcc.dg/strlenopt-22.c
gcc/testsuite/gcc.dg/strlenopt-22g.c
gcc/testsuite/gcc.dg/strlenopt-24.c
gcc/testsuite/gcc.dg/strlenopt-25.c
gcc/testsuite/gcc.dg/strlenopt-26.c
gcc/testsuite/gcc.dg/strlenopt-27.c
gcc/testsuite/gcc.dg/strlenopt-28.c
gcc/testsuite/gcc.dg/strlenopt-29.c
gcc/testsuite/gcc.dg/strlenopt-2f.c
gcc/testsuite/gcc.dg/strlenopt-3.c
gcc/testsuite/gcc.dg/strlenopt-30.c
gcc/testsuite/gcc.dg/strlenopt-31g.c
gcc/testsuite/gcc.dg/strlenopt-32.c
gcc/testsuite/gcc.dg/strlenopt-33.c
gcc/testsuite/gcc.dg/strlenopt-33g.c
gcc/testsuite/gcc.dg/strlenopt-34.c
gcc/testsuite/gcc.dg/strlenopt-35.c
gcc/testsuite/gcc.dg/strlenopt-4.c
gcc/testsuite/gcc.dg/strlenopt-48.c
gcc/testsuite/gcc.dg/strlenopt-49.c
gcc/testsuite/gcc.dg/strlenopt-4g.c
gcc/testsuite/gcc.dg/strlenopt-4gf.c
gcc/testsuite/gcc.dg/strlenopt-5.c
gcc/testsuite/gcc.dg/strlenopt-50.c
gcc/testsuite/gcc.dg/strlenopt-51.c
gcc/testsuite/gcc.dg/strlenopt-52.c
gcc/testsuite/gcc.dg/strlenopt-53.c
gcc/testsuite/gcc.dg/strlenopt-54.c
gcc/testsuite/gcc.dg/strlenopt-55.c
gcc/testsuite/gcc.dg/strlenopt-56.c
gcc/testsuite/gcc.dg/strlenopt-6.c
gcc/testsuite/gcc.dg/strlenopt-61.c
gcc/testsuite/gcc.dg/strlenopt-68.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/strlenopt-7.c
gcc/testsuite/gcc.dg/strlenopt-9.c
gcc/testsuite/gcc.dg/strlenopt.h
gcc/testsuite/gcc.dg/tree-ssa/builtin-snprintf-6.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/builtin-snprintf-7.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/builtin-snprintf-8.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/builtin-snprintf-9.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/builtin-snprintf-warn-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-21.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/dump-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr83501.c
gcc/testsuite/gcc.dg/tree-ssa/strlen-2.c
gcc/tree-pass.h
gcc/tree-ssa-strlen.c
gcc/tree-ssa-strlen.h
gcc/tree-vrp.c
gcc/vr-values.c