http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59719

            Bug ID: 59719
           Summary: Too much space allocated to unions containing variable
                    length arrays
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nickc at gcc dot gnu.org

Created attachment 31771
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31771&action=edit
test case to demonstrate the problem - effective on targets which use section
anchors

When gcc emits assembler directives to describe a union containing a variable
length array it tries to ensure that the end of the union is correctly aligned,
but it ends up emitting an incorrectly sized .zero pseudo-op. 

For example in the uploaded testcase, when compiled with an x86 toolchain, the
variable first_var_union is described in the assembler output as:

        .type   first_var_union, @object
        .size   first_var_union, 20
  first_var_union:
        .zero   4
        .string "12-octet-str"
        .zero   16

Note how the size of the variable is set to 20, but the actual size is
4+13+16=33 bytes.  Presumably the second .zero directive should have been
".zero 3".

This might just be a curiosity were it not for the fact that it makes any
following variables unaligned (unless the size of the union just happens to fir
into an alignment category).  Plus for targets which use section anchors (eg
aarch64, arm, ppc, mips), the computation of the offset to variables beyond the
variable length union will be based upon the expected size (20) not the real
size (33).

Reply via email to