https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69990

            Bug ID: 69990
           Summary: decl alignment not respected
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: amodra at gmail dot com
  Target Milestone: ---

The following testcase on powerpc64le-linux results in
/usr/local/powerpc64le-linux/bin/ld: pack.o: In function `main':
pack.c:(.text.startup+0x10): error: R_PPC64_TOC16_LO_DS not a multiple of 4
/usr/local/powerpc64le-linux/bin/ld: final link failed: Bad value


/* -O2 -fsection-anchors -ftree-loop-vectorize */

#pragma pack(1)
struct S0 {
  volatile int f0:12;
} static a[] = {{15}}, c[] = {{15}};

struct S0 b[] = {{7}};
int d;

int main(void)
{
  struct S0 *f[] = { c, (struct S0 *)&d };
  return __builtin_printf ("%x %x %x\n", a[0].f0, b[0].f0, f[0]->f0);
}


Breakpoint 1, offsettable_ok_by_alignment (mode=DImode, offset=0,
op=0x7ffff6db39a8) at /src/gcc.git/gcc/config/rs6000/rs6000.c:7109
(gdb) p debug_rtx(op)
(symbol_ref:DI ("a") [flags 0x2] <var_decl 0x7ffff7ff5990 a>)
$1 = void
(gdb) p debug_tree(decl)
 <var_decl 0x7ffff7ff5990 a
    type <array_type 0x7ffff6da3150
        type <record_type 0x7ffff6da3c78 S0 tree_2 type_0 HI
            size <integer_cst 0x7ffff6c26480 constant 16>
            unit size <integer_cst 0x7ffff6c26498 constant 2>
            align 8 symtab 0 alias set 1 canonical type 0x7ffff6da3c78 fields
<field_decl 0x7ffff6da8098 f0> context <translation_unit_decl 0x7ffff6d9f5a0
D.2852>
            pointer_to_this <pointer_type 0x7ffff6da3f18> chain <type_decl
0x7ffff6da8000 D.2840>>
        HI size <integer_cst 0x7ffff6c26480 16> unit size <integer_cst
0x7ffff6c26498 2>
        align 8 symtab 0 alias set 1 canonical type 0x7ffff6da3150
        domain <integer_type 0x7ffff6d7a1f8 type <integer_type 0x7ffff6c1d0a8
sizetype>
            DI
            size <integer_cst 0x7ffff6c262d0 constant 64>
            unit size <integer_cst 0x7ffff6c262e8 constant 8>
            align 64 symtab 0 alias set -1 canonical type 0x7ffff6d7a1f8
precision 64 min <integer_cst 0x7ffff6c26300 0> max <integer_cst 0x7ffff6c26300
0>>
        pointer_to_this <pointer_type 0x7ffff6da3498>>
    readonly used static HI file /src/tmp/ds_mem.c line 6 col 10 size
<integer_cst 0x7ffff6c26480 16> unit size <integer_cst 0x7ffff6c26498 2>
    user align 128 context <translation_unit_decl 0x7ffff6d9f5a0 D.2852>
    (mem/u/c:HI (symbol_ref:DI ("a") [flags 0x2] <var_decl 0x7ffff7ff5990 a>)
[1 a+0 S2 A128]) chain <var_decl 0x7ffff7ff5a20 c>>
$2 = void

So the alignment of "a" is reported as 128 bits, but in fact "a" is only 16 bit
aligned as seen below in extract from assembly file.

        .comm   d,4,4
        .globl b
        .set    a,c
        .section        ".data"
        .align 4
        .set    .LANCHOR0,. + 0
        .type   b, @object
        .size   b, 2
b:
        .byte   7
        .byte   0
        .type   c, @object
        .size   c, 2
c:
        .byte   15
        .byte   0

Reply via email to