From 0f8754352485c6aaa6a6b85ce252585ae1eb31d7 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 1 Apr 2016 17:27:11 +0200 Subject: [PATCH] re PR c++/70488 (ICE in tree.c:7345 triggered by warning of placement new too small on VLA) 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 From-SVN: r234676 --- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/init.c | 6 ++++-- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/init/new47.C | 19 +++++++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/init/new47.C 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 + Marek Polacek + + 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 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 + Marek Polacek + + PR c++/70488 + * g++.dg/init/new47.C: New test. + 2016-04-01 Ramana Radhakrishnan 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); +} -- 2.30.2