[C] c: Set attributes for fields when forming a composite type [PR117806]

Message ID f289a6648182a44d78bbd3e49e517e59752352bf.camel@tugraz.at
State Committed
Commit 1539bcd19c5928d8359722c532dfcc7a26a16dda
Headers
Series [C] c: Set attributes for fields when forming a composite type [PR117806] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 fail Patch failed to apply

Commit Message

Martin Uecker Nov. 29, 2024, 4:15 p.m. UTC
  It seems we also miss a decl_attributes call for the fields
when building the composite type.


Bootstrapped and regression tested on x86_64.


    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.
  

Comments

Joseph Myers Nov. 29, 2024, 7:14 p.m. UTC | #1
On Fri, 29 Nov 2024, Martin Uecker wrote:

> It seems we also miss a decl_attributes call for the fields
> when building the composite type.
> 
> 
> Bootstrapped and regression tested on x86_64.
> 
> 
>     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.

OK.
  

Patch

diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 611daccb926..e60f89a21d9 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -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
index 00000000000..bc2c8c665e7
--- /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;
+