================
@@ -431,3 +431,43 @@ int g = sizeof(G);
// CHECK-NEXT: | nvsize=20, nvalign=2, preferrednvalign=2]
} // namespace test11
+namespace test12 {
+// Fields whose base element is `double`/`long double` test their natural
+// 8-byte alignment under __ms_struct__.
+// See: issue 219627.
+struct __attribute__((__ms_struct__)) S { double d; };
+int a = sizeof(S);
+
+struct __attribute__((__ms_struct__)) LD { long double d; };
+int b = sizeof(LD);
+
+struct __attribute__((__ms_struct__)) CD { _Complex double d; };
+int c = sizeof(CD);
+
+struct __attribute__((__ms_struct__)) Arr { double d[4]; };
+int e = sizeof(Arr);
+
+// CHECK: *** Dumping AST Record Layout
+// CHECK-NEXT: 0 | struct test12::S
+// CHECK-NEXT: 0 | double d
+// CHECK-NEXT: | [sizeof=8, dsize=8, align=8, preferredalign=8,
+// CHECK-NEXT: | nvsize=8, nvalign=8, preferrednvalign=8]
----------------
hubert-reinterpretcast wrote:
That is not the expected behaviour if we are meant to be GCC-compatible (note
that `struct A` has a four-byte alignment requirement and is placed as such
within `struct B`, which is not marked `ms_struct`):
```console
$ ( set -x ; cat msstruct.c && gcc -std=c2x -Wall -Wextra -pedantic
-fsyntax-only msstruct.c && gcc -v )
+ cat msstruct.c
typedef struct [[gnu::ms_struct]] A { double d; } A;
typedef struct B { char c; A a; } B;
static_assert(alignof(A) == 4);
static_assert(__builtin_offsetof(B, a) == 4);
+ gcc -std=c2x -Wall -Wextra -pedantic -fsyntax-only msstruct.c
+ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/freeware/libexec/gcc/powerpc-ibm-aix7.2.0.0/13/lto-wrapper
Target: powerpc-ibm-aix7.2.0.0
Configured with: ../gcc-13.3.0/configure --prefix=/opt/freeware
--mandir=/opt/freeware/man --infodir=/opt/freeware/info
--with-local-prefix=/opt/freeware --enable-languages=c,c++,fortran,go
--enable-version-specific-runtime-libs --disable-nls --disable-libstdcxx-pch
--disable-werror --enable-libstdcxx-filesystem-ts --with-gcc-major-version-only
--program-suffix=-13 --with-cpu=default32 --host=powerpc-ibm-aix7.2.0.0
--with-libiconv-prefix=/opt/freeware/libiconv_static
--with-libiconv-type=static --with-included-gettext
Thread model: aix
Supported LTO compression algorithms: zlib zstd
gcc version 13.3.0 (GCC)
```
The assertion failure is a more honest reflection of the status quo that Clang
does not implement intentional semantics for such cases:
https://godbolt.org/z/rW58E6xK8
The documentation on this aspect is rather sparse. It appears that this
attribute, in effect, selects between `-mms-bitfields` and `-mno-ms-bitfields`:
- https://clang.llvm.org/docs/AttributeReference.html#gcc-struct-ms-struct
-
https://gcc.gnu.org/onlinedocs/gcc/PowerPC-Attributes.html#index-ms_005fstruct_002c-PowerPC
-
https://gcc.gnu.org/onlinedocs/gcc/x86-Attributes.html#index-ms_005fstruct_002c-x86
The GCC documentation creates no impression that `-m[no-]ms-bitfields` modifies
behaviour on the Power-versus-natural-alignment axis:
- https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html#index-mno-ms-bitfields
The Clang documentation is thin and rather vague:
- https://clang.llvm.org/docs/ClangCommandLineReference.html
https://github.com/llvm/llvm-project/pull/219661
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits