public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111086] New: Possibly incorrect warning: arm-none-eabi-gcc:packed attribute causes inefficient alignment for <field>
@ 2023-08-21  4:42 tonyjosinew at gmail dot com
  2023-08-21  5:13 ` [Bug c/111086] " pinskia at gcc dot gnu.org
  2023-08-21  6:01 ` tonyjosinew at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: tonyjosinew at gmail dot com @ 2023-08-21  4:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111086
           Summary: Possibly incorrect warning: arm-none-eabi-gcc:packed
                    attribute causes inefficient alignment for <field>
           Product: gcc
           Version: 9.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tonyjosinew at gmail dot com
  Target Milestone: ---

Toolchain and compilation info
------------------------------

The exact version of GCC, the system type:

arm-none-eabi-gcc (15:9-2019-q4-0ubuntu1) 9.2.1 20191025 (release)
[ARM/arm-9-branch revision 277599]


The options given when GCC was configured/built:

-c -Wpacked


The complete command line that triggers the bug:

arm-none-eabi-gcc test.c -c -Wpacked

The compiler output (error messages, warnings, etc.);

test.c:22:14: warning: packed attribute causes inefficient alignment for 'ch1'
[-Wattributes]
   22 |     uint32_t ch1;
      |              ^~~
test.c:23:14: warning: packed attribute causes inefficient alignment for 'ch2'
[-Wattributes]
   23 |     uint16_t ch2;
      |              ^~~

Description:
------------
When the following struct is compiled in the above listed compiler:

struct Struct_test 
{
    uint32_t ch1;
    uint16_t ch2;
    uint32_t ch3;
}
__attribute__( ( packed ) );

this "warning: packed attribute causes inefficient alignment for <struct field
name>" is triggered. 

As per the manual -Wpacked means: Warn when the packed attribute has no effect
on struct layout. But in this case the packed attribute does have an impact on
the struct layout as it removes the padding between ch2 and ch3, but still it
causes a warning. Though the warning is listed as associated with:
-Wattributes. It doesn't show up if -Wpacked is not given as a compile option.

Is this a valid warning? I'm not fully sure what is meant by the warning, from
the looks of it seems like the compiler is trying to warn that with the packed
attribute the fields that are aligned relative to the struct can be aligned
inefficiently as the alignment of the entire struct is now 1 because of
packing.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/111086] Possibly incorrect warning: arm-none-eabi-gcc:packed attribute causes inefficient alignment for <field>
  2023-08-21  4:42 [Bug c/111086] New: Possibly incorrect warning: arm-none-eabi-gcc:packed attribute causes inefficient alignment for <field> tonyjosinew at gmail dot com
@ 2023-08-21  5:13 ` pinskia at gcc dot gnu.org
  2023-08-21  6:01 ` tonyjosinew at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-21  5:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
              if (STRICT_ALIGNMENT)
                warning (OPT_Wpacked, "packed attribute causes inefficient "
                         "alignment for %qE", name);
              else
                warning (OPT_Wpacked,
                         "packed attribute is unnecessary for %qE", name);


The warning is happening because arm is a strict alignment target that means
the target will not do a hardware unaligned load and will require load byte by
byte.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/111086] Possibly incorrect warning: arm-none-eabi-gcc:packed attribute causes inefficient alignment for <field>
  2023-08-21  4:42 [Bug c/111086] New: Possibly incorrect warning: arm-none-eabi-gcc:packed attribute causes inefficient alignment for <field> tonyjosinew at gmail dot com
  2023-08-21  5:13 ` [Bug c/111086] " pinskia at gcc dot gnu.org
@ 2023-08-21  6:01 ` tonyjosinew at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: tonyjosinew at gmail dot com @ 2023-08-21  6:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Tony Josi <tonyjosinew at gmail dot com> ---
In that case I think the warning should be generated for all the fields in the
struct, why just the first 2 fields (ch1 and ch2 in the example struct in the
bug report)?


Also the warning is listed under [-Wattributes], as it is triggered only if
-Wpacked is added, I would expect it to be listed with [-Wpacked].


It might be also a good idea to modify the help/man page of the -Wpacked to
include about this warning if its a valid one, because currently the
documentation of -Wpacked only talks about effects on struct layout.

Thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-08-21  6:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-21  4:42 [Bug c/111086] New: Possibly incorrect warning: arm-none-eabi-gcc:packed attribute causes inefficient alignment for <field> tonyjosinew at gmail dot com
2023-08-21  5:13 ` [Bug c/111086] " pinskia at gcc dot gnu.org
2023-08-21  6:01 ` tonyjosinew at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).