re PR c++/89507 (bogus "size of array exceeds maximum object size")
authorJakub Jelinek <jakub@redhat.com>
Tue, 26 Feb 2019 21:27:33 +0000 (22:27 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 26 Feb 2019 21:27:33 +0000 (22:27 +0100)
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
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/new2.C [new file with mode: 0644]
gcc/tree.c

index bf5cf95fe2629842410b794060d33946995dcfe6..41afdd13724f29c1fcd9b479682e6b475f8a901b 100644 (file)
@@ -1,3 +1,9 @@
+2019-02-26  Jakub Jelinek  <jakub@redhat.com>
+
+       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  <ebotcazou@adacore.com>
 
        * config/sparc/sparc-opts.h (enum processor_type): Rename to...
index 6e3c5f737024b22d5e792380793f0ab2bba2667e..14a8f541e814117c0d822ef086ce5dca6bcfeeef 100644 (file)
@@ -1,5 +1,8 @@
 2019-02-26  Jakub Jelinek  <jakub@redhat.com>
 
+       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 (file)
index 0000000..b086b9c
--- /dev/null
@@ -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" }
index 30e01df0ace64ac8ad11f92d7d90b8d94aee9798..0c70bb9cdd51083d2e6374d41c7b1e6511df58ad 100644 (file)
@@ -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;
     }