Unreviewed patch (PR3952)

Richard Henderson rth@redhat.com
Fri Sep 14 17:11:00 GMT 2001


On Tue, Sep 11, 2001 at 08:56:39PM +0200, Franz Sirl wrote:
> < http://gcc.gnu.org/ml/gcc-patches/2001-08/msg01537.html >

The patch is incorrect.  The test decomposes to 

	extern char foo[0];
	char foo[1];

which ought to illicit an error (IMO, since zero-length arrays
are a gcc extension, but the standard does say that if both have
integer constant expressions, then both size specifiers shall 
have the same constant value (6.7.5.2/6)).

Note that this is not the same as

	extern char foo[];
	char foo[1];

which is valid.  I think a complete test case of the alternatives
would be

/* incomplete decl matches */
extern char arr0[];
char arr0[1];

/* two integral expressions must be the same */
extern char arr1[1];
char arr1[1];
extern char arr2[0];
char arr2[0];
extern char arr3[0];		/* { dg-error "previous declaration" } */
char arr3[1];			/* { dg-error "conflicting types" } */

/* variable size matches */
void func(int n, int arr[n]);
void func(int n, int arr[1]);

I have not extensively tested the following patch, but it appears
to do what's wanted.

Joseph, do you concur?


r~


Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-typeck.c,v
retrieving revision 1.136
diff -c -p -d -r1.136 c-typeck.c
*** c-typeck.c	2001/09/13 14:37:09	1.136
--- c-typeck.c	2001/09/15 00:02:36
*************** comptypes (type1, type2)
*** 505,510 ****
--- 505,512 ----
        {
  	tree d1 = TYPE_DOMAIN (t1);
  	tree d2 = TYPE_DOMAIN (t2);
+ 	bool d1_variable, d2_variable;
+ 	bool d1_zero, d2_zero;
  	val = 1;
  
  	/* Target types must match incl. qualifiers.  */
*************** comptypes (type1, type2)
*** 513,526 ****
  	  return 0;
  
  	/* Sizes must match unless one is missing or variable.  */
! 	if (d1 == 0 || d2 == 0 || d1 == d2
! 	    || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
! 	    || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
! 	    || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
! 	    || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
  	  break;
  
! 	if (! tree_int_cst_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2))
  	    || ! tree_int_cst_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2)))
  	  val = 0;
  
--- 515,539 ----
  	  return 0;
  
  	/* Sizes must match unless one is missing or variable.  */
! 	if (d1 == 0 || d2 == 0 || d1 == d2)
  	  break;
  
! 	d1_zero = ! TYPE_MAX_VALUE (d1);
! 	d2_zero = ! TYPE_MAX_VALUE (d2);
! 
! 	d1_variable = (! d1_zero
! 		       && (TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
! 			   || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST));
! 	d2_variable = (! d2_zero
! 		       && (TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
! 			   || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST));
! 
! 	if (d1_variable || d2_variable)
! 	  break;
! 	if (d1_zero && d2_zero)
! 	  break;
! 	if (d1_zero || d2_zero
! 	    || ! tree_int_cst_equal (TYPE_MIN_VALUE (d1), TYPE_MIN_VALUE (d2))
  	    || ! tree_int_cst_equal (TYPE_MAX_VALUE (d1), TYPE_MAX_VALUE (d2)))
  	  val = 0;
  



More information about the Gcc-patches mailing list