* cp/decl.c (reshape_init_array_1): Enforce constructor creation for VLAs when initialized with zero value. * testsuite/g++.dg/pr93730.C: New test * testsuite/g++.dg/abi/mangle72.C: Change mangling to new version
Signed-off-by: Slava Barinov <v.bari...@samsung.com> This fixes case when VLA is explicitly initialized with zero, not generic issue c++/58646 though. Bootstrapped on x86_64, no testsuite regressions found, except mangling change in mangle72.C, Not sure about mangling: is there any ABI requirements to mangling for that cases? --- gcc/ChangeLog | 8 ++++++++ gcc/cp/decl.c | 3 ++- gcc/testsuite/g++.dg/abi/mangle72.C | 14 +++++++------- gcc/testsuite/g++.dg/pr93730.C | 8 ++++++++ 4 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr93730.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f5876a3023e..10fa0334ec3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2020-02-20 Vyacheslav Barinov <v.bari...@samsung.com> + + PR c++/93730 + * cp/decl.c (reshape_init_array_1): Enforce constructor creation + for VLAs when initialized with zero value. + * testsuite/g++.dg/pr93730.C: New test + * testsuite/g++.dg/abi/mangle72.C: Change mangling to new version + 2020-02-19 Bernd Edlinger <bernd.edlin...@hotmail.de> * collect2.c (maybe_run_lto_and_relink): Fix typo in diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 31a556a0a1f..e90a397fc11 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -6043,7 +6043,8 @@ reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d, even if the string is empty. */ tree init_type = TREE_TYPE (elt_init); if (POINTER_TYPE_P (elt_type) != POINTER_TYPE_P (init_type) - || !type_initializer_zero_p (elt_type, elt_init)) + || !type_initializer_zero_p (elt_type, elt_init) + || sized_array_p) last_nonzero = index; /* This can happen with an invalid initializer (c++/54501). */ diff --git a/gcc/testsuite/g++.dg/abi/mangle72.C b/gcc/testsuite/g++.dg/abi/mangle72.C index 656a0cae403..928a38da021 100644 --- a/gcc/testsuite/g++.dg/abi/mangle72.C +++ b/gcc/testsuite/g++.dg/abi/mangle72.C @@ -27,16 +27,16 @@ void g__ (Y<B{{ }}>) { } // { dg-final { scan-assembler "_Z3g__1YIXtl1BtlA2_M1AA2_iLS3_0EEEEE" } } void g0_ (Y<B{{ 0 }}>) { } -// { dg-final { scan-assembler "_Z3g0_1YIXtl1BtlA2_M1AA2_iLS3_0EEEEE" } } +// { dg-final { scan-assembler "_Z3g0_1YIXtl1BtlA2_M1AA2_iLS3_0ELS3_0EEEEE" } } void g00 (Y<B{{ 0, 0 }}>) { } -// { dg-final { scan-assembler "_Z3g001YIXtl1BtlA2_M1AA2_iLS3_0EEEEE" } } +// { dg-final { scan-assembler "_Z3g001YIXtl1BtlA2_M1AA2_iLS3_0ELS3_0EEEEE" } } void g0x (Y<B{{ 0, &A::a }}>) { } // FIXME: This needs to mangle differently from g00. The space at // the end is intentional to make the directive fail so that the xfail // can be reminder to change this once the mangling is fixed. -// { dg-final { scan-assembler "_Z3g0x1YIXtl1BtlA2_M1AA2_iLS3_0EEEEE " { xfail *-*-* } } } +// { dg-final { scan-assembler "_Z3g0x1YIXtl1BtlA2_M1AA2_iLS3_0ELS3_0EEEEE " { xfail *-*-* } } } void gx_ (Y<B{{ &A::a }}>) { } // { dg-final { scan-assembler "_Z3gx_1YIXtl1BtlA2_M1AA2_iLS3_0ELS3_0EEEEE" } } @@ -49,17 +49,17 @@ void h___ (Z<C{{ }}>) { } // { dg-final { scan-assembler "_Z4h___1ZIXtl1CtlA3_M1AA2_iLS3_0EEEEE" } } void h0__ (Z<C{{ 0 }}>) { } -// { dg-final { scan-assembler "_Z4h0__1ZIXtl1CtlA3_M1AA2_iLS3_0EEEEE" } } +// { dg-final { scan-assembler "_Z4h0__1ZIXtl1CtlA3_M1AA2_iLS3_0ELS3_0EEEEE" } } void h00_ (Z<C{{ 0, 0 }}>) { } -// { dg-final { scan-assembler "_Z4h00_1ZIXtl1CtlA3_M1AA2_iLS3_0EEEEE" } } +// { dg-final { scan-assembler "_Z4h00_1ZIXtl1CtlA3_M1AA2_iLS3_0ELS3_0ELS3_0EEEEE" } } void h000 (Z<C{{ 0, 0, 0 }}>) { } -// { dg-final { scan-assembler "_Z4h0001ZIXtl1CtlA3_M1AA2_iLS3_0EEEEE" } } +// { dg-final { scan-assembler "_Z4h0001ZIXtl1CtlA3_M1AA2_iLS3_0ELS3_0ELS3_0EEEEE" } } void h00x (Z<C{{ 0, 0, &A::a }}>) { } // FIXME: This needs to mangle differently from hx0_ and hx__. -// { dg-final { scan-assembler "_Z4h00x1ZIXtl1CtlA3_M1AA2_iLS3_0ELS3_0EEEEE " { xfail *-*-*} } } +// { dg-final { scan-assembler "_Z4h00x1ZIXtl1CtlA3_M1AA2_iLS3_0ELS3_0ELS3_0EEEEE " { xfail *-*-*} } } void h0x0 (Z<C{{ 0, &A::a, 0 }}>) { } // { dg-final { scan-assembler "_Z4h0x01ZIXtl1CtlA3_M1AA2_iLS3_0ELS3_0ELS3_0EEEEE" } } diff --git a/gcc/testsuite/g++.dg/pr93730.C b/gcc/testsuite/g++.dg/pr93730.C new file mode 100644 index 00000000000..066c23a99cb --- /dev/null +++ b/gcc/testsuite/g++.dg/pr93730.C @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-Wno-vla" } */ + +int sz = 1; + +void f() { + int arr[1][sz] = { 0 }; +} -- 2.25.1