]> git.ipfire.org Git - thirdparty/gcc.git/commit
d: Fix error with -Warray-bounds and -O2 [PR117002]
authorIain Buclaw <ibuclaw@gdcproject.org>
Sat, 29 Mar 2025 22:16:25 +0000 (23:16 +0100)
committerIain Buclaw <ibuclaw@gdcproject.org>
Mon, 31 Mar 2025 17:15:33 +0000 (19:15 +0200)
commit9fadadbbbc2b5352e5e70e0e1a9be9b447176913
tree546f373331a3244509cea1c232f2393d2ad72d27
parentb9adf3a4c8112df1d74440157f578a8344ebe166
d: Fix error with -Warray-bounds and -O2 [PR117002]

The record layout of class types in D don't get any tail padding, so it
is possible for the `classInstanceSize' to not be a multiple of the
`classInstanceAlignment'.

Rather than setting the instance alignment on the underlying
RECORD_TYPE, instead give the type an alignment of 1, which will mark it
as TYPE_PACKED.  The value of `classInstanceAlignment' is instead
applied to the DECL_ALIGN of both the static `init' symbol, and the
stack allocated variable used when generating `new' for a `scope' class.

PR d/117002

gcc/d/ChangeLog:

* decl.cc (aggregate_initializer_decl): Set explicit decl alignment of
class instance.
* expr.cc (ExprVisitor::visit (NewExp *)): Likewise.
* types.cc (TypeVisitor::visit (TypeClass *)): Mark the record type of
classes as packed.

gcc/testsuite/ChangeLog:

* gdc.dg/torture/pr117002.d: New test.
gcc/d/decl.cc
gcc/d/expr.cc
gcc/d/types.cc
gcc/testsuite/gdc.dg/torture/pr117002.d [new file with mode: 0644]