https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124003

            Bug ID: 124003
           Summary: Using an aligned attribute in a typedef used for a
                    field is not the same as indicating the attribute on
                    the type of the field
           Product: gcc
           Version: 15.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: [email protected]
  Target Milestone: ---

Created attachment 63608
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63608&action=edit
Sample file reproducing the problem

First of all, we are not sure that this is a bug. We found it while trying to
replicate the behavior of GCC in an analyzer for C.

The sample file is attached.

The result that we get is:

field_t  : size 2 -- align 1
struct S1: size 3 -- align 1
struct S2: size 4 -- align 2
struct S3: size 3 -- align 1

We would have expected to be either:

field_t  : size 2 -- align 1
struct S1: size 3 -- align 1
struct S2: size 3 -- align 1
struct S3: size 3 -- align 1

or (even if it would be still surprising) :

field_t  : size 2 -- align 1
struct S1: size 4 -- align 2
struct S2: size 4 -- align 2
struct S3: size 3 -- align 1

It seems like when using an attribute in a typedef, if we use it for the type
of a field, the attribute is attached to the field instead of being attached to
the type, which is surprising.

Is it expected? If so, can someone explain the semantics of this code?

I found two issues that may be related, but I am not sure that it is the same:
- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109824
- https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46354

Reply via email to