From f70cb6f5b0ee51223319ec524994e59d356fb862 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 2 Aug 2018 14:25:57 +0000 Subject: [PATCH] re PR c++/86763 (Wrong code comparing member of copy of a 237 byte object with nontrivial default constructor on x86-64 arch) 2018-08-02 Richard Biener PR c++/86763 * class.c (layout_class_type): Copy TYPE_TYPELESS_STORAGE to the CLASSTYPE_AS_BASE. * g++.dg/torture/pr86763.C: New testcase. From-SVN: r263261 --- gcc/ChangeLog | 6 +++++ gcc/cp/class.c | 1 + gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/torture/pr86763.C | 36 ++++++++++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 gcc/testsuite/g++.dg/torture/pr86763.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 85c1ef57991..a406f8e1303 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-08-02 Richard Biener + + PR c++/86763 + * class.c (layout_class_type): Copy TYPE_TYPELESS_STORAGE + to the CLASSTYPE_AS_BASE. + 2018-08-02 Richard Biener PR tree-optimization/86816 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index de59831c54e..76a9e186c26 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -6279,6 +6279,7 @@ layout_class_type (tree t, tree *virtuals_p) 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. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b0e7505500d..976bfa8d07d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-08-02 Richard Biener + + PR c++/86763 + * g++.dg/torture/pr86763.C: New testcase. + 2018-08-02 Richard Biener PR tree-optimization/86816 diff --git a/gcc/testsuite/g++.dg/torture/pr86763.C b/gcc/testsuite/g++.dg/torture/pr86763.C new file mode 100644 index 00000000000..6b79d561a60 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr86763.C @@ -0,0 +1,36 @@ +// { dg-do run } +// { dg-additional-options "-fschedule-insns2 -fstrict-aliasing" } + +#include +#include +#include +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); +} -- 2.30.2