PR c++/87996 - size of array is negative error when SIZE_MAX/2 < sizeof(array) <...
authorMartin Sebor <msebor@redhat.com>
Mon, 11 Feb 2019 17:35:17 +0000 (17:35 +0000)
committerMartin Sebor <msebor@gcc.gnu.org>
Mon, 11 Feb 2019 17:35:17 +0000 (10:35 -0700)
commit28a8cef1e240989c199dfd8538c826c134098f85
treea7b930a4f8e120d187bde8f6ea311c2ed60e6d55
parent3c4860e346b8292ac398d971aff933586b11e3ea
PR c++/87996 - size of array is negative error when SIZE_MAX/2 < sizeof(array) <= SIZE_MAX

gcc/ChangeLog:

PR c++/87996
* builtins.c (max_object_size): Move from here...
* builtins.h (max_object_size): ...and here...
* tree.c (max_object_size): ...to here...
* tree.h (max_object_size): ...and here.

gcc/c-family/ChangeLog:

PR c++/87996
* c-common.c (invalid_array_size_error): New function.
(valid_array_size_p): Call it.  Handle size as well as type.
* c-common.h (valid_constant_size_p): New function.
(enum cst_size_error): New type.

gcc/cp/ChangeLog:

PR c++/87996
* decl.c (compute_array_index_type_loc): Preserve signed sizes
for diagnostics.  Call valid_array_size_p instead of error.
* init.c (build_new_1): Compute size for diagnostic.  Call
invalid_array_size_error
(build_new): Call valid_array_size_p instead of error.

gcc/testsuite/ChangeLog:

PR c++/87996
* c-c++-common/array-5.c: New test.
* c-c++-common/pr68107.c: Adjust text of diagnostics.
* g++.dg/init/new38.C: Same.
* g++.dg/init/new43.C: Same.
* g++.dg/init/new44.C: Same.
* g++.dg/init/new46.C: Same.
* g++.dg/other/large-size-array.C: Same.
* g++.dg/other/new-size-type.C: Same.
* g++.dg/template/array30.C: Same.
* g++.dg/template/array32.C: New test.
* g++.dg/template/dependent-name3.C: Adjust.
* gcc.dg/large-size-array-3.c: Same.
* gcc.dg/large-size-array-5.c: Same.
* gcc.dg/large-size-array.c: Same.
* g++.old-deja/g++.brendan/array1.C: Same.
* g++.old-deja/g++.mike/p6149.C: Same.

From-SVN: r268774
29 files changed:
gcc/ChangeLog
gcc/builtins.c
gcc/builtins.h
gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/c-family/c-common.h
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/cp/init.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/array-5.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/pr68107.c
gcc/testsuite/g++.dg/init/new38.C
gcc/testsuite/g++.dg/init/new43.C
gcc/testsuite/g++.dg/init/new44.C
gcc/testsuite/g++.dg/init/new46.C
gcc/testsuite/g++.dg/other/large-size-array.C
gcc/testsuite/g++.dg/other/new-size-type.C
gcc/testsuite/g++.dg/template/array30.C
gcc/testsuite/g++.dg/template/array32.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/dependent-name3.C
gcc/testsuite/g++.dg/ubsan/pr81530.C
gcc/testsuite/g++.old-deja/g++.brendan/array1.C
gcc/testsuite/g++.old-deja/g++.mike/p6149.C
gcc/testsuite/gcc.dg/large-size-array-3.c
gcc/testsuite/gcc.dg/large-size-array-5.c
gcc/testsuite/gcc.dg/large-size-array.c
gcc/tree.c
gcc/tree.h