aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-08-20 09:53:58 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2007-08-20 09:53:58 +0200
commit412bbe81d92ba9c32a2ebd523391bb8f6637a2f7 (patch)
treec2c802aba74aa922e346224b83ab6282792c8007 /gcc
parenta9eafe819c64a5f6dbc52dbe908ca680de8ca103 (diff)
downloadgcc-412bbe81d92ba9c32a2ebd523391bb8f6637a2f7.zip
gcc-412bbe81d92ba9c32a2ebd523391bb8f6637a2f7.tar.gz
gcc-412bbe81d92ba9c32a2ebd523391bb8f6637a2f7.tar.bz2
re PR c++/33025 (Wrong calling of placement new with conditionals)
PR c++/33025 * init.c (build_new_1): Rename placement_var variable to placement_expr. Initialize it with save_expr rather than get_temp_regvar. * g++.dg/init/new23.C: New test. From-SVN: r127639
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/init.c15
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/init/new23.C20
4 files changed, 38 insertions, 8 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 3fd17c4..b12b785 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2007-08-20 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/33025
+ * init.c (build_new_1): Rename placement_var variable to placement_expr.
+ Initialize it with save_expr rather than get_temp_regvar.
+
2007-08-17 Andrew Pinski <andrew_pinski@playstation.sony.com>
PR c++/28989
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 08f8b76..3c74812 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -1656,7 +1656,7 @@ build_new_1 (tree placement, tree type, tree nelts, tree init,
beginning of the storage allocated for an array-new expression in
order to store the number of elements. */
tree cookie_size = NULL_TREE;
- tree placement_var;
+ tree placement_expr;
/* True if the function we are calling is a placement allocation
function. */
bool placement_allocation_fn_p;
@@ -1749,17 +1749,16 @@ build_new_1 (tree placement, tree type, tree nelts, tree init,
alloc_fn = NULL_TREE;
/* If PLACEMENT is a simple pointer type, then copy it into
- PLACEMENT_VAR. */
+ PLACEMENT_EXPR. */
if (processing_template_decl
|| placement == NULL_TREE
|| TREE_CHAIN (placement) != NULL_TREE
|| TREE_CODE (TREE_TYPE (TREE_VALUE (placement))) != POINTER_TYPE)
- placement_var = NULL_TREE;
+ placement_expr = NULL_TREE;
else
{
- placement_var = get_temp_regvar (TREE_TYPE (TREE_VALUE (placement)),
- TREE_VALUE (placement));
- placement = tree_cons (NULL_TREE, placement_var, NULL_TREE);
+ placement_expr = save_expr (TREE_VALUE (placement));
+ placement = tree_cons (NULL_TREE, placement_expr, NULL_TREE);
}
/* Allocate the object. */
@@ -1857,7 +1856,7 @@ build_new_1 (tree placement, tree type, tree nelts, tree init,
{
rval = build_nop (pointer_type, alloc_call);
if (placement != NULL)
- rval = avoid_placement_new_aliasing (rval, placement_var);
+ rval = avoid_placement_new_aliasing (rval, placement_expr);
return rval;
}
@@ -2122,7 +2121,7 @@ build_new_1 (tree placement, tree type, tree nelts, tree init,
gcc_assert (!lvalue_p (rval));
if (placement != NULL)
- rval = avoid_placement_new_aliasing (rval, placement_var);
+ rval = avoid_placement_new_aliasing (rval, placement_expr);
return rval;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 22e5df7..1c792ad 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2007-08-20 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/33025
+ * g++.dg/init/new23.C: New test.
+
2007-08-20 Andrew Pinski <andrew_pinski@playstation.sony.com>
PR middle-end/30564
diff --git a/gcc/testsuite/g++.dg/init/new23.C b/gcc/testsuite/g++.dg/init/new23.C
new file mode 100644
index 0000000..cedd898
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/new23.C
@@ -0,0 +1,20 @@
+// PR c++/33025
+// { dg-do run }
+// { dg-options "-O2" }
+
+typedef __SIZE_TYPE__ size_t;
+inline void *operator new (size_t, void *p) throw () { return p; }
+extern "C" void abort ();
+
+int
+main()
+{
+ const unsigned num = 10;
+ unsigned *data = new unsigned[2 * num];
+ unsigned *ptr = data;
+ for (unsigned i = 0; i < 2 * num; ++i)
+ (i % 2 == 0) ? new (ptr) unsigned (2) : new (ptr++) unsigned (1);
+ if (ptr - data != num)
+ abort ();
+ return 0;
+}