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]

Re: [PATCH][RFC] Fix PR33724, fix PR19382 differently


On Wed, 10 Oct 2007, Richard Guenther wrote:

> On Wed, 10 Oct 2007, Eric Botcazou wrote:
> 
> > > PR33724 is about us generating two incompatible TYPE_POINTER_TO types
> > > to unsigned char.  The type-checking code doesn't really know which one
> > > to check against.  The different pointer-to types were introduced by
> > > the fix for PR19382.
> > 
> > Can't it simply allow both?
> 
> Unless I run into...
> 
> > 
> > > In the following patch there are two possible fixes/workarounds for
> > > the problem.  The first patch to tree.c arranges to put the
> > > ref-all pointer-to type last in the list of TYPE_POINTER_TO types
> > > (this is just a workaround, I think it is fundamentally bogus to have
> > > two incompatible pointer-to types). 
> > 
> > You even can have more than 2 if you change the mode.
> 
> ...this, I don't think this is the correct way to go.  But yes, I can also
> change the verifier to be more careful about the TYPE_POINTER_TO type
> it uses.

Which would be the following; testing in progress.

Richard.

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

	PR middle-end/33724
	* tree-cfg.c (one_pointer_to_useless_type_conversion_p): New function.
	(verify_gimple_expr): Use it to verify pointer-to types for
	ADDR_EXPRs.

	* gcc.dg/pr33724.c: New testcase.

Index: tree-cfg.c
===================================================================
*** tree-cfg.c	(revision 129199)
--- tree-cfg.c	(working copy)
*************** verify_gimple_reference (tree expr)
*** 3538,3543 ****
--- 3538,3561 ----
    return verify_gimple_min_lval (expr);
  }
  
+ /* Returns true if there is one pointer type in TYPE_POINTER_TO (SRC_OBJ)
+    list of pointer-to types that is trivially convertible to DEST.  */
+ 
+ static bool
+ one_pointer_to_useless_type_conversion_p (tree dest, tree src_obj)
+ {
+   tree src;
+ 
+   if (!TYPE_POINTER_TO (src_obj))
+     return true;
+ 
+   for (src = TYPE_POINTER_TO (src_obj); src; src = TYPE_NEXT_PTR_TO (src))
+     if (useless_type_conversion_p (dest, src))
+       return true;
+ 
+   return false;
+ }
+ 
  /* Verify the GIMPLE expression EXPR.  Returns true if there is an
     error, otherwise false.  */
  
*************** verify_gimple_expr (tree expr)
*** 3773,3786 ****
  	    error ("invalid operand in unary expression");
  	    return true;
  	  }
! 	if (TYPE_POINTER_TO (TREE_TYPE (op))
! 	    && !useless_type_conversion_p (type,
! 					   TYPE_POINTER_TO (TREE_TYPE (op)))
  	    /* FIXME: a longstanding wart, &a == &a[0].  */
  	    && (TREE_CODE (TREE_TYPE (op)) != ARRAY_TYPE
! 		|| (TYPE_POINTER_TO (TREE_TYPE (TREE_TYPE (op)))
! 		    && !useless_type_conversion_p (type,
! 			  TYPE_POINTER_TO (TREE_TYPE (TREE_TYPE (op)))))))
  	  {
  	    error ("type mismatch in address expression");
  	    debug_generic_stmt (TREE_TYPE (expr));
--- 3791,3801 ----
  	    error ("invalid operand in unary expression");
  	    return true;
  	  }
! 	if (!one_pointer_to_useless_type_conversion_p (type, TREE_TYPE (op))
  	    /* FIXME: a longstanding wart, &a == &a[0].  */
  	    && (TREE_CODE (TREE_TYPE (op)) != ARRAY_TYPE
! 		|| !one_pointer_to_useless_type_conversion_p (type,
! 		      TREE_TYPE (TREE_TYPE (op)))))
  	  {
  	    error ("type mismatch in address expression");
  	    debug_generic_stmt (TREE_TYPE (expr));
Index: testsuite/gcc.dg/pr33724.c
===================================================================
*** testsuite/gcc.dg/pr33724.c	(revision 0)
--- testsuite/gcc.dg/pr33724.c	(revision 0)
***************
*** 0 ****
--- 1,20 ----
+ /* { dg-do compile } */
+ 
+ /* We ICEd with type-checking enabled.  */
+ 
+ struct xt_entry_target {
+   char name[1];
+ };
+ struct ipt_entry {
+   unsigned char elems[1];
+ };
+ void match_different(const unsigned char *);
+ int dump_entry(struct xt_entry_target *t)
+ {
+   return __builtin_strcmp (t->name, "");
+ }
+ void is_same(const struct ipt_entry *a)
+ {
+   match_different(a->elems);
+ }
+ 


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