https://gcc.gnu.org/g:a3989d8158705975ab72c9167469905cbe7d11cf

commit r14-11437-ga3989d8158705975ab72c9167469905cbe7d11cf
Author: Martin Uecker <uec...@tugraz.at>
Date:   Sat Mar 22 17:35:58 2025 +0100

    c: Set attributes for fields when forming a composite type [PR117806]
    
    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.
    
    (cherry picked from commit 1539bcd19c5928d8359722c532dfcc7a26a16dda)

Diff:
---
 gcc/c/c-typeck.cc               |  2 ++
 gcc/testsuite/gcc.dg/pr117806.c | 13 +++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 24cc4faa55fa..57d5ca586608 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -773,6 +773,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
index 000000000000..bc2c8c665e73
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr117806.c
@@ -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;
+

Reply via email to