aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-array-bounds.cc
diff options
context:
space:
mode:
authorAndrew MacLeod <amacleod@redhat.com>2024-06-05 15:12:27 -0400
committerAndrew MacLeod <amacleod@redhat.com>2024-06-10 16:26:58 -0400
commit74ee12ff68243bb177fb8653474dff80c3792139 (patch)
tree6c006043c78264870d2d3424305ee5cd489fee29 /gcc/gimple-array-bounds.cc
parent9aaf29b9ba5ffe332220d002ddde85d96fd6657d (diff)
downloadgcc-74ee12ff68243bb177fb8653474dff80c3792139.zip
gcc-74ee12ff68243bb177fb8653474dff80c3792139.tar.gz
gcc-74ee12ff68243bb177fb8653474dff80c3792139.tar.bz2
Move array_bounds warnings into a separate pass.
Array bounds checking is currently tied to VRP. This causes issues with using laternate VRP algorithms as well as experimenting with moving the location of the warnings later. This moves it to its own pass and cleans up the vrp_pass object. * gimple-array-bounds.cc (array_bounds_checker::array_bounds_checker): Always use current range_query. (pass_data_array_bounds): New. (pass_array_bounds): New. (make_pass_array_bounds): New. * gimple-array-bounds.h (array_bounds_checker): Adjust prototype. * passes.def (pass_array_bounds): New. Add after VRP1. * timevar.def (TV_TREE_ARRAY_BOUNDS): New timevar. * tree-pass.h (make_pass_array_bounds): Add prototype. * tree-vrp.cc (execute_ranger_vrp): Remove warning param and do not invoke array bounds warning pass. (pass_vrp::pass_vrp): Adjust params. (pass_vrp::close): Adjust parameters. (pass_vrp::warn_array_bounds_p): Remove. (make_pass_vrp): Remove warning param. (make_pass_early_vrp): Remove warning param. (make_pass_fast_vrp): Remove warning param.
Diffstat (limited to 'gcc/gimple-array-bounds.cc')
-rw-r--r--gcc/gimple-array-bounds.cc63
1 files changed, 55 insertions, 8 deletions
diff --git a/gcc/gimple-array-bounds.cc b/gcc/gimple-array-bounds.cc
index 2fa3d18..1637a2f 100644
--- a/gcc/gimple-array-bounds.cc
+++ b/gcc/gimple-array-bounds.cc
@@ -38,10 +38,12 @@ along with GCC; see the file COPYING3. If not see
#include "domwalk.h"
#include "tree-cfg.h"
#include "attribs.h"
+#include "tree-pass.h"
+#include "gimple-range.h"
-array_bounds_checker::array_bounds_checker (struct function *func,
- range_query *qry)
- : fun (func), m_ptr_qry (qry)
+// Always use the current range query for the bounds checker.
+array_bounds_checker::array_bounds_checker (struct function *func)
+ : fun (func), m_ptr_qry (get_range_query (func))
{
/* No-op. */
}
@@ -838,11 +840,7 @@ class check_array_bounds_dom_walker : public dom_walker
{
public:
check_array_bounds_dom_walker (array_bounds_checker *checker)
- : dom_walker (CDI_DOMINATORS,
- /* Discover non-executable edges, preserving EDGE_EXECUTABLE
- flags, so that we can merge in information on
- non-executable edges from vrp_folder . */
- REACHABLE_BLOCKS_PRESERVING_FLAGS),
+ : dom_walker (CDI_DOMINATORS, REACHABLE_BLOCKS),
checker (checker) { }
~check_array_bounds_dom_walker () {}
@@ -888,3 +886,52 @@ array_bounds_checker::check ()
check_array_bounds_dom_walker w (this);
w.walk (ENTRY_BLOCK_PTR_FOR_FN (fun));
}
+
+const pass_data pass_data_array_bounds =
+{
+ GIMPLE_PASS, /* type */
+ "bounds", /* name */
+ OPTGROUP_NONE, /* optinfo_flags */
+ TV_TREE_ARRAY_BOUNDS, /* tv_id */
+ PROP_ssa, /* properties_required */
+ 0, /* properties_provided */
+ 0, /* properties_destroyed */
+ 0, /* todo_flags_start */
+ ( 0 ), /* No TODOs */
+};
+
+class pass_array_bounds : public gimple_opt_pass
+{
+public:
+ pass_array_bounds (gcc::context *ctxt, const pass_data &data_)
+ : gimple_opt_pass (data_, ctxt), data (data_)
+ { }
+
+ /* opt_pass methods: */
+ opt_pass * clone () final override
+ { return new pass_array_bounds (m_ctxt, data); }
+ bool gate (function *) final override
+ {
+ // Gate on the VRP pass to preserve previous behavior.
+ return flag_tree_vrp && (warn_array_bounds || warn_strict_flex_arrays);
+ }
+ unsigned int execute (function *fun) final override
+ {
+ calculate_dominance_info (CDI_DOMINATORS);
+ // Enable ranger as the current range query.
+ enable_ranger (fun, false);
+ array_bounds_checker array_checker (fun);
+ array_checker.check ();
+ disable_ranger (fun);
+ return 0;
+ }
+
+ private:
+ const pass_data &data;
+}; // class pass_array_bounds
+
+gimple_opt_pass *
+make_pass_array_bounds (gcc::context *ctxt)
+{
+ return new pass_array_bounds (ctxt, pass_data_array_bounds);
+}