This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PING^1: [PATCH] Add TYPE_EMPTY_RECORD for C++ empty class
- From: Jakub Jelinek <jakub at redhat dot com>
- To: "H.J. Lu" <hjl dot tools at gmail dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>, Richard Biener <richard dot guenther at gmail dot com>, Markus Trippelsdorf <markus at trippelsdorf dot de>
- Date: Tue, 26 Jan 2016 22:40:00 +0100
- Subject: Re: PING^1: [PATCH] Add TYPE_EMPTY_RECORD for C++ empty class
- Authentication-results: sourceware.org; auth=none
- References: <566F23AE dot 6070604 at redhat dot com> <CAMe9rOoodvn=C0NcpHiFb3nVLr2j9vXBibpSpAcE7wKcxSt3jQ at mail dot gmail dot com> <566F2A0B dot 4010102 at redhat dot com> <CAMe9rOpRKYX5csM9PNhO6msWPMe-FAcCcixzEHiGp=WiAN567A at mail dot gmail dot com> <56A7C8AC dot 8070204 at redhat dot com> <CAMe9rOr96trJpuXrjb_-90SmFmfMCRQ57nyD-4fW7Q5ET_mvFg at mail dot gmail dot com> <alpine dot DEB dot 2 dot 20 dot 1601262118020 dot 8312 at laptop-mg dot saclay dot inria dot fr> <CAMe9rOrXESQ3oJNzvXd1X9k=rD_DM+OSya_54vcRutVVPz4PjA at mail dot gmail dot com> <alpine dot DEB dot 2 dot 20 dot 1601262134021 dot 8312 at laptop-mg dot saclay dot inria dot fr> <CAMe9rOpx=-s-KZzBLWteNeY3JczmJ_p0dKN8giNkWAM92D85Rg at mail dot gmail dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Tue, Jan 26, 2016 at 01:21:52PM -0800, H.J. Lu wrote:
> Like this:
>
> /* Returns true if TYPE is POD for the purpose of layout and an empty
> class or an class with empty classes. */
>
> static bool
> is_empty_record (tree type)
> {
> if (type == error_mark_node)
> return false;
>
> if (!CLASS_TYPE_P (type))
> return false;
>
> if (CLASSTYPE_NON_LAYOUT_POD_P (type))
> return false;
>
> gcc_assert (COMPLETE_TYPE_P (type));
>
> if (CLASSTYPE_EMPTY_P (type))
> return true;
>
> tree field;
>
> for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
> if (TREE_CODE (field) == FIELD_DECL
> && !DECL_ARTIFICIAL (field)
> && !is_empty_record (TREE_TYPE (field)))
> return false;
>
> return true;
> }
So you say that K1 in e.g.:
struct A1 {}; struct A2 {};
struct B1 { A1 a; A2 b; }; struct B2 { A1 a; A2 b; };
struct C1 { B1 a; B2 b; }; struct C2 { B1 a; B2 b; };
struct D1 { C1 a; C2 b; }; struct D2 { C1 a; C2 b; };
struct E1 { D1 a; D2 b; }; struct E2 { D1 a; D2 b; };
struct F1 { E1 a; E2 b; }; struct F2 { E1 a; E2 b; };
struct G1 { F1 a; F2 b; }; struct G2 { F1 a; F2 b; };
struct H1 { G1 a; G2 b; }; struct H2 { G1 a; G2 b; };
struct I1 { H1 a; H2 b; }; struct I2 { H1 a; H2 b; };
struct J1 { I1 a; I2 b; }; struct J2 { I1 a; I2 b; };
struct K1 { J1 a; J2 b; };
int v;
__attribute__((noinline, noclone))
K1 foo (int a, K1 x, int b)
{
v = a + b;
return x;
}
K1 k, m;
void
bar (void)
{
m = foo (1, k, 2);
}
is empty class? What does clang do with this?
Jakub