Blame SOURCES/gcc48-pr28865.patch

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