testsuite: Extend C++ struct-layout-1.exp testing to test C++14 vs. C++17 interoperab...
authorJakub Jelinek <jakub@redhat.com>
Tue, 21 Apr 2020 15:08:10 +0000 (17:08 +0200)
committerJakub Jelinek <jakub@redhat.com>
Tue, 21 Apr 2020 15:08:10 +0000 (17:08 +0200)
commit619602346aed9dae3f338d9f18767414446adf78
tree59ad149afa45faa4dc6cff80eaab372fd09b21e6
parent73f8e9dca5ff891ed19001b213fd1f6ce31417e3
testsuite: Extend C++ struct-layout-1.exp testing to test C++14 vs. C++17 interoperability of structs with empty bases [PR94383]

Jonathan reported an ABI incompatibility between C++14 and C++17 in
passing some aggregates with empty bases on aarch64 (and apparently on arm
too).

The following patch adds 3000 (by default) tests for such interoperability,
using the struct-layout-1* framework.  The current 3000 tests are generated
as is (so unchanged from previous ones), and afterwards there is another set
of 3000 ones, where always one of the tNNN_x.C and tNNN_y.C tests get added
-std=c++14 -DCXX14_VS_CXX17 and another one -std=c++17 -DCXX14_VS_CXX17
options (which one which is chosen pseudo-randomly), which causes the
structs to have an empty base.

I haven't added (yet) checks if the alternate compiler does support these
options (I think that can be done incrementally), so for now this testing is
done only if the alternate compiler is not used.

I had to fix a bug in the flexible array handling, because while we were
lucky in the 3000 generated tests not to have toplevel fields after field
with flexible array members, in the next 3000 we aren't lucky anymore.
But even with that change, diff -upr between old and new
testsuite/g++/g++.dg/g++.dg-struct-layout-1/ doesn't show any differences
except for the ^Only in... messages for the new tests in there.

Bootstrapped/regtested on x86_64-linux and i686-linux and additionally
tested on aarch64-linux, where
FAIL: tmpdir-g++.dg-struct-layout-1/t032 cp_compat_x_tst.o-cp_compat_y_tst.o execute
FAIL: tmpdir-g++.dg-struct-layout-1/t056 cp_compat_x_tst.o-cp_compat_y_tst.o execute
FAIL: tmpdir-g++.dg-struct-layout-1/t057 cp_compat_x_tst.o-cp_compat_y_tst.o execute
FAIL: tmpdir-g++.dg-struct-layout-1/t058 cp_compat_x_tst.o-cp_compat_y_tst.o execute
FAIL: tmpdir-g++.dg-struct-layout-1/t059 cp_compat_x_tst.o-cp_compat_y_tst.o execute
because of the backend bug, and with that bug fixed it succeeds.
Matthew has kindly tested it also on aarch64-linux and arm*-*.

The primary goal of the patch is catch if some targets other than aarch64 or
arm aren't affected too.

2020-04-21  Jakub Jelinek  <jakub@redhat.com>

PR c++/94383
* g++.dg/compat/struct-layout-1.exp: If !$use_alt, add -c to generator
args.
* g++.dg/compat/struct-layout-1_generate.c (dg_options): Add another
%s to the start of dg-options arg.
(cxx14_vs_cxx17, do_cxx14_vs_cxx17): New variables.
(switchfiles): If cxx14_vs_cxx17, prepend -std=c++14 -DCXX14_VS_CXX17
or -std=c++17 -DCXX17_VS_CXX14 - randomly - to dg-options.
(output): Don't append further fields once one with flexible array
member is added.
(generate_random_tests): Don't use toplevel unions if cxx14_vs_cxx17.
(main): If -c, emit second set of tests for -std=c++14 vs. -std=c++17
testing.
* g++.dg/compat/struct-layout-1_x1.h (empty_base): New type.
(EMPTY_BASE): Define.
(TX): Use EMPTY_BASE.
* g++.dg/compat/struct-layout-1_y1.h (empty_base): New type.
(EMPTY_BASE): Define.
(TX): Use EMPTY_BASE.
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/compat/struct-layout-1.exp
gcc/testsuite/g++.dg/compat/struct-layout-1_generate.c
gcc/testsuite/g++.dg/compat/struct-layout-1_x1.h
gcc/testsuite/g++.dg/compat/struct-layout-1_y1.h