https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84468

--- Comment #10 from Martin Sebor <msebor at gcc dot gnu.org> ---
Thanks, I can reproduce it with that test case.  Checking for the basic block
being null fixes the SEGV for me.  Let me retest this and post an update for
review.

Index: gcc/tree-ssa-strlen.c
===================================================================
--- gcc/tree-ssa-strlen.c       (revision 257963)
+++ gcc/tree-ssa-strlen.c       (working copy)
@@ -1856,8 +1856,20 @@ 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);
+         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);

Reply via email to