public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105125] New: Bogus and Misleading Warning: Packed attribute is unnecessary.
@ 2022-04-01 13:34 Kimon.Hoffmann at lawo dot com
2022-04-01 13:41 ` [Bug c++/105125] " Kimon.Hoffmann at lawo dot com
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Kimon.Hoffmann at lawo dot com @ 2022-04-01 13:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105125
Bug ID: 105125
Summary: Bogus and Misleading Warning: Packed attribute is
unnecessary.
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Kimon.Hoffmann at lawo dot com
Target Milestone: ---
GCC erroneously declares a packed attribute on a struct member as unnecessary,
while it clearly isn't.
Reproducer:
---------- 8< ----------
#include <cstdint>
struct A
{
std::uint32_t i;
};
struct B
{
std::uint64_t i;
};
struct C
{
A a;
B b;
};
struct D
{
A a [[gnu::packed]];
B b;
};
struct E
{
A a;
B b [[gnu::packed]];
};
struct F
{
B b [[gnu::packed]];
A a;
};
static_assert((sizeof(A) == 4) && (alignof(A) == 4));
static_assert((sizeof(B) == 8) && (alignof(B) == 8));
static_assert((sizeof(C) == 16) && (alignof(C) == 8));
static_assert((sizeof(D) == 16) && (alignof(D) == 8));
static_assert((sizeof(E) == 12) && (alignof(E) == 4));
static_assert((sizeof(F) == 12) && (alignof(F) == 4));
---------- >8 ----------
Invocation: cat test.cpp | x86_64-linux-gnu-g++ -xc++ -std=c++17 -Wpacked -c -o
/dev/null -
Observed behavior:
<stdin>:21:7: warning: packed attribute is unnecessary for ‘D::a’
[-Wattributes]
<stdin>:33:7: warning: packed attribute is unnecessary for ‘F::b’
[-Wattributes]
Expected behaviur:
While the warning referring to line 21 is correct, the warning referring to
line 33 isn't, and thus no message is expected.
Please note that this report describes the same behavior as report #59220, but
is more generally applicable, as the aforementioned report uses an explicitly
overaligned type, and might thus give the false impression that overalignment
is a required prerequisite for the issue to.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/105125] Bogus and Misleading Warning: Packed attribute is unnecessary.
2022-04-01 13:34 [Bug c++/105125] New: Bogus and Misleading Warning: Packed attribute is unnecessary Kimon.Hoffmann at lawo dot com
@ 2022-04-01 13:41 ` Kimon.Hoffmann at lawo dot com
2022-11-29 1:06 ` [Bug middle-end/105125] " pinskia at gcc dot gnu.org
2022-11-29 1:12 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: Kimon.Hoffmann at lawo dot com @ 2022-04-01 13:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105125
Kimon.Hoffmann at lawo dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail| |10.1.0, 11.1.0, 11.2.0,
| |5.1.0, 6.1.0, 7.1.0, 8.1.0,
| |9.1.0
--- Comment #1 from Kimon.Hoffmann at lawo dot com ---
I checked the behavior with each major version since version 5, using the x.1.0
version as the representative, and can confirm that the issue is present in all
versions checked.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/105125] Bogus and Misleading Warning: Packed attribute is unnecessary.
2022-04-01 13:34 [Bug c++/105125] New: Bogus and Misleading Warning: Packed attribute is unnecessary Kimon.Hoffmann at lawo dot com
2022-04-01 13:41 ` [Bug c++/105125] " Kimon.Hoffmann at lawo dot com
@ 2022-11-29 1:06 ` pinskia at gcc dot gnu.org
2022-11-29 1:12 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-29 1:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105125
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|c++ |middle-end
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
C testcase (moved over the GNU style attributes from C23 attributes though):
```
#include <stdint.h>
#define static_assert _Static_assert
#define alignof _Alignof
struct A
{
uint32_t i;
};
struct B
{
uint64_t i;
};
struct C
{
struct A a;
struct B b;
};
struct D
{
struct A a __attribute__((packed));
struct B b;
};
struct E
{
struct A a;
struct B b __attribute__((packed));
};
struct F
{
struct B b __attribute__((packed));
struct A a;
};
static_assert((sizeof(struct A) == 4) && (alignof(struct A) == 4));
static_assert((sizeof(struct B) == 8) && (alignof(struct B) == 8));
static_assert((sizeof(struct C) == 16) && (alignof(struct C) == 8));
static_assert((sizeof(struct D) == 16) && (alignof(struct D) == 8));
static_assert((sizeof(struct E) == 12) && (alignof(struct E) == 4));
static_assert((sizeof(struct F) == 12) && (alignof(struct F) == 4));
```
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug middle-end/105125] Bogus and Misleading Warning: Packed attribute is unnecessary.
2022-04-01 13:34 [Bug c++/105125] New: Bogus and Misleading Warning: Packed attribute is unnecessary Kimon.Hoffmann at lawo dot com
2022-04-01 13:41 ` [Bug c++/105125] " Kimon.Hoffmann at lawo dot com
2022-11-29 1:06 ` [Bug middle-end/105125] " pinskia at gcc dot gnu.org
@ 2022-11-29 1:12 ` pinskia at gcc dot gnu.org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-29 1:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105125
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The code has been wrong since the warning was added back in 1999:
r0-25196-g3c12fcc27809a2 ....
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-29 1:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01 13:34 [Bug c++/105125] New: Bogus and Misleading Warning: Packed attribute is unnecessary Kimon.Hoffmann at lawo dot com
2022-04-01 13:41 ` [Bug c++/105125] " Kimon.Hoffmann at lawo dot com
2022-11-29 1:06 ` [Bug middle-end/105125] " pinskia at gcc dot gnu.org
2022-11-29 1:12 ` pinskia at gcc dot gnu.org
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).