> Am 02.06.2023 um 21:12 schrieb Iain Sandoe via Gcc-patches > <gcc-patches@gcc.gnu.org>: > > @David: I am not sure what sets the ABI on AIX (for Darwin, it is effectively > "whatever the system compiler [Apple gcc-4] does") but from an inspection of > the code, it seems that (if the platform should honour #pragma pack) a similar > effect could be present there too. > > Tested on powerpc-apple-darwin9, powerpc64-linux-gnu and on i686 and x86_64 > Darwin. Checked that the testcases also pass for Apple gcc-4.2.1. > pushed to trunk, thanks > Iain > > --- 8< --- > > This bug was essentially that darwin_rs6000_special_round_type_align() > was ignoring externally-imposed capping of field alignment. > > Signed-off-by: Iain Sandoe <i...@sandoe.co.uk> > > PR target/110044 > > gcc/ChangeLog: > > * config/rs6000/rs6000.cc (darwin_rs6000_special_round_type_align): > Make sure that we do not have a cap on field alignment before altering > the struct layout based on the type alignment of the first entry. > > gcc/testsuite/ChangeLog: > > * gcc.target/powerpc/darwin-abi-13-0.c: New test. > * gcc.target/powerpc/darwin-abi-13-1.c: New test. > * gcc.target/powerpc/darwin-abi-13-2.c: New test. > * gcc.target/powerpc/darwin-structs-0.h: New test. > --- > gcc/config/rs6000/rs6000.cc | 3 +- > .../gcc.target/powerpc/darwin-abi-13-0.c | 23 +++++++++++++++ > .../gcc.target/powerpc/darwin-abi-13-1.c | 27 +++++++++++++++++ > .../gcc.target/powerpc/darwin-abi-13-2.c | 27 +++++++++++++++++ > .../gcc.target/powerpc/darwin-structs-0.h | 29 +++++++++++++++++++ > 5 files changed, 108 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/gcc.target/powerpc/darwin-abi-13-0.c > create mode 100644 gcc/testsuite/gcc.target/powerpc/darwin-abi-13-1.c > create mode 100644 gcc/testsuite/gcc.target/powerpc/darwin-abi-13-2.c > create mode 100644 gcc/testsuite/gcc.target/powerpc/darwin-structs-0.h > > diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc > index 5b3b8b52e7e..42f49e4a56b 100644 > --- a/gcc/config/rs6000/rs6000.cc > +++ b/gcc/config/rs6000/rs6000.cc > @@ -8209,7 +8209,8 @@ darwin_rs6000_special_round_type_align (tree type, > unsigned int computed, > type = TREE_TYPE (type); > } while (AGGREGATE_TYPE_P (type)); > > - if (! AGGREGATE_TYPE_P (type) && type != error_mark_node) > + if (type != error_mark_node && ! AGGREGATE_TYPE_P (type) > + && ! TYPE_PACKED (type) && maximum_field_alignment == 0) Just noticed while browsing mail. ‚Maximum_field_alignment‘ sounds like Something that should be factored in when Computing align but as written there’s no adjustment done instead? Is there a way to get that to more than BITS_PER_UNIT? > align = MAX (align, TYPE_ALIGN (type)); > > return align; > diff --git a/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-0.c > b/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-0.c > new file mode 100644 > index 00000000000..d8d3c63a083 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-0.c > @@ -0,0 +1,23 @@ > +/* { dg-do compile { target powerpc*-*-darwin* } } */ > +/* { dg-require-effective-target ilp32 } */ > +/* { dg-options "-Wno-long-long" } */ > + > +#include "darwin-structs-0.h" > + > +int tcd[sizeof(cd) != 12 ? -1 : 1]; > +int acd[__alignof__(cd) != 4 ? -1 : 1]; > + > +int sdc[sizeof(dc) != 16 ? -1 : 1]; > +int adc[__alignof__(dc) != 8 ? -1 : 1]; > + > +int scL[sizeof(cL) != 12 ? -1 : 1]; > +int acL[__alignof__(cL) != 4 ? -1 : 1]; > + > +int sLc[sizeof(Lc) != 16 ? -1 : 1]; > +int aLc[__alignof__(Lc) != 8 ? -1 : 1]; > + > +int scD[sizeof(cD) != 32 ? -1 : 1]; > +int acD[__alignof__(cD) != 16 ? -1 : 1]; > + > +int sDc[sizeof(Dc) != 32 ? -1 : 1]; > +int aDc[__alignof__(Dc) != 16 ? -1 : 1]; > diff --git a/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-1.c > b/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-1.c > new file mode 100644 > index 00000000000..4d888d383fa > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-1.c > @@ -0,0 +1,27 @@ > +/* { dg-do compile { target powerpc*-*-darwin* } } */ > +/* { dg-require-effective-target ilp32 } */ > +/* { dg-options "-Wno-long-long" } */ > + > +#pragma pack(push, 1) > + > +#include "darwin-structs-0.h" > + > +int tcd[sizeof(cd) != 9 ? -1 : 1]; > +int acd[__alignof__(cd) != 1 ? -1 : 1]; > + > +int sdc[sizeof(dc) != 9 ? -1 : 1]; > +int adc[__alignof__(dc) != 1 ? -1 : 1]; > + > +int scL[sizeof(cL) != 9 ? -1 : 1]; > +int acL[__alignof__(cL) != 1 ? -1 : 1]; > + > +int sLc[sizeof(Lc) != 9 ? -1 : 1]; > +int aLc[__alignof__(Lc) != 1 ? -1 : 1]; > + > +int scD[sizeof(cD) != 17 ? -1 : 1]; > +int acD[__alignof__(cD) != 1 ? -1 : 1]; > + > +int sDc[sizeof(Dc) != 17 ? -1 : 1]; > +int aDc[__alignof__(Dc) != 1 ? -1 : 1]; > + > +#pragma pack(pop) > diff --git a/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-2.c > b/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-2.c > new file mode 100644 > index 00000000000..3bd52c0a8f8 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/darwin-abi-13-2.c > @@ -0,0 +1,27 @@ > +/* { dg-do compile { target powerpc*-*-darwin* } } */ > +/* { dg-require-effective-target ilp32 } */ > +/* { dg-options "-Wno-long-long" } */ > + > +#pragma pack(push, 2) > + > +#include "darwin-structs-0.h" > + > +int tcd[sizeof(cd) != 10 ? -1 : 1]; > +int acd[__alignof__(cd) != 2 ? -1 : 1]; > + > +int sdc[sizeof(dc) != 10 ? -1 : 1]; > +int adc[__alignof__(dc) != 2 ? -1 : 1]; > + > +int scL[sizeof(cL) != 10 ? -1 : 1]; > +int acL[__alignof__(cL) != 2 ? -1 : 1]; > + > +int sLc[sizeof(Lc) != 10 ? -1 : 1]; > +int aLc[__alignof__(Lc) != 2 ? -1 : 1]; > + > +int scD[sizeof(cD) != 18 ? -1 : 1]; > +int acD[__alignof__(cD) != 2 ? -1 : 1]; > + > +int sDc[sizeof(Dc) != 18 ? -1 : 1]; > +int aDc[__alignof__(Dc) != 2 ? -1 : 1]; > + > +#pragma pack(pop) > diff --git a/gcc/testsuite/gcc.target/powerpc/darwin-structs-0.h > b/gcc/testsuite/gcc.target/powerpc/darwin-structs-0.h > new file mode 100644 > index 00000000000..1db44f7a808 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/darwin-structs-0.h > @@ -0,0 +1,29 @@ > +typedef struct _cd { > + char c; > + double d; > +} cd; > + > +typedef struct _dc { > + double d; > + char c; > +} dc; > + > +typedef struct _cL { > + char c; > + long long L; > +} cL; > + > +typedef struct _Lc { > + long long L; > + char c; > +} Lc; > + > +typedef struct _cD { > + char c; > + long double D; > +} cD; > + > +typedef struct _Dc { > + long double D; > + char c; > +} Dc; > -- > 2.39.2 (Apple Git-143) >
Re: [pushed] Darwin, PPC: Fix struct layout with pragma pack [PR110044].
Richard Biener via Gcc-patches Sat, 03 Jun 2023 04:20:47 -0700
- [pushed] Darwin, PPC: Fix struct layout wit... Iain Sandoe via Gcc-patches
- Re: [pushed] Darwin, PPC: Fix struct l... Richard Biener via Gcc-patches
- Re: [pushed] Darwin, PPC: Fix stru... Iain Sandoe