public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95976] New: [[no_unique_address]] on union members has the opposite-of-intended effect
@ 2020-06-29 16:52 metaprogrammingtheworld at gmail dot com
2020-06-30 11:56 ` [Bug c++/95976] " jakub at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: metaprogrammingtheworld at gmail dot com @ 2020-06-29 16:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95976
Bug ID: 95976
Summary: [[no_unique_address]] on union members has the
opposite-of-intended effect
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: metaprogrammingtheworld at gmail dot com
Target Milestone: ---
When using [[no_unique_address]] with union members, ironically, each member is
now given a unique address! Without [[no_unique_address]], the layout is as one
would expect. This is particularly unfortunate since it means that a union's
size grows in proportion to the number of members when using
[[no_unique_address]]!
Example:
//////////
struct empty {};
union no_attribute_t
{
empty _0;
empty _1;
};
union with_attribute_t
{
[[no_unique_address]] empty _0;
[[no_unique_address]] empty _1;
};
constexpr no_attribute_t no_attribute{};
constexpr with_attribute_t with_attribute{};
// This succeeds
static_assert( &no_attribute._0 == &no_attribute._1 );
// This fails
static_assert( &with_attribute._0 == &with_attribute._1 );
//////////
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/95976] [[no_unique_address]] on union members has the opposite-of-intended effect
2020-06-29 16:52 [Bug c++/95976] New: [[no_unique_address]] on union members has the opposite-of-intended effect metaprogrammingtheworld at gmail dot com
@ 2020-06-30 11:56 ` jakub at gcc dot gnu.org
2020-06-30 12:27 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-06-30 11:56 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95976
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Version|unknown |10.1.0
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This changed behavior twice, first one with
r9-3261-gbedf03a298f87b43f02eaee57542fbd10228ec08
with which the union size became 0 rather than the expected 1, and then in
r9-5710-g7e574f68fa82e7c5f879fd468291ec8b5ebecc83
which made the union size 2 instead (also incorrect). From what I can see in
the standard, [[no_unique_address]] is allowed on union members and those
members are potentially-overlapping subobjects, but the union description makes
it clear that all those members start at offset 0.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/95976] [[no_unique_address]] on union members has the opposite-of-intended effect
2020-06-29 16:52 [Bug c++/95976] New: [[no_unique_address]] on union members has the opposite-of-intended effect metaprogrammingtheworld at gmail dot com
2020-06-30 11:56 ` [Bug c++/95976] " jakub at gcc dot gnu.org
@ 2020-06-30 12:27 ` jakub at gcc dot gnu.org
2020-07-10 3:24 ` jason at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-06-30 12:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95976
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2020-06-30
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Keywords| |ABI
CC| |jason at gcc dot gnu.org,
| |redi at gcc dot gnu.org
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
One way to fix this would be:
--- gcc/cp/class.c.jj 2020-06-27 12:35:11.935311848 +0200
+++ gcc/cp/class.c 2020-06-30 14:18:08.448067688 +0200
@@ -6575,7 +6575,9 @@ layout_class_type (tree t, tree *virtual
/* We must also reset the DECL_MODE of the field. */
SET_DECL_MODE (field, TYPE_MODE (type));
}
- else if (might_overlap && is_empty_class (type))
+ else if (might_overlap
+ && is_empty_class (type)
+ && TREE_CODE (t) != UNION_TYPE)
{
DECL_FIELD_ABI_IGNORED (field) = 1;
layout_empty_base_or_field (rli, field, empty_base_offsets);
Another might be not to change DECL_FIELD_OFFSET in layout_empty_base_or_field
for TREE_CODE (rli->t) == UNION_TYPE, etc.
The question is if [[no_unique_address]] members of a union should affect any
ABI decisions (such as passing the union by value) or not.
Looking at the config/*/* code, in most cases the targets ignore
DECL_FIELD_ABI_IGNORED on UNION_TYPE members, but ia64 does not, and I think
rs6000_special_round_type_align and darwin_rs6000_special_round_type_align
don't ignore it either.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/95976] [[no_unique_address]] on union members has the opposite-of-intended effect
2020-06-29 16:52 [Bug c++/95976] New: [[no_unique_address]] on union members has the opposite-of-intended effect metaprogrammingtheworld at gmail dot com
2020-06-30 11:56 ` [Bug c++/95976] " jakub at gcc dot gnu.org
2020-06-30 12:27 ` jakub at gcc dot gnu.org
@ 2020-07-10 3:24 ` jason at gcc dot gnu.org
2020-07-10 12:36 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2020-07-10 3:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95976
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |jason at gcc dot gnu.org
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/95976] [[no_unique_address]] on union members has the opposite-of-intended effect
2020-06-29 16:52 [Bug c++/95976] New: [[no_unique_address]] on union members has the opposite-of-intended effect metaprogrammingtheworld at gmail dot com
` (2 preceding siblings ...)
2020-07-10 3:24 ` jason at gcc dot gnu.org
@ 2020-07-10 12:36 ` cvs-commit at gcc dot gnu.org
2020-07-10 12:36 ` cvs-commit at gcc dot gnu.org
2020-08-04 17:35 ` jason at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-07-10 12:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95976
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jason Merrill
<jason@gcc.gnu.org>:
https://gcc.gnu.org/g:3bb330022ce47a3e8966a9930f392e497c608f59
commit r10-8456-g3bb330022ce47a3e8966a9930f392e497c608f59
Author: Jason Merrill <jason@redhat.com>
Date: Thu Jul 9 15:11:12 2020 -0400
c++: [[no_unique_address]] fixes. [PR96105]
We were wrongly checking is_empty_class on the result of strip_array_types
rather than the actual field type. We weren't considering the alignment of
the data member. We needed to handle unions the same way as
layout_nonempty_base_or_field.
gcc/cp/ChangeLog:
PR c++/96105
PR c++/96052
PR c++/95976
* class.c (check_field_decls): An array of empty classes is not an
empty data member.
(layout_empty_base_or_field): Handle explicit alignment.
Fix union handling.
gcc/testsuite/ChangeLog:
PR c++/96105
PR c++/96052
PR c++/95976
* g++.dg/cpp2a/no_unique_address4.C: New test.
* g++.dg/cpp2a/no_unique_address5.C: New test.
* g++.dg/cpp2a/no_unique_address6.C: New test.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/95976] [[no_unique_address]] on union members has the opposite-of-intended effect
2020-06-29 16:52 [Bug c++/95976] New: [[no_unique_address]] on union members has the opposite-of-intended effect metaprogrammingtheworld at gmail dot com
` (3 preceding siblings ...)
2020-07-10 12:36 ` cvs-commit at gcc dot gnu.org
@ 2020-07-10 12:36 ` cvs-commit at gcc dot gnu.org
2020-08-04 17:35 ` jason at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-07-10 12:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95976
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jason Merrill <jason@gcc.gnu.org>:
https://gcc.gnu.org/g:e47dfca5aa473e77fdff95d631dc39de87a41eec
commit r11-2014-ge47dfca5aa473e77fdff95d631dc39de87a41eec
Author: Jason Merrill <jason@redhat.com>
Date: Thu Jul 9 15:11:12 2020 -0400
c++: [[no_unique_address]] fixes. [PR96105]
We were wrongly checking is_empty_class on the result of strip_array_types
rather than the actual field type. We weren't considering the alignment of
the data member. We needed to handle unions the same way as
layout_nonempty_base_or_field.
gcc/cp/ChangeLog:
PR c++/96105
PR c++/96052
PR c++/95976
* class.c (check_field_decls): An array of empty classes is not an
empty data member.
(layout_empty_base_or_field): Handle explicit alignment.
Fix union handling.
gcc/testsuite/ChangeLog:
PR c++/96105
PR c++/96052
PR c++/95976
* g++.dg/cpp2a/no_unique_address4.C: New test.
* g++.dg/cpp2a/no_unique_address5.C: New test.
* g++.dg/cpp2a/no_unique_address6.C: New test.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/95976] [[no_unique_address]] on union members has the opposite-of-intended effect
2020-06-29 16:52 [Bug c++/95976] New: [[no_unique_address]] on union members has the opposite-of-intended effect metaprogrammingtheworld at gmail dot com
` (4 preceding siblings ...)
2020-07-10 12:36 ` cvs-commit at gcc dot gnu.org
@ 2020-08-04 17:35 ` jason at gcc dot gnu.org
5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2020-08-04 17:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95976
Jason Merrill <jason at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Target Milestone|--- |10.2
Resolution|--- |FIXED
--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 10.2/11.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2020-08-04 17:35 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-29 16:52 [Bug c++/95976] New: [[no_unique_address]] on union members has the opposite-of-intended effect metaprogrammingtheworld at gmail dot com
2020-06-30 11:56 ` [Bug c++/95976] " jakub at gcc dot gnu.org
2020-06-30 12:27 ` jakub at gcc dot gnu.org
2020-07-10 3:24 ` jason at gcc dot gnu.org
2020-07-10 12:36 ` cvs-commit at gcc dot gnu.org
2020-07-10 12:36 ` cvs-commit at gcc dot gnu.org
2020-08-04 17:35 ` jason 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).