]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c: Set attributes for fields when forming a composite type [PR117806]
authorMartin Uecker <uecker@tugraz.at>
Fri, 29 Nov 2024 16:04:36 +0000 (17:04 +0100)
committerMartin Uecker <uecker@gcc.gnu.org>
Sat, 30 Nov 2024 07:40:24 +0000 (08:40 +0100)
We need to call decl_attributes when creating the fields for a composite
type.

PR c/117806

gcc/c/ChangeLog:
* c-typeck.cc (composite_type_internal): Call decl_attributes.

gcc/testsuite/ChangeLog:
* gcc.dg/pr117806.c: New test.

gcc/c/c-typeck.cc
gcc/testsuite/gcc.dg/pr117806.c [new file with mode: 0644]

index 611daccb926d3042fe90f782a6b8186014126ce6..e60f89a21d99d09b0407323b398c1deb26c3365f 100644 (file)
@@ -791,6 +791,8 @@ composite_type_internal (tree t1, tree t2, struct composite_cache* cache)
              DECL_ATTRIBUTES (f) = DECL_ATTRIBUTES (a);
              C_DECL_VARIABLE_SIZE (f) = C_TYPE_VARIABLE_SIZE (t);
 
+             decl_attributes (&f, DECL_ATTRIBUTES (f), 0);
+
              finish_decl (f, input_location, NULL, NULL, NULL);
 
              if (DECL_C_BIT_FIELD (a))
diff --git a/gcc/testsuite/gcc.dg/pr117806.c b/gcc/testsuite/gcc.dg/pr117806.c
new file mode 100644 (file)
index 0000000..bc2c8c6
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-std=c23" } */
+
+struct Test {
+  double D __attribute__((packed,aligned(4)));
+} x;
+struct Test {
+  double D __attribute__((packed,aligned(4)));
+} x;
+struct Test {
+  double D __attribute__((packed,aligned(4)));
+} x;
+