Blame SOURCES/gcc48-pr28865.patch

4dd737
2014-01-16  Nick Clifton  <nickc@redhat.com>
4dd737
4dd737
	PR middle-end/28865
4dd737
	* varasm.c (output_constant): Return the number of bytes actually
4dd737
	emitted.
4dd737
	(output_constructor_array_range): Update the field size with the
4dd737
	number of bytes emitted by output_constant.
4dd737
	(output_constructor_regular_field): Likewise.  Also do not
4dd737
	complain if the total number of bytes emitted is now greater
4dd737
	than the expected fieldpos.
4dd737
	* output.h (output_constant): Update prototype and descriptive
4dd737
	comment.
4dd737
4dd737
	* gcc.c-torture/compile/pr28865.c: New.
4dd737
	* gcc.c-torture/execute/pr28865.c: New.
4dd737
4dd737
--- gcc/varasm.c	(revision 206660)
4dd737
+++ gcc/varasm.c	(revision 206661)
4dd737
@@ -4474,8 +4474,10 @@ static unsigned HOST_WIDE_INT
4dd737
    This includes the pseudo-op such as ".int" or ".byte", and a newline.
4dd737
    Assumes output_addressed_constants has been done on EXP already.
4dd737
 
4dd737
-   Generate exactly SIZE bytes of assembler data, padding at the end
4dd737
-   with zeros if necessary.  SIZE must always be specified.
4dd737
+   Generate at least SIZE bytes of assembler data, padding at the end
4dd737
+   with zeros if necessary.  SIZE must always be specified.  The returned
4dd737
+   value is the actual number of bytes of assembler data generated, which
4dd737
+   may be bigger than SIZE if the object contains a variable length field.
4dd737
 
4dd737
    SIZE is important for structure constructors,
4dd737
    since trailing members may have been omitted from the constructor.
4dd737
@@ -4490,14 +4492,14 @@ static unsigned HOST_WIDE_INT
4dd737
 
4dd737
    ALIGN is the alignment of the data in bits.  */
4dd737
 
4dd737
-void
4dd737
+unsigned HOST_WIDE_INT
4dd737
 output_constant (tree exp, unsigned HOST_WIDE_INT size, unsigned int align)
4dd737
 {
4dd737
   enum tree_code code;
4dd737
   unsigned HOST_WIDE_INT thissize;
4dd737
 
4dd737
   if (size == 0 || flag_syntax_only)
4dd737
-    return;
4dd737
+    return size;
4dd737
 
4dd737
   /* See if we're trying to initialize a pointer in a non-default mode
4dd737
      to the address of some declaration somewhere.  If the target says
4dd737
@@ -4562,7 +4564,7 @@ output_constant (tree exp, unsigned HOST
4dd737
       && vec_safe_is_empty (CONSTRUCTOR_ELTS (exp)))
4dd737
     {
4dd737
       assemble_zeros (size);
4dd737
-      return;
4dd737
+      return size;
4dd737
     }
4dd737
 
4dd737
   if (TREE_CODE (exp) == FDESC_EXPR)
4dd737
@@ -4574,7 +4576,7 @@ output_constant (tree exp, unsigned HOST
4dd737
 #else
4dd737
       gcc_unreachable ();
4dd737
 #endif
4dd737
-      return;
4dd737
+      return size;
4dd737
     }
4dd737
 
4dd737
   /* Now output the underlying data.  If we've handling the padding, return.
4dd737
@@ -4612,8 +4614,7 @@ output_constant (tree exp, unsigned HOST
4dd737
       switch (TREE_CODE (exp))
4dd737
 	{
4dd737
 	case CONSTRUCTOR:
4dd737
-	    output_constructor (exp, size, align, NULL);
4dd737
-	  return;
4dd737
+	  return output_constructor (exp, size, align, NULL);
4dd737
 	case STRING_CST:
4dd737
 	  thissize = MIN ((unsigned HOST_WIDE_INT)TREE_STRING_LENGTH (exp),
4dd737
 			  size);
4dd737
@@ -4648,11 +4649,10 @@ output_constant (tree exp, unsigned HOST
4dd737
     case RECORD_TYPE:
4dd737
     case UNION_TYPE:
4dd737
       gcc_assert (TREE_CODE (exp) == CONSTRUCTOR);
4dd737
-      output_constructor (exp, size, align, NULL);
4dd737
-      return;
4dd737
+      return output_constructor (exp, size, align, NULL);
4dd737
 
4dd737
     case ERROR_MARK:
4dd737
-      return;
4dd737
+      return 0;
4dd737
 
4dd737
     default:
4dd737
       gcc_unreachable ();
4dd737
@@ -4660,6 +4660,8 @@ output_constant (tree exp, unsigned HOST
4dd737
 
4dd737
   if (size > thissize)
4dd737
     assemble_zeros (size - thissize);
4dd737
+
4dd737
+  return size;
4dd737
 }
4dd737
 
4dd737
 
4dd737
@@ -4759,7 +4761,7 @@ output_constructor_array_range (oc_local
4dd737
       if (local->val == NULL_TREE)
4dd737
 	assemble_zeros (fieldsize);
4dd737
       else
4dd737
-	output_constant (local->val, fieldsize, align2);
4dd737
+	fieldsize = output_constant (local->val, fieldsize, align2);
4dd737
 
4dd737
       /* Count its size.  */
4dd737
       local->total_bytes += fieldsize;
4dd737
@@ -4808,9 +4810,8 @@ output_constructor_regular_field (oc_loc
4dd737
      Note no alignment needed in an array, since that is guaranteed
4dd737
      if each element has the proper size.  */
4dd737
   if ((local->field != NULL_TREE || local->index != NULL_TREE)
4dd737
-      && fieldpos != local->total_bytes)
4dd737
+      && fieldpos > local->total_bytes)
4dd737
     {
4dd737
-      gcc_assert (fieldpos >= local->total_bytes);
4dd737
       assemble_zeros (fieldpos - local->total_bytes);
4dd737
       local->total_bytes = fieldpos;
4dd737
     }
4dd737
@@ -4847,7 +4848,7 @@ output_constructor_regular_field (oc_loc
4dd737
   if (local->val == NULL_TREE)
4dd737
     assemble_zeros (fieldsize);
4dd737
   else
4dd737
-    output_constant (local->val, fieldsize, align2);
4dd737
+    fieldsize = output_constant (local->val, fieldsize, align2);
4dd737
 
4dd737
   /* Count its size.  */
4dd737
   local->total_bytes += fieldsize;
4dd737
--- gcc/output.h	(revision 206660)
4dd737
+++ gcc/output.h	(revision 206661)
4dd737
@@ -294,11 +294,13 @@ extern void output_quoted_string (FILE *
4dd737
    This includes the pseudo-op such as ".int" or ".byte", and a newline.
4dd737
    Assumes output_addressed_constants has been done on EXP already.
4dd737
 
4dd737
-   Generate exactly SIZE bytes of assembler data, padding at the end
4dd737
-   with zeros if necessary.  SIZE must always be specified.
4dd737
+   Generate at least SIZE bytes of assembler data, padding at the end
4dd737
+   with zeros if necessary.  SIZE must always be specified.  The returned
4dd737
+   value is the actual number of bytes of assembler data generated, which
4dd737
+   may be bigger than SIZE if the object contains a variable length field.
4dd737
 
4dd737
    ALIGN is the alignment in bits that may be assumed for the data.  */
4dd737
-extern void output_constant (tree, unsigned HOST_WIDE_INT, unsigned int);
4dd737
+extern unsigned HOST_WIDE_INT output_constant (tree, unsigned HOST_WIDE_INT, unsigned int);
4dd737
 
4dd737
 /* When outputting delayed branch sequences, this rtx holds the
4dd737
    sequence being output.  It is null when no delayed branch
4dd737
--- gcc/testsuite/gcc.c-torture/execute/pr28865.c	(revision 0)
4dd737
+++ gcc/testsuite/gcc.c-torture/execute/pr28865.c	(revision 206661)
4dd737
@@ -0,0 +1,21 @@
4dd737
+struct A { int a; char b[]; };
4dd737
+union B { struct A a; char b[sizeof (struct A) + 31]; };
4dd737
+union B b = { { 1, "123456789012345678901234567890" } };
4dd737
+union B c = { { 2, "123456789012345678901234567890" } };
4dd737
+
4dd737
+__attribute__((noinline, noclone)) void
4dd737
+foo (int *x[2])
4dd737
+{
4dd737
+  x[0] = &b.a.a;
4dd737
+  x[1] = &c.a.a;
4dd737
+}
4dd737
+
4dd737
+int
4dd737
+main ()
4dd737
+{
4dd737
+  int *x[2];
4dd737
+  foo (x);
4dd737
+  if (*x[0] != 1 || *x[1] != 2)
4dd737
+    __builtin_abort ();
4dd737
+  return 0;
4dd737
+}
4dd737
--- gcc/testsuite/gcc.c-torture/compile/pr28865.c	(revision 0)
4dd737
+++ gcc/testsuite/gcc.c-torture/compile/pr28865.c	(revision 206661)
4dd737
@@ -0,0 +1,16 @@
4dd737
+struct var_len
4dd737
+{
4dd737
+  int field1;
4dd737
+  const char field2[];
4dd737
+};
4dd737
+
4dd737
+/* Note - strictly speaking this array declaration is illegal
4dd737
+   since each element has a variable length.  GCC allows it
4dd737
+   (for the moment) because it is used in existing code, such
4dd737
+   as glibc.  */
4dd737
+static const struct var_len var_array[] = 
4dd737
+{
4dd737
+  { 1, "Long exposure noise reduction" },
4dd737
+  { 2, "Shutter/AE lock buttons" },
4dd737
+  { 3, "Mirror lockup" }
4dd737
+};