Skip to content

Commit

Permalink
c++: [[no_unique_address]] and virtual base [PR104139]
Browse files Browse the repository at this point in the history
Fixing a thinko in my patch for 103681: when computing the size of a virtual
base, it would help to use its binfo instead of the one for the derived
class.

	PR c++/104139
	PR c++/103681

gcc/cp/ChangeLog:

	* class.cc (end_of_class): Use base_binfo.

gcc/testsuite/ChangeLog:

	* g++.dg/abi/no_unique_address2.C: Adjust to detect this on x86-64.
  • Loading branch information
jicama committed Jan 21, 2022
1 parent 45cae5b commit 23be9f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gcc/cp/class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6414,8 +6414,8 @@ end_of_class (tree t, eoc_mode mode)
{
if (mode == eoc_nv_or_dsize)
/* For dsize, don't count trailing empty bases. */
offset = size_binop (PLUS_EXPR, BINFO_OFFSET (binfo),
CLASSTYPE_SIZE_UNIT (BINFO_TYPE (binfo)));
offset = size_binop (PLUS_EXPR, BINFO_OFFSET (base_binfo),
CLASSTYPE_SIZE_UNIT (BINFO_TYPE (base_binfo)));
else
offset = end_of_base (base_binfo);
if (tree_int_cst_lt (result, offset))
Expand Down
27 changes: 27 additions & 0 deletions gcc/testsuite/g++.dg/abi/no_unique_address2.C
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,30 @@ struct B4
#define SA(X) static_assert ((X), #X)
SA (sizeof (B2) == sizeof (B1));
SA (sizeof (B3) == sizeof (B4));

namespace N2
{
// C as big as _vptr to test PR c++/104139
struct C
{
long c;
};

struct D: virtual C
{
virtual void f();
};

struct B3: D
{
char c2;
};

struct B4
{
D d [[no_unique_address]];
char c2;
};

SA (sizeof (B3) == sizeof (B4));
}

0 comments on commit 23be9f8

Please sign in to comment.