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] Fix PR33641, error in the type verifier


This fixes the type verifier to not assert that for POINTER_PLUS_EXPR
we have a op1 of INTEGER_TYPE.  Instead it is good enough to assert
that op1 is trivially convertible to sizetype.

We also now ICE if type verification errors occured instead of just
emitting errors.

Bootstrapped and tested on x86_64-unknown-linux-gnu for all languages,
applied to mainline.

Richard.

2007-10-04  Richard Guenther  <rguenther@suse.de>

	PR middle-end/33641
	* tree-cfg.c (verify_gimple_expr): Operand one of POINTER_PLUS_EXPR
	does not need to be of INTEGER_TYPE.
	(verify_gimple_2): New function split out from ...
	(verify_gimple_1): ... here.  ICE if there was an error during
	verification.

	* gcc.c-torture/compile/pr33641.c: New testcase.

Index: tree-cfg.c
===================================================================
*** tree-cfg.c	(revision 129003)
--- tree-cfg.c	(working copy)
*************** verify_gimple_expr (tree expr)
*** 3724,3730 ****
  	    return true;
  	  }
  	if (!POINTER_TYPE_P (TREE_TYPE (op0))
- 	    || TREE_CODE (TREE_TYPE (op1)) != INTEGER_TYPE
  	    || !useless_type_conversion_p (type, TREE_TYPE (op0))
  	    || !useless_type_conversion_p (sizetype, TREE_TYPE (op1)))
  	  {
--- 3724,3729 ----
*************** verify_gimple_stmt (tree stmt)
*** 4023,4034 ****
      }
  }
  
! /* Verify the GIMPLE statements inside the statement list STMTS.  */
  
! void
! verify_gimple_1 (tree stmts)
  {
    tree_stmt_iterator tsi;
  
    for (tsi = tsi_start (stmts); !tsi_end_p (tsi); tsi_next (&tsi))
      {
--- 4022,4035 ----
      }
  }
  
! /* Verify the GIMPLE statements inside the statement list STMTS.
!    Returns true if there were any errors.  */
  
! static bool
! verify_gimple_2 (tree stmts)
  {
    tree_stmt_iterator tsi;
+   bool err = false;
  
    for (tsi = tsi_start (stmts); !tsi_end_p (tsi); tsi_next (&tsi))
      {
*************** verify_gimple_1 (tree stmts)
*** 4037,4064 ****
        switch (TREE_CODE (stmt))
  	{
  	case BIND_EXPR:
! 	  verify_gimple_1 (BIND_EXPR_BODY (stmt));
  	  break;
  
  	case TRY_CATCH_EXPR:
  	case TRY_FINALLY_EXPR:
! 	  verify_gimple_1 (TREE_OPERAND (stmt, 0));
! 	  verify_gimple_1 (TREE_OPERAND (stmt, 1));
  	  break;
  
  	case CATCH_EXPR:
! 	  verify_gimple_1 (CATCH_BODY (stmt));
  	  break;
  
  	case EH_FILTER_EXPR:
! 	  verify_gimple_1 (EH_FILTER_FAILURE (stmt));
  	  break;
  
  	default:
! 	  if (verify_gimple_stmt (stmt))
! 	    debug_generic_expr (stmt);
  	}
      }
  }
  
  /* Verify the GIMPLE statements inside the current function.  */
--- 4038,4081 ----
        switch (TREE_CODE (stmt))
  	{
  	case BIND_EXPR:
! 	  err |= verify_gimple_2 (BIND_EXPR_BODY (stmt));
  	  break;
  
  	case TRY_CATCH_EXPR:
  	case TRY_FINALLY_EXPR:
! 	  err |= verify_gimple_2 (TREE_OPERAND (stmt, 0));
! 	  err |= verify_gimple_2 (TREE_OPERAND (stmt, 1));
  	  break;
  
  	case CATCH_EXPR:
! 	  err |= verify_gimple_2 (CATCH_BODY (stmt));
  	  break;
  
  	case EH_FILTER_EXPR:
! 	  err |= verify_gimple_2 (EH_FILTER_FAILURE (stmt));
  	  break;
  
  	default:
! 	  {
! 	    bool err2 = verify_gimple_stmt (stmt);
! 	    if (err2)
! 	      debug_generic_expr (stmt);
! 	    err |= err2;
! 	  }
  	}
      }
+ 
+   return err;
+ }
+ 
+ 
+ /* Verify the GIMPLE statements inside the statement list STMTS.  */
+ 
+ void
+ verify_gimple_1 (tree stmts)
+ {
+   if (verify_gimple_2 (stmts))
+     internal_error ("verify_gimple failed");
  }
  
  /* Verify the GIMPLE statements inside the current function.  */
Index: testsuite/gcc.c-torture/compile/pr33641.c
===================================================================
*** testsuite/gcc.c-torture/compile/pr33641.c	(revision 0)
--- testsuite/gcc.c-torture/compile/pr33641.c	(revision 0)
***************
*** 0 ****
--- 1,12 ----
+ /* This failed with type checking enabled.  */
+ 
+ typedef enum { one, two } exp;
+ extern exp pe;
+ extern char pt[256];
+ void psd (void (*f) (void *), void *p);
+ static void rle (void *e) { }
+ void
+ foo (void)
+ {
+   psd ((void (*)(void *)) (rle), (void *) (pt + pe));
+ }


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