This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] tree-cfg.c: Check that a nonlocal label doesn't appear inthe middle of a basic block. (Take 2)


Hi,

Attached is a revised patch to check that a nonlocal label doesn't
appear in the middle of a basic block.

The previous version of this patch used stmt_starts_bb_p, thereby
verifying that neither a nonlocal label nor a forced label appears
appear in the middle of a basic block.

This version focues on nonlocal labels by explicitly using
DECL_NONLOCAL.  Of course, it can be easily extended to check forced
labels simply by replacing DECL_NONLOCAL with stmt_starts_bb_p.

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

2005-01-20  Kazu Hirata  <kazu@cs.umass.edu>

	* tree-cfg.c (tree_verify_flow_info): Check that a nonlocal
	label doesn't appear in the middle of a basic block.

Index: tree-cfg.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-cfg.c,v
retrieving revision 2.140
diff -c -d -p -r2.140 tree-cfg.c
*** tree-cfg.c	19 Jan 2005 21:02:53 -0000	2.140
--- tree-cfg.c	20 Jan 2005 09:38:39 -0000
*************** tree_verify_flow_info (void)
*** 3595,3619 ****
      {
        bool found_ctrl_stmt = false;
  
        /* Skip labels on the start of basic block.  */
        for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
  	{
! 	  if (TREE_CODE (bsi_stmt (bsi)) != LABEL_EXPR)
  	    break;
  
! 	  if (label_to_block (LABEL_EXPR_LABEL (bsi_stmt (bsi))) != bb)
  	    {
- 	      tree stmt = bsi_stmt (bsi);
  	      error ("Label %s to block does not match in bb %d\n",
  		     IDENTIFIER_POINTER (DECL_NAME (LABEL_EXPR_LABEL (stmt))),
  		     bb->index);
  	      err = 1;
  	    }
  
! 	  if (decl_function_context (LABEL_EXPR_LABEL (bsi_stmt (bsi)))
  	      != current_function_decl)
  	    {
- 	      tree stmt = bsi_stmt (bsi);
  	      error ("Label %s has incorrect context in bb %d\n",
  		     IDENTIFIER_POINTER (DECL_NAME (LABEL_EXPR_LABEL (stmt))),
  		     bb->index);
--- 3595,3631 ----
      {
        bool found_ctrl_stmt = false;
  
+       stmt = NULL_TREE;
+ 
        /* Skip labels on the start of basic block.  */
        for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
  	{
! 	  tree prev_stmt = stmt;
! 
! 	  stmt = bsi_stmt (bsi);
! 
! 	  if (TREE_CODE (stmt) != LABEL_EXPR)
  	    break;
  
! 	  if (prev_stmt && DECL_NONLOCAL (LABEL_EXPR_LABEL (stmt)))
! 	    {
! 	      error ("Nonlocal label %s in the middle of basic block bb %d",
! 		     IDENTIFIER_POINTER (DECL_NAME (LABEL_EXPR_LABEL (stmt))),
! 		     bb->index);
! 	      err = 1;
! 	    }
! 
! 	  if (label_to_block (LABEL_EXPR_LABEL (stmt)) != bb)
  	    {
  	      error ("Label %s to block does not match in bb %d\n",
  		     IDENTIFIER_POINTER (DECL_NAME (LABEL_EXPR_LABEL (stmt))),
  		     bb->index);
  	      err = 1;
  	    }
  
! 	  if (decl_function_context (LABEL_EXPR_LABEL (stmt))
  	      != current_function_decl)
  	    {
  	      error ("Label %s has incorrect context in bb %d\n",
  		     IDENTIFIER_POINTER (DECL_NAME (LABEL_EXPR_LABEL (stmt))),
  		     bb->index);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]