public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/109824] New: aligned attribute lost on first usage
@ 2023-05-12 9:35 stsp at users dot sourceforge.net
2023-05-12 9:38 ` [Bug c++/109824] " stsp at users dot sourceforge.net
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: stsp at users dot sourceforge.net @ 2023-05-12 9:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109824
Bug ID: 109824
Summary: aligned attribute lost on first usage
Product: gcc
Version: 12.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: stsp at users dot sourceforge.net
Target Milestone: ---
Created attachment 55063
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55063&action=edit
test case
struct a {
short aa;
};
typedef struct a less_aligned_a __attribute__ ((aligned (1)));
static inline void foo(void)
{
#ifndef BUG
struct a aa __attribute__((unused));
#endif
}
class t1 {
less_aligned_a i;
public:
less_aligned_a &get_ref() {
return i;
}
} __attribute__((packed));
t1 ap;
less_aligned_a* a = &ap.get_ref();
-----
$ g++ -Wall -c a.cpp
a.cpp: In instantiation of ‘less_aligned_a& t1<T>::get_ref() [with T = int;
less_aligned_a = a]’:
a.cpp:23:32: required from here
a.cpp:18:16: error: cannot bind packed field ‘((t1<int>*)this)->t1<int>::i’ to
‘less_aligned_a&’ {aka ‘a&’}
18 | return i;
But comment out the line 9 under "ifndef BUG"
and it compiles without an error.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/109824] aligned attribute lost on first usage
2023-05-12 9:35 [Bug c++/109824] New: aligned attribute lost on first usage stsp at users dot sourceforge.net
@ 2023-05-12 9:38 ` stsp at users dot sourceforge.net
2023-05-12 20:49 ` pinskia at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: stsp at users dot sourceforge.net @ 2023-05-12 9:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109824
--- Comment #1 from Stas Sergeev <stsp at users dot sourceforge.net> ---
Sorry, copied the output from wrong place.
The real error msg looks like this:
$ g++ -Wall -c a.cpp
a.cpp: In member function ‘less_aligned_a& t1::get_ref()’:
a.cpp:17:16: error: cannot bind packed field ‘((t1*)this)->t1::i’ to
‘less_aligned_a&’ {aka ‘a&’}
17 | return i;
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/109824] aligned attribute lost on first usage
2023-05-12 9:35 [Bug c++/109824] New: aligned attribute lost on first usage stsp at users dot sourceforge.net
2023-05-12 9:38 ` [Bug c++/109824] " stsp at users dot sourceforge.net
@ 2023-05-12 20:49 ` pinskia at gcc dot gnu.org
2023-05-12 22:59 ` stsp at users dot sourceforge.net
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-12 20:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109824
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=77388
Status|UNCONFIRMED |RESOLVED
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This is by design.
*** This bug has been marked as a duplicate of bug 109654 ***
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/109824] aligned attribute lost on first usage
2023-05-12 9:35 [Bug c++/109824] New: aligned attribute lost on first usage stsp at users dot sourceforge.net
2023-05-12 9:38 ` [Bug c++/109824] " stsp at users dot sourceforge.net
2023-05-12 20:49 ` pinskia at gcc dot gnu.org
@ 2023-05-12 22:59 ` stsp at users dot sourceforge.net
2023-05-12 23:15 ` [Bug c++/109824] aligned attribute lost when using it on a typedef of a struct if there was not an usage of the struct beforehand pinskia at gcc dot gnu.org
2023-05-12 23:18 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: stsp at users dot sourceforge.net @ 2023-05-12 22:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109824
Stas Sergeev <stsp at users dot sourceforge.net> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|DUPLICATE |---
--- Comment #3 from Stas Sergeev <stsp at users dot sourceforge.net> ---
Andrew, why not to read the bug description
at least, or try what was said in it?
It says:
But comment out the line 9 under "ifndef BUG"
and it compiles without an error.
This has nothing to do with the bug you
referred as a duplicate.
Please indicate that you tried that, only
then close.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/109824] aligned attribute lost when using it on a typedef of a struct if there was not an usage of the struct beforehand
2023-05-12 9:35 [Bug c++/109824] New: aligned attribute lost on first usage stsp at users dot sourceforge.net
` (2 preceding siblings ...)
2023-05-12 22:59 ` stsp at users dot sourceforge.net
@ 2023-05-12 23:15 ` pinskia at gcc dot gnu.org
2023-05-12 23:18 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-12 23:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109824
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|aligned attribute lost on |aligned attribute lost when
|first usage |using it on a typedef of a
| |struct if there was not an
| |usage of the struct
| |beforehand
Keywords| |accepts-invalid, wrong-code
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Right, the error message is correct when using it before hand; the alignment
attribute is there.
In the case of the used struct not used before hand, the alignment is lost.
This is the opposite of what you wrote even. You thought it was being lost if
there was an use before hand, rather the alignment is correct then.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/109824] aligned attribute lost when using it on a typedef of a struct if there was not an usage of the struct beforehand
2023-05-12 9:35 [Bug c++/109824] New: aligned attribute lost on first usage stsp at users dot sourceforge.net
` (3 preceding siblings ...)
2023-05-12 23:15 ` [Bug c++/109824] aligned attribute lost when using it on a typedef of a struct if there was not an usage of the struct beforehand pinskia at gcc dot gnu.org
@ 2023-05-12 23:18 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-05-12 23:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109824
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Last reconfirmed| |2023-05-12
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is a better testcase:
```
struct a {
int aa;
};
typedef struct a less_aligned_a __attribute__ ((aligned (1)));
static_assert(alignof(less_aligned_a) == 1);
struct a aa __attribute__((unused));
static_assert(alignof(less_aligned_a) == 1);
```
Which shows the issue.
The first static_assert works but the second one does not.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-05-12 23:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-12 9:35 [Bug c++/109824] New: aligned attribute lost on first usage stsp at users dot sourceforge.net
2023-05-12 9:38 ` [Bug c++/109824] " stsp at users dot sourceforge.net
2023-05-12 20:49 ` pinskia at gcc dot gnu.org
2023-05-12 22:59 ` stsp at users dot sourceforge.net
2023-05-12 23:15 ` [Bug c++/109824] aligned attribute lost when using it on a typedef of a struct if there was not an usage of the struct beforehand pinskia at gcc dot gnu.org
2023-05-12 23:18 ` 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).