Bug 59719 - Too much space allocated to unions containing variable length arrays
Summary: Too much space allocated to unions containing variable length arrays
Status: RESOLVED DUPLICATE of bug 28865
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-08 12:01 UTC by Nick Clifton
Modified: 2014-01-09 19:34 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
test case to demonstrate the problem - effective on targets which use section anchors (721 bytes, text/x-csrc)
2014-01-08 12:01 UTC, Nick Clifton
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Clifton 2014-01-08 12:01:21 UTC
Created attachment 31771 [details]
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).
Comment 1 Mikael Pettersson 2014-01-08 12:44:12 UTC
Related to / dup of PR28865 and PR57180 ?
Comment 2 Jakub Jelinek 2014-01-09 19:34:33 UTC
Dup.

*** This bug has been marked as a duplicate of bug 28865 ***