From 8735903781aabdb48683d24d783eba6c76fd8c99 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 26 Feb 2019 22:27:33 +0100 Subject: [PATCH] re PR c++/89507 (bogus "size of array exceeds maximum object size") PR c++/89507 * tree.c (valid_constant_size_p): Deal with size INTEGER_CSTs with types other than sizetype/ssizetype. * g++.dg/other/new2.C: New test. From-SVN: r269233 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 3 +++ gcc/testsuite/g++.dg/other/new2.C | 5 +++++ gcc/tree.c | 17 +++++++---------- 4 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/g++.dg/other/new2.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bf5cf95fe26..41afdd13724 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-02-26 Jakub Jelinek + + PR c++/89507 + * tree.c (valid_constant_size_p): Deal with size INTEGER_CSTs + with types other than sizetype/ssizetype. + 2019-02-26 Eric Botcazou * config/sparc/sparc-opts.h (enum processor_type): Rename to... diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6e3c5f73702..14a8f541e81 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,8 @@ 2019-02-26 Jakub Jelinek + PR c++/89507 + * g++.dg/other/new2.C: New test. + PR tree-optimization/89500 * gcc.dg/pr89500.c: New test. * gcc.dg/Wstringop-overflow-10.c: New test. diff --git a/gcc/testsuite/g++.dg/other/new2.C b/gcc/testsuite/g++.dg/other/new2.C new file mode 100644 index 00000000000..b086b9c4389 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/new2.C @@ -0,0 +1,5 @@ +// PR c++/89507 +// { dg-do compile } + +unsigned char const n = 128; +int *p = new int[n]; // { dg-bogus "array exceeds maximum object size" } diff --git a/gcc/tree.c b/gcc/tree.c index 30e01df0ace..0c70bb9cdd5 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -7533,19 +7533,16 @@ valid_constant_size_p (const_tree size, cst_size_error *perr /* = NULL */) return false; } - tree type = TREE_TYPE (size); - if (TYPE_UNSIGNED (type)) + if (tree_int_cst_sgn (size) < 0) { - if (!tree_fits_uhwi_p (size) - || tree_int_cst_sign_bit (size)) - { - *perr = cst_size_too_big; - return false; - } + *perr = cst_size_negative; + return false; } - else if (tree_int_cst_sign_bit (size)) + if (!tree_fits_uhwi_p (size) + || (wi::to_widest (TYPE_MAX_VALUE (sizetype)) + < wi::to_widest (size) * 2)) { - *perr = cst_size_negative; + *perr = cst_size_too_big; return false; } -- 2.30.2