diff options
author | Martin Sebor <msebor@redhat.com> | 2018-03-07 19:30:31 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2018-03-07 12:30:31 -0700 |
commit | a76acaedcee2e75b16adfa0112632873c1fe2e71 (patch) | |
tree | 06a0c23188ccd0d051f0d12c261d793b03baaa68 /gcc/tree-ssa-strlen.c | |
parent | b78b513e41b3d491efa0bd639cedbad8622a09bd (diff) | |
download | gcc-a76acaedcee2e75b16adfa0112632873c1fe2e71.zip gcc-a76acaedcee2e75b16adfa0112632873c1fe2e71.tar.gz gcc-a76acaedcee2e75b16adfa0112632873c1fe2e71.tar.bz2 |
PR tree-optimization/84468 - bogus -Wstringop-truncation despite assignment after conditional strncpy
gcc/ChangeLog:
PR tree-optimization/84468
* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Consider successor
basic block when looking for nul assignment.
gcc/testsuite/ChangeLog:
PR tree-optimization/84468
* g++.dg/warn/Wstringop-truncation-2.C: New test.
* gcc.dg/Wstringop-truncation.c: New test.
* gcc.dg/Wstringop-truncation-2.c: New test.
From-SVN: r258339
Diffstat (limited to 'gcc/tree-ssa-strlen.c')
-rw-r--r-- | gcc/tree-ssa-strlen.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 1266f39..72f6a17 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -1856,8 +1856,33 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt) avoid the truncation warning. */ gsi_next_nondebug (&gsi); gimple *next_stmt = gsi_stmt (gsi); + if (!next_stmt) + { + /* When there is no statement in the same basic block check + the immediate successor block. */ + if (basic_block bb = gimple_bb (stmt)) + { + if (single_succ_p (bb)) + { + /* For simplicity, ignore blocks with multiple outgoing + edges for now and only consider successor blocks along + normal edges. */ + edge e = EDGE_SUCC (bb, 0); + if (!(e->flags & EDGE_ABNORMAL)) + { + gsi = gsi_start_bb (e->dest); + next_stmt = gsi_stmt (gsi); + if (next_stmt && is_gimple_debug (next_stmt)) + { + gsi_next_nondebug (&gsi); + next_stmt = gsi_stmt (gsi); + } + } + } + } + } - if (!gsi_end_p (gsi) && is_gimple_assign (next_stmt)) + if (next_stmt && is_gimple_assign (next_stmt)) { tree lhs = gimple_assign_lhs (next_stmt); tree_code code = TREE_CODE (lhs); |