https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468
--- Comment #14 from Martin Sebor <msebor at gcc dot gnu.org> --- (In reply to Romain Geissler from comment #13) Ah, right. It's not skipping over debug statements. That's easier to fix than pr84561. This should do it: Index: gcc/tree-ssa-strlen.c =================================================================== --- gcc/tree-ssa-strlen.c (revision 257963) +++ gcc/tree-ssa-strlen.c (working copy) @@ -1856,8 +1856,21 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi 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)) + { + basic_block nextbb + = EDGE_COUNT (bb->succs) ? EDGE_SUCC (bb, 0)->dest : NULL; + gimple_stmt_iterator it = gsi_start_bb (nextbb); + gsi_next_nondebug (&it); + next_stmt = gsi_stmt (it); + } + } - 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);