Blame SOURCES/gcc48-pr28865.patch

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