PR middle-end/83688 - check if buffers may overlap when copying strings using sprintf
authorMartin Sebor <msebor@redhat.com>
Tue, 12 Nov 2019 17:18:37 +0000 (17:18 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Tue, 12 Nov 2019 17:18:37 +0000 (10:18 -0700)
commit937a86b49e4ed8ef72c1384d617feff26580a048
treef247820d00501e7e2424408054361e5b8ea56067
parent966e31a17b92d627dc323a77d363948012c3163d
PR middle-end/83688 - check if buffers may overlap when copying strings using sprintf

gcc/ChangeLog:

PR middle-end/83688
* gimple-ssa-sprintf.c (format_result::alias_info): New struct.
(directive::argno): New member.
(format_result::aliases, format_result::alias_count): New data members.
(format_result::append_alias): New member function.
(fmtresult::dst_offset): New data member.
(pass_sprintf_length::call_info::dst_origin): New data member.
(pass_sprintf_length::call_info::dst_field, dst_offset): Same.
(char_type_p, array_elt_at_offset, field_at_offset): New functions.
(get_origin_and_offset): Same.
(format_string): Call it.
(format_directive): Call append_alias and set directive argument
number.
(maybe_warn_overlap): New function.
(pass_sprintf_length::compute_format_length): Call it.
(pass_sprintf_length::handle_gimple_call): Initialize new members.
* gcc/tree-ssa-strlen.c (): Also enable when -Wrestrict is on.

gcc/testsuite/ChangeLog:

PR tree-optimization/35503
* gcc.dg/tree-ssa/builtin-sprintf-warn-23.c: New test.

From-SVN: r278098
gcc/ChangeLog
gcc/gimple-ssa-sprintf.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-23.c [new file with mode: 0644]
gcc/tree-ssa-strlen.c