Commit a09ca93a by Jeff Law Committed by Jeff Law

gimple-ssa-sprintf.c: Include domwalk.h.

	* gimple-ssa-sprintf.c: Include domwalk.h.
	(class sprintf_dom_walker): New class, derived from dom_walker.
	(sprintf_dom_walker::before_dom_children): New function.
	(struct call_info): Moved into sprintf_dom_walker class
	(compute_formath_length, handle_gimple_call): Likewise.
	(sprintf_length::execute): Call the dominator walker rather
	than walking the statements.

From-SVN: r254156
parent a565d95c
2017-10-27 Jeff Law <law@redhat.com> 2017-10-27 Jeff Law <law@redhat.com>
* gimple-ssa-sprintf.c: Include domwalk.h.
(class sprintf_dom_walker): New class, derived from dom_walker.
(sprintf_dom_walker::before_dom_children): New function.
(struct call_info): Moved into sprintf_dom_walker class
(compute_formath_length, handle_gimple_call): Likewise.
(sprintf_length::execute): Call the dominator walker rather
than walking the statements.
* tree-vrp.c (check_all_array_refs): Do not use wi->info to smuggle * tree-vrp.c (check_all_array_refs): Do not use wi->info to smuggle
gimple statement locations. gimple statement locations.
(check_array_bounds): Corresponding changes. Get the statement's (check_array_bounds): Corresponding changes. Get the statement's
...@@ -79,6 +79,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -79,6 +79,7 @@ along with GCC; see the file COPYING3. If not see
#include "toplev.h" #include "toplev.h"
#include "substring-locations.h" #include "substring-locations.h"
#include "diagnostic.h" #include "diagnostic.h"
#include "domwalk.h"
/* The likely worst case value of MB_LEN_MAX for the target, large enough /* The likely worst case value of MB_LEN_MAX for the target, large enough
for UTF-8. Ideally, this would be obtained by a target hook if it were for UTF-8. Ideally, this would be obtained by a target hook if it were
...@@ -113,6 +114,19 @@ static int warn_level; ...@@ -113,6 +114,19 @@ static int warn_level;
struct format_result; struct format_result;
class sprintf_dom_walker : public dom_walker
{
public:
sprintf_dom_walker () : dom_walker (CDI_DOMINATORS) {}
~sprintf_dom_walker () {}
virtual edge before_dom_children (basic_block) FINAL OVERRIDE;
bool handle_gimple_call (gimple_stmt_iterator *);
struct call_info;
bool compute_format_length (call_info &, format_result *);
};
class pass_sprintf_length : public gimple_opt_pass class pass_sprintf_length : public gimple_opt_pass
{ {
bool fold_return_value; bool fold_return_value;
...@@ -135,10 +149,6 @@ public: ...@@ -135,10 +149,6 @@ public:
fold_return_value = param; fold_return_value = param;
} }
bool handle_gimple_call (gimple_stmt_iterator *);
struct call_info;
bool compute_format_length (call_info &, format_result *);
}; };
bool bool
...@@ -976,7 +986,7 @@ bytes_remaining (unsigned HOST_WIDE_INT navail, const format_result &res) ...@@ -976,7 +986,7 @@ bytes_remaining (unsigned HOST_WIDE_INT navail, const format_result &res)
/* Description of a call to a formatted function. */ /* Description of a call to a formatted function. */
struct pass_sprintf_length::call_info struct sprintf_dom_walker::call_info
{ {
/* Function call statement. */ /* Function call statement. */
gimple *callstmt; gimple *callstmt;
...@@ -2348,7 +2358,7 @@ format_plain (const directive &dir, tree) ...@@ -2348,7 +2358,7 @@ format_plain (const directive &dir, tree)
should be diagnosed given the AVAILable space in the destination. */ should be diagnosed given the AVAILable space in the destination. */
static bool static bool
should_warn_p (const pass_sprintf_length::call_info &info, should_warn_p (const sprintf_dom_walker::call_info &info,
const result_range &avail, const result_range &result) const result_range &avail, const result_range &result)
{ {
if (result.max <= avail.min) if (result.max <= avail.min)
...@@ -2419,7 +2429,7 @@ should_warn_p (const pass_sprintf_length::call_info &info, ...@@ -2419,7 +2429,7 @@ should_warn_p (const pass_sprintf_length::call_info &info,
static bool static bool
maybe_warn (substring_loc &dirloc, location_t argloc, maybe_warn (substring_loc &dirloc, location_t argloc,
const pass_sprintf_length::call_info &info, const sprintf_dom_walker::call_info &info,
const result_range &avail_range, const result_range &res, const result_range &avail_range, const result_range &res,
const directive &dir) const directive &dir)
{ {
...@@ -2716,7 +2726,7 @@ maybe_warn (substring_loc &dirloc, location_t argloc, ...@@ -2716,7 +2726,7 @@ maybe_warn (substring_loc &dirloc, location_t argloc,
in *RES. Return true if the directive has been handled. */ in *RES. Return true if the directive has been handled. */
static bool static bool
format_directive (const pass_sprintf_length::call_info &info, format_directive (const sprintf_dom_walker::call_info &info,
format_result *res, const directive &dir) format_result *res, const directive &dir)
{ {
/* Offset of the beginning of the directive from the beginning /* Offset of the beginning of the directive from the beginning
...@@ -3004,7 +3014,7 @@ format_directive (const pass_sprintf_length::call_info &info, ...@@ -3004,7 +3014,7 @@ format_directive (const pass_sprintf_length::call_info &info,
the directive. */ the directive. */
static size_t static size_t
parse_directive (pass_sprintf_length::call_info &info, parse_directive (sprintf_dom_walker::call_info &info,
directive &dir, format_result *res, directive &dir, format_result *res,
const char *str, unsigned *argno) const char *str, unsigned *argno)
{ {
...@@ -3431,7 +3441,7 @@ parse_directive (pass_sprintf_length::call_info &info, ...@@ -3431,7 +3441,7 @@ parse_directive (pass_sprintf_length::call_info &info,
that caused the processing to be terminated early). */ that caused the processing to be terminated early). */
bool bool
pass_sprintf_length::compute_format_length (call_info &info, sprintf_dom_walker::compute_format_length (call_info &info,
format_result *res) format_result *res)
{ {
if (dump_file) if (dump_file)
...@@ -3514,7 +3524,7 @@ get_destination_size (tree dest) ...@@ -3514,7 +3524,7 @@ get_destination_size (tree dest)
of its return values. */ of its return values. */
static bool static bool
is_call_safe (const pass_sprintf_length::call_info &info, is_call_safe (const sprintf_dom_walker::call_info &info,
const format_result &res, bool under4k, const format_result &res, bool under4k,
unsigned HOST_WIDE_INT retval[2]) unsigned HOST_WIDE_INT retval[2])
{ {
...@@ -3573,7 +3583,7 @@ is_call_safe (const pass_sprintf_length::call_info &info, ...@@ -3573,7 +3583,7 @@ is_call_safe (const pass_sprintf_length::call_info &info,
static bool static bool
try_substitute_return_value (gimple_stmt_iterator *gsi, try_substitute_return_value (gimple_stmt_iterator *gsi,
const pass_sprintf_length::call_info &info, const sprintf_dom_walker::call_info &info,
const format_result &res) const format_result &res)
{ {
tree lhs = gimple_get_lhs (info.callstmt); tree lhs = gimple_get_lhs (info.callstmt);
...@@ -3690,7 +3700,7 @@ try_substitute_return_value (gimple_stmt_iterator *gsi, ...@@ -3690,7 +3700,7 @@ try_substitute_return_value (gimple_stmt_iterator *gsi,
static bool static bool
try_simplify_call (gimple_stmt_iterator *gsi, try_simplify_call (gimple_stmt_iterator *gsi,
const pass_sprintf_length::call_info &info, const sprintf_dom_walker::call_info &info,
const format_result &res) const format_result &res)
{ {
unsigned HOST_WIDE_INT dummy[2]; unsigned HOST_WIDE_INT dummy[2];
...@@ -3717,7 +3727,7 @@ try_simplify_call (gimple_stmt_iterator *gsi, ...@@ -3717,7 +3727,7 @@ try_simplify_call (gimple_stmt_iterator *gsi,
and gsi_next should not be performed in the caller. */ and gsi_next should not be performed in the caller. */
bool bool
pass_sprintf_length::handle_gimple_call (gimple_stmt_iterator *gsi) sprintf_dom_walker::handle_gimple_call (gimple_stmt_iterator *gsi)
{ {
call_info info = call_info (); call_info info = call_info ();
...@@ -3982,6 +3992,24 @@ pass_sprintf_length::handle_gimple_call (gimple_stmt_iterator *gsi) ...@@ -3982,6 +3992,24 @@ pass_sprintf_length::handle_gimple_call (gimple_stmt_iterator *gsi)
return call_removed; return call_removed;
} }
edge
sprintf_dom_walker::before_dom_children (basic_block bb)
{
for (gimple_stmt_iterator si = gsi_start_bb (bb); !gsi_end_p (si); )
{
/* Iterate over statements, looking for function calls. */
gimple *stmt = gsi_stmt (si);
if (is_gimple_call (stmt) && handle_gimple_call (&si))
/* If handle_gimple_call returns true, the iterator is
already pointing to the next statement. */
continue;
gsi_next (&si);
}
return NULL;
}
/* Execute the pass for function FUN. */ /* Execute the pass for function FUN. */
unsigned int unsigned int
...@@ -3989,26 +4017,13 @@ pass_sprintf_length::execute (function *fun) ...@@ -3989,26 +4017,13 @@ pass_sprintf_length::execute (function *fun)
{ {
init_target_to_host_charmap (); init_target_to_host_charmap ();
basic_block bb; calculate_dominance_info (CDI_DOMINATORS);
FOR_EACH_BB_FN (bb, fun)
{
for (gimple_stmt_iterator si = gsi_start_bb (bb); !gsi_end_p (si); )
{
/* Iterate over statements, looking for function calls. */
gimple *stmt = gsi_stmt (si);
if (is_gimple_call (stmt) && handle_gimple_call (&si))
/* If handle_gimple_call returns true, the iterator is
already pointing to the next statement. */
continue;
gsi_next (&si); sprintf_dom_walker sprintf_dom_walker;
} sprintf_dom_walker.walk (ENTRY_BLOCK_PTR_FOR_FN (fun));
}
/* Clean up object size info. */ /* Clean up object size info. */
fini_object_sizes (); fini_object_sizes ();
return 0; return 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