This fixes the PR by making sure CLASSTYPE_AS_BASE types inherit TYPE_TYPELESS_STORAGE from the main type so that types that inherit a type with TYPE_TYPELESS_STORAGE also get TYPE_TYPELESS_STORAGE propagated.
Bootstrap & regtest running on x86_64-unknown-linux-gnu, OK? Thanks, Richard. 2018-08-02 Richard Biener <rguent...@suse.de> PR c++/86763 * class.c (layout_class_type): Copy TYPE_TYPELESS_STORAGE to the CLASSTYPE_AS_BASE. * g++.dg/torture/pr86763.C: New testcase. Index: gcc/cp/class.c =================================================================== --- gcc/cp/class.c (revision 263209) +++ gcc/cp/class.c (working copy) @@ -6243,6 +6243,7 @@ layout_class_type (tree t, tree *virtual bitsize_int (BITS_PER_UNIT))); SET_TYPE_ALIGN (base_t, rli->record_align); TYPE_USER_ALIGN (base_t) = TYPE_USER_ALIGN (t); + TYPE_TYPELESS_STORAGE (base_t) = TYPE_TYPELESS_STORAGE (t); /* Copy the non-static data members of T. This will include its direct non-virtual bases & vtable. */ Index: gcc/testsuite/g++.dg/torture/pr86763.C =================================================================== --- gcc/testsuite/g++.dg/torture/pr86763.C (nonexistent) +++ gcc/testsuite/g++.dg/torture/pr86763.C (working copy) @@ -0,0 +1,36 @@ +// { dg-do run } +// { dg-additional-options "-fschedule-insns2 -fstrict-aliasing" } + +#include <cstdint> +#include <cassert> +#include <time.h> +struct ID { + uint64_t value; +}; +uint64_t value(ID id) { return id.value; } +uint64_t gen { 1000 }; +struct Msg { + uint64_t time; + ID id; +}; +struct V { + V() { } + V(Msg const & msg) : msg(msg) { } + Msg & get() { return msg; } + Msg msg; + char pad[237 - sizeof(Msg)]; +}; +struct T : V { using V::V; }; +Msg init_msg() { + Msg msg; + timespec t; + clock_gettime(CLOCK_REALTIME, &t); + msg.time = t.tv_sec + t.tv_nsec; + msg.id.value = ++gen; + return msg; +} +int main() { + T t; + t = init_msg(); + assert(value(t.get().id) == 1001); +}