On 2/17/21 4:50 AM, Jakub Jelinek wrote:
Hi!

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.

lgtm -- yes, an array bound of -1 is certainly odd :)


Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2021-02-17  Jakub Jelinek  <ja...@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.

--- gcc/cp/init.c.jj    2021-02-12 23:57:30.501141871 +0100
+++ gcc/cp/init.c       2021-02-16 09:29:24.635069944 +0100
@@ -252,7 +252,7 @@ build_zero_init_1 (tree type, tree nelts
                                     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);
--- gcc/testsuite/g++.dg/ubsan/pr99106.C.jj 2021-02-16 09:35:50.575679899 +0100
+++ gcc/testsuite/g++.dg/ubsan/pr99106.C        2021-02-16 09:35:42.904767167 
+0100
@@ -0,0 +1,5 @@
+// PR sanitizer/99106
+// { dg-do compile }
+// { dg-options "-fsanitize=undefined" }
+
+#include "../ext/flexary38.C"

        Jakub



--
Nathan Sidwell

Reply via email to