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] don't complain too small an array component size if overflow


A recent check has been introduced in layout_type for array types, possibly
triggering

   error ("alignment of array elements is greater than element size");

This error shows up spuriously on the following Ada testcase, expected
to compile silently:

   procedure P is
      package Matrixes is
	 type Matrix_T is array (Integer, Integer) of Integer;
      end Matrixes;
   begin
      null;
   end;

This test builds an array[integer] of (array[integer] of integer)
type, without allocating any object of this type (which would raise
storage_error at run-time).

The inner size overflows and the error triggers because the code
doesn't check if TREE_CONSTANT_OVERFLOW is set on the component size
before comparing the value to the alignment.

The patch below addresses that by adding such a check.

Bootstrapped and reg tested on i686-pc-linux-gnu, configured with
--enable-languages=all,ada

Thanks in advance,

Olivier

2005-10-22  Olivier Hainque  <hainque@adacore.com>

	* stor-layout.c (layout_type): Don't complain about a too small
	an array element type size compared to its alignement when the
	size overflows.

--- stor-layout.c.ori	2005-10-18 09:57:15.000000000 +0200
+++ stor-layout.c	2005-10-21 16:10:52.000000000 +0200
@@ -1827,10 +1827,11 @@ layout_type (tree type)
 		TYPE_MODE (type) = BLKmode;
 	      }
 	  }
 	if (TYPE_SIZE_UNIT (element)
 	    && TREE_CODE (TYPE_SIZE_UNIT (element)) == INTEGER_CST
+	    && !TREE_CONSTANT_OVERFLOW (TYPE_SIZE_UNIT (element))
 	    && !integer_zerop (TYPE_SIZE_UNIT (element))
 	    && compare_tree_int (TYPE_SIZE_UNIT (element),
 			  	 TYPE_ALIGN_UNIT (element)) < 0)
 	  error ("alignment of array elements is greater than element size");
 	break;


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