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