public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r8-10886] c++: Fix up build_zero_init_1 once more [PR99106]
@ 2021-04-22 16:50 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-04-22 16:50 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:3a51e6261f7d98d54fc370125b1895542c3cdce9
commit r8-10886-g3a51e6261f7d98d54fc370125b1895542c3cdce9
Author: Jakub Jelinek <jakub@redhat.com>
Date: Wed Feb 17 15:03:25 2021 +0100
c++: Fix up build_zero_init_1 once more [PR99106]
My earlier build_zero_init_1 patch for flexible array members created
an empty CONSTRUCTOR. As the following testcase shows, that doesn't work
very well because the middle-end doesn't expect CONSTRUCTOR elements with
incomplete type (that the empty CONSTRUCTOR at the end of outer CONSTRUCTOR
had).
The following patch just doesn't add any CONSTRUCTOR for the flexible array
members, it doesn't seem to be needed.
2021-02-17 Jakub Jelinek <jakub@redhat.com>
PR sanitizer/99106
* init.c (build_zero_init_1): For flexible array members just return
NULL_TREE instead of returning empty CONSTRUCTOR with non-complete
ARRAY_TYPE.
* g++.dg/ubsan/pr99106.C: New test.
(cherry picked from commit af868e89ec21340d1cafd26eaed356ce4b0104c3)
Diff:
---
gcc/cp/init.c | 2 +-
gcc/testsuite/g++.dg/ubsan/pr99106.C | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 26f5c3a0461..b5235082a25 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -250,7 +250,7 @@ build_zero_init_1 (tree type, tree nelts, bool static_storage_p,
build_one_cst (TREE_TYPE (nelts)));
/* Treat flexible array members like [0] arrays. */
else if (TYPE_DOMAIN (type) == NULL_TREE)
- max_index = build_minus_one_cst (sizetype);
+ return NULL_TREE;
else
max_index = array_type_nelts (type);
diff --git a/gcc/testsuite/g++.dg/ubsan/pr99106.C b/gcc/testsuite/g++.dg/ubsan/pr99106.C
new file mode 100644
index 00000000000..ccb48a96f4b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ubsan/pr99106.C
@@ -0,0 +1,5 @@
+// PR sanitizer/99106
+// { dg-do compile }
+// { dg-options "-fsanitize=undefined" }
+
+#include "../ext/flexary38.C"
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-04-22 16:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-22 16:50 [gcc r8-10886] c++: Fix up build_zero_init_1 once more [PR99106] Jakub Jelinek
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).