re PR c++/70488 (ICE in tree.c:7345 triggered by warning of placement new too small...
authorJakub Jelinek <jakub@redhat.com>
Fri, 1 Apr 2016 15:27:11 +0000 (17:27 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 1 Apr 2016 15:27:11 +0000 (17:27 +0200)
PR c++/70488
* init.c (warn_placement_new_too_small): Test whether
DECL_SIZE_UNIT or TYPE_SIZE_UNIT are integers that fit into uhwi.

* g++.dg/init/new47.C: New test.

Co-Authored-By: Marek Polacek <polacek@redhat.com>
From-SVN: r234676

gcc/cp/ChangeLog
gcc/cp/init.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/init/new47.C [new file with mode: 0644]

index e44818dc42dce9823897dadd790a27af1ff40aca..24528300fce5545ee886e2fd96743576501f7bb4 100644 (file)
@@ -1,3 +1,10 @@
+2016-04-01  Jakub Jelinek  <jakub@redhat.com>
+           Marek Polacek  <polacek@redhat.com>
+
+       PR c++/70488
+       * init.c (warn_placement_new_too_small): Test whether
+       DECL_SIZE_UNIT or TYPE_SIZE_UNIT are integers that fit into uhwi.
+
 2016-04-01  Nathan Sidwell  <nathan@acm.org>
 
        PR c++/68475
index aee3b8416e4b05d44058ea178861f31057aed349..5997d53ddb5503dd727c09f52026289f4b7f3772 100644 (file)
@@ -2430,7 +2430,8 @@ warn_placement_new_too_small (tree type, tree nelts, tree size, tree oper)
         though the size of a member of a union may be viewed as extending
         to the end of the union itself (it is by __builtin_object_size).  */
       if ((TREE_CODE (oper) == VAR_DECL || use_obj_size)
-         && DECL_SIZE_UNIT (oper))
+         && DECL_SIZE_UNIT (oper)
+         && tree_fits_uhwi_p (DECL_SIZE_UNIT (oper)))
        {
          /* Use the size of the entire array object when the expression
             refers to a variable or its size depends on an expression
@@ -2438,7 +2439,8 @@ warn_placement_new_too_small (tree type, tree nelts, tree size, tree oper)
          bytes_avail = tree_to_uhwi (DECL_SIZE_UNIT (oper));
          exact_size = !use_obj_size;
        }
-      else if (TYPE_SIZE_UNIT (TREE_TYPE (oper)))
+      else if (TYPE_SIZE_UNIT (TREE_TYPE (oper))
+              && tree_fits_uhwi_p (TYPE_SIZE_UNIT (TREE_TYPE (oper))))
        {
          /* Use the size of the type of the destination buffer object
             as the optimistic estimate of the available space in it.  */
index 5393d8c7ee3e5d131abd0425828844fe3e85aa0b..a4a1df51afcfe123091ee652a82d6a70485b2860 100644 (file)
@@ -1,3 +1,9 @@
+2016-04-01  Jakub Jelinek  <jakub@redhat.com>
+           Marek Polacek  <polacek@redhat.com>
+
+       PR c++/70488
+       * g++.dg/init/new47.C: New test.
+
 2016-04-01  Ramana Radhakrishnan  <ramana.radhakrishnan@arm.com>
 
        PR target/70496
diff --git a/gcc/testsuite/g++.dg/init/new47.C b/gcc/testsuite/g++.dg/init/new47.C
new file mode 100644 (file)
index 0000000..acd52d7
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/70448
+// { dg-do compile }
+// { dg-options "-Wall" }
+
+typedef __typeof__ (sizeof 0) size_t;
+void *operator new (size_t, void *p) { return p; }
+void *operator new[] (size_t, void *p) { return p; }
+struct S { size_t s; };
+void bar (S *);
+
+void
+foo (unsigned int s)
+{
+  char t[sizeof (S) + s];
+  S *f = new (t) S;
+  bar (f);
+  f = new (t) S[1];
+  bar (f);
+}