]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Fix up build_zero_init_1 once more [PR99106]
authorJakub Jelinek <jakub@redhat.com>
Wed, 17 Feb 2021 14:03:25 +0000 (15:03 +0100)
committerJakub Jelinek <jakub@redhat.com>
Fri, 19 Mar 2021 23:27:49 +0000 (00:27 +0100)
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 7768cadb4246117964a9ba159740da3b9c20811d)

gcc/cp/init.c
gcc/testsuite/g++.dg/ubsan/pr99106.C [new file with mode: 0644]

index bbd33f46697e12023dc888ab2e2f94b3ca79b70d..878099ecaadd23e810c0aa75d5ecee009202ed00 100644 (file)
@@ -251,7 +251,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 (file)
index 0000000..ccb48a9
--- /dev/null
@@ -0,0 +1,5 @@
+// PR sanitizer/99106
+// { dg-do compile }
+// { dg-options "-fsanitize=undefined" }
+
+#include "../ext/flexary38.C"