diff mbox series

[committed,PR,tree-optimization/82123] 02/06 Perform EVRP analysis in sprintf warning pass

Message ID cf794a4f-06a6-a45e-6251-669a7772ce6c@redhat.com
State New
Headers show
Series [committed,PR,tree-optimization/82123] 02/06 Perform EVRP analysis in sprintf warning pass | expand

Commit Message

Jeff Law Feb. 20, 2018, 6:52 p.m. UTC
This is the second patch in the series to fix 82123/81592.  It generates
range information within the sprintf warning pass using the EVRP
analyzer.  We don't use the range information in this patch.

This twiddles one test -- adding the calls into the analyzer from the
sprintf pass causes us to record a range for an object that didn't have
one before and compromises the test.  I just turn off VRP  which is
sufficient to obscure things so that we don't remove the
__builtin_unreachable.


Bootstrapped and regression tested on x86_64-linux-gnu.

Jeff
* gimple-ssa-sprintf.c: Include alloc-pool.h, vr-values.h and 
	gimple-ssa-evrp-analyze.h
	(class sprintf_dom_walker): Add after_dom_children member function.
	Add evrp_range_analyzer member.
	(sprintf_dom_walker::before_dom_children): Call into the EVRP
	range analyzer as needed.
	(sprintf_dom_walker::after_dom_children): New member function.

	* gcc.dg/builtin-unreachable-6.c: Turn off VRP.
diff mbox series

Patch

diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c
index a2dd545..545f833 100644
--- a/gcc/gimple-ssa-sprintf.c
+++ b/gcc/gimple-ssa-sprintf.c
@@ -80,6 +80,9 @@  along with GCC; see the file COPYING3.  If not see
 #include "substring-locations.h"
 #include "diagnostic.h"
 #include "domwalk.h"
+#include "alloc-pool.h"
+#include "vr-values.h"
+#include "gimple-ssa-evrp-analyze.h"
 
 /* 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
@@ -121,10 +124,12 @@  class sprintf_dom_walker : public dom_walker
   ~sprintf_dom_walker () {}
 
   edge before_dom_children (basic_block) FINAL OVERRIDE;
+  void after_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 evrp_range_analyzer evrp_range_analyzer;
 };
 
 class pass_sprintf_length : public gimple_opt_pass
@@ -3456,7 +3461,7 @@  parse_directive (sprintf_dom_walker::call_info &info,
 
 bool
 sprintf_dom_walker::compute_format_length (call_info &info,
-					    format_result *res)
+					   format_result *res)
 {
   if (dump_file)
     {
@@ -4012,11 +4017,15 @@  sprintf_dom_walker::handle_gimple_call (gimple_stmt_iterator *gsi)
 edge
 sprintf_dom_walker::before_dom_children (basic_block bb)
 {
+  evrp_range_analyzer.enter (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);
 
+      /* First record ranges generated by this statement.  */
+      evrp_range_analyzer.record_ranges_from_stmt (stmt, false);
+
       if (is_gimple_call (stmt) && handle_gimple_call (&si))
 	/* If handle_gimple_call returns true, the iterator is
 	   already pointing to the next statement.  */
@@ -4027,6 +4036,12 @@  sprintf_dom_walker::before_dom_children (basic_block bb)
   return NULL;
 }
 
+void
+sprintf_dom_walker::after_dom_children (basic_block bb)
+{
+  evrp_range_analyzer.leave (bb);
+}
+
 /* Execute the pass for function FUN.  */
 
 unsigned int
diff --git a/gcc/testsuite/gcc.dg/builtin-unreachable-6.c b/gcc/testsuite/gcc.dg/builtin-unreachable-6.c
index 1915dd1..b0504be 100644
--- a/gcc/testsuite/gcc.dg/builtin-unreachable-6.c
+++ b/gcc/testsuite/gcc.dg/builtin-unreachable-6.c
@@ -1,5 +1,5 @@ 
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-fab1 -fno-tree-dominator-opts" } */
+/* { dg-options "-O2 -fdump-tree-fab1 -fno-tree-dominator-opts -fno-tree-vrp" } */
 
 void
 foo (int b, int c)