Commit 937a86b4 by Martin Sebor Committed by Martin Sebor

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
parent 966e31a1
2019-11-12 Martin Sebor <msebor@redhat.com>
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.
2019-11-12 Ilya Leoshkevich <iii@linux.ibm.com> 2019-11-12 Ilya Leoshkevich <iii@linux.ibm.com>
PR rtl-optimization/92430 PR rtl-optimization/92430
2019-11-12 Martin Sebor <msebor@redhat.com>
PR tree-optimization/35503
* gcc.dg/tree-ssa/builtin-sprintf-warn-23.c: New test.
2019-11-12 Nathan Sidwell <nathan@acm.org> 2019-11-12 Nathan Sidwell <nathan@acm.org>
* g++.dg/lookup/pr6936.C: Delete, identical to using38.C * g++.dg/lookup/pr6936.C: Delete, identical to using38.C
......
...@@ -5344,6 +5344,7 @@ pass_strlen::gate (function *) ...@@ -5344,6 +5344,7 @@ pass_strlen::gate (function *)
{ {
return ((warn_format_overflow > 0 return ((warn_format_overflow > 0
|| warn_format_trunc > 0 || warn_format_trunc > 0
|| warn_restrict > 0
|| flag_optimize_strlen > 0 || flag_optimize_strlen > 0
|| flag_printf_return_value) || flag_printf_return_value)
&& optimize > 0); && optimize > 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment