public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++/93730 create VLA constructor if explicitly initialized as zeroes
       [not found] <CGME20200220071135eucas1p1af0b37124681ceb36eeddd16ba62ecb6@eucas1p1.samsung.com>
@ 2020-02-20  7:11 ` Slava Barinov
  0 siblings, 0 replies; only message in thread
From: Slava Barinov @ 2020-02-20  7:11 UTC (permalink / raw)
  To: gcc-patches; +Cc: Slava Barinov

	* 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.barinov@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.barinov@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.edlinger@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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-02-20  7:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20200220071135eucas1p1af0b37124681ceb36eeddd16ba62ecb6@eucas1p1.samsung.com>
2020-02-20  7:11 ` [PATCH] c++/93730 create VLA constructor if explicitly initialized as zeroes Slava Barinov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).