From 5a40ae3c3acf7eaabc9599f5701adbd2f6ec607e Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 7 Dec 2017 13:21:51 +0000 Subject: [PATCH] re PR tree-optimization/83296 (missing -Wstringop-overflow due to missing range info for MAX_EXPR) 2017-12-07 Richard Biener PR tree-optimization/83296 PR tree-optimization/67769 * tree-ssa-phiopt.c (conditional_replacement): Do not reset flow sensitive info in an unrelated BB. (value_replacement): Use reset_flow_sensitive_info. (minmax_replacement): Reset flow sensitive info on the def we move. Do not reset flow sensitive info in the whole BB we move the stmt to. (abs_replacement): Likewise. * g++.dg/warn/Wstringop-overflow-1.C: New testcase. From-SVN: r255466 --- gcc/ChangeLog | 12 +++++++ gcc/testsuite/ChangeLog | 6 ++++ .../g++.dg/warn/Wstringop-overflow-1.C | 15 ++++++++ gcc/tree-ssa-phiopt.c | 35 +++++++++---------- 4 files changed, 50 insertions(+), 18 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wstringop-overflow-1.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index dab026a0c83..3f6fbaa35b5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2017-12-07 Richard Biener + + PR tree-optimization/83296 + PR tree-optimization/67769 + * tree-ssa-phiopt.c (conditional_replacement): Do not reset + flow sensitive info in an unrelated BB. + (value_replacement): Use reset_flow_sensitive_info. + (minmax_replacement): Reset flow sensitive info on the def + we move. Do not reset flow sensitive info in the whole BB + we move the stmt to. + (abs_replacement): Likewise. + 2017-12-07 Segher Boessenkool PR target/43871 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d85142f1bfc..bb44c700dc2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2017-12-07 Richard Biener + + PR tree-optimization/83296 + PR tree-optimization/67769 + * g++.dg/warn/Wstringop-overflow-1.C: New testcase. + 2017-12-07 Julia Koval * gcc.target/i386/avx512-check.h: Handle bit_VAES. diff --git a/gcc/testsuite/g++.dg/warn/Wstringop-overflow-1.C b/gcc/testsuite/g++.dg/warn/Wstringop-overflow-1.C new file mode 100644 index 00000000000..ce5157bfe20 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wstringop-overflow-1.C @@ -0,0 +1,15 @@ +// { dg-do compile } +// { dg-additional-options "-O2 -Wstringop-overflow=2" } + +struct S { + char a[5]; + void (*pf)(void); +}; + +void f (struct S *s, int n) +{ + if (n < sizeof s->a + 1) + n = sizeof s->a + 1; + + __builtin_strncpy (s->a, "123456", n); // { dg-warning "writing 6" } +} diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c index 6e0e18689da..85f51a479e2 100644 --- a/gcc/tree-ssa-phiopt.c +++ b/gcc/tree-ssa-phiopt.c @@ -672,7 +672,6 @@ conditional_replacement (basic_block cond_bb, basic_block middle_bb, } replace_phi_edge_with_variable (cond_bb, e1, phi, new_var); - reset_flow_sensitive_info_in_bb (cond_bb); /* Note that we optimized this PHI. */ return true; @@ -1138,22 +1137,22 @@ value_replacement (basic_block cond_bb, basic_block middle_bb, cond_rhs, false, rhs2)))))) { gsi = gsi_for_stmt (cond); + /* Moving ASSIGN might change VR of lhs, e.g. when moving u_6 + def-stmt in: + if (n_5 != 0) + goto ; + else + goto ; + + : + # RANGE [0, 4294967294] + u_6 = n_5 + 4294967295; + + : + # u_3 = PHI */ + reset_flow_sensitive_info (lhs); if (INTEGRAL_TYPE_P (TREE_TYPE (lhs))) { - /* Moving ASSIGN might change VR of lhs, e.g. when moving u_6 - def-stmt in: - if (n_5 != 0) - goto ; - else - goto ; - - : - # RANGE [0, 4294967294] - u_6 = n_5 + 4294967295; - - : - # u_3 = PHI */ - SSA_NAME_RANGE_INFO (lhs) = NULL; /* If available, we can use VR of phi result at least. */ tree phires = gimple_phi_result (phi); struct range_info_def *phires_range_info @@ -1166,7 +1165,7 @@ value_replacement (basic_block cond_bb, basic_block middle_bb, for (int i = prep_cnt - 1; i >= 0; --i) { tree plhs = gimple_assign_lhs (prep_stmt[i]); - SSA_NAME_RANGE_INFO (plhs) = NULL; + reset_flow_sensitive_info (plhs); gsi_from = gsi_for_stmt (prep_stmt[i]); gsi_move_before (&gsi_from, &gsi); } @@ -1490,6 +1489,8 @@ minmax_replacement (basic_block cond_bb, basic_block middle_bb, /* Move the statement from the middle block. */ gsi = gsi_last_bb (cond_bb); gsi_from = gsi_last_nondebug_bb (middle_bb); + reset_flow_sensitive_info (SINGLE_SSA_TREE_OPERAND (gsi_stmt (gsi_from), + SSA_OP_DEF)); gsi_move_before (&gsi_from, &gsi); } @@ -1508,7 +1509,6 @@ minmax_replacement (basic_block cond_bb, basic_block middle_bb, gsi_insert_before (&gsi, new_stmt, GSI_NEW_STMT); replace_phi_edge_with_variable (cond_bb, e1, phi, result); - reset_flow_sensitive_info_in_bb (cond_bb); return true; } @@ -1636,7 +1636,6 @@ abs_replacement (basic_block cond_bb, basic_block middle_bb, } replace_phi_edge_with_variable (cond_bb, e1, phi, result); - reset_flow_sensitive_info_in_bb (cond_bb); /* Note that we optimized this PHI. */ return true; -- 2.30.2