aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2016-04-01 15:27:11 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2016-04-01 15:27:11 +0000
commite5b1a1d9ec0fb2d6e3148a854bcc9f624c561db9 (patch)
treec676f74751d79ea607d57b64284bf39211f533b7
parentb2ca3fb0b185603b5611c2916f388a16609bdf52 (diff)
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@234676 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/init.c6
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/g++.dg/init/new47.C19
4 files changed, 36 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index e44818dc42d..24528300fce 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index aee3b8416e4..5997d53ddb5 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -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. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 5393d8c7ee3..a4a1df51afc 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 00000000000..acd52d7993b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/new47.C
@@ -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);
+}