]> gcc.gnu.org Git - gcc.git/commit
c++: Fix up ubsan false positives on references [PR95693]
authorJakub Jelinek <jakub@redhat.com>
Fri, 22 Jan 2021 18:03:23 +0000 (19:03 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 20 Apr 2021 23:28:08 +0000 (01:28 +0200)
commit4ccdb3fdbc14102c91b6148bcbe09d0763726ae0
tree41bdde4e7277e2554350e6821ffe66f2c7065c16
parent45a6eae129c6fee387a3bb7075181d8509fa6e2a
c++: Fix up ubsan false positives on references [PR95693]

Alex' 2 years old change to build_zero_init_1 to return NULL pointer with
reference type for references breaks the sanitizers, the assignment of NULL
to a reference typed member is then instrumented before it is overwritten
with a non-NULL address later on.
That change has been done to fix error recovery ICE during
process_init_constructor_record, where we:
          if (TYPE_REF_P (fldtype))
            {
              if (complain & tf_error)
                error ("member %qD is uninitialized reference", field);
              else
                return PICFLAG_ERRONEOUS;
            }
a few lines earlier, but then continue and ICE when build_zero_init returns
NULL.

The following patch reverts the build_zero_init_1 change and instead creates
the NULL with reference type constants during the error recovery.

The pr84593.C testcase Alex' change was fixing still works as before.

2021-01-22  Jakub Jelinek  <jakub@redhat.com>

PR sanitizer/95693
* init.c (build_zero_init_1): Revert the 2018-03-06 change to
return build_zero_cst for reference types.
* typeck2.c (process_init_constructor_record): Instead call
build_zero_cst here during error recovery instead of build_zero_init.

* g++.dg/ubsan/pr95693.C: New test.

(cherry picked from commit e5750f847158e7f9bdab770fd9c5fff58c5074d3)
gcc/cp/init.c
gcc/cp/typeck2.c
gcc/testsuite/g++.dg/ubsan/pr95693.C [new file with mode: 0644]
This page took 0.061915 seconds and 5 git commands to generate.