From aa67d03c30f907fd47adfadff3fb7c58c0b437d1 Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Tue, 20 Feb 2018 11:52:07 -0700 Subject: [PATCH] re PR middle-end/82123 (spurious -Wformat-overflow warning for converted vars) PR middle-end/82123 PR tree-optimization/81592 PR middle-end/79257 * 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. From-SVN: r257852 --- gcc/ChangeLog | 7 +++++++ gcc/gimple-ssa-sprintf.c | 17 ++++++++++++++++- gcc/testsuite/ChangeLog | 7 +++++++ gcc/testsuite/gcc.dg/builtin-unreachable-6.c | 2 +- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 748be06d671..bef9eb1d3ff 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -3,6 +3,13 @@ PR middle-end/82123 PR tree-optimization/81592 PR middle-end/79257 + * 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. * gimple-ssa-evrp-analyze.c (evrp_range_analyzer::enter): Do nothing if not optimizing. (evrp_range_analyzer::record_ranges_from_stmt): Likewise. diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c index a2dd54502e8..545f8337c13 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/ChangeLog b/gcc/testsuite/ChangeLog index d6cedecf44a..de9cd420e9e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2018-02-20 Jeff Law + + PR middle-end/82123 + PR tree-optimization/81592 + PR middle-end/79257 + * gcc.dg/builtin-unreachable-6.c: Turn off VRP. + 2018-02-20 Jakub Jelinek PR c++/84488 diff --git a/gcc/testsuite/gcc.dg/builtin-unreachable-6.c b/gcc/testsuite/gcc.dg/builtin-unreachable-6.c index 1915dd13f42..b0504be89cc 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) -- 2.30.2