public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Slava Barinov <v.barinov@samsung.com>
To: gcc-patches@gcc.gnu.org
Cc: Slava Barinov <v.barinov@samsung.com>
Subject: [PATCH] c++/93730 create VLA constructor if explicitly initialized as zeroes
Date: Thu, 20 Feb 2020 07:11:00 -0000	[thread overview]
Message-ID: <20200220071120.13391-1-v.barinov@samsung.com> (raw)
In-Reply-To: <CGME20200220071135eucas1p1af0b37124681ceb36eeddd16ba62ecb6@eucas1p1.samsung.com>

	* 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

           reply	other threads:[~2020-02-20  7:11 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <CGME20200220071135eucas1p1af0b37124681ceb36eeddd16ba62ecb6@eucas1p1.samsung.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200220071120.13391-1-v.barinov@samsung.com \
    --to=v.barinov@samsung.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).