Commit 8f2b097e by Ville Voutilainen Committed by Ville Voutilainen

Remove the null check from placement new in all modes

gcc/cp/

Remove the null check from placement new in all modes
* init.c (build_new_1): Don't do a null check for
a namespace-scope non-replaceable placement new
in any mode unless -fcheck-new is provided.

testsuite/

Remove the null check from placement new in all modes
* g++.dg/init/pr35878_1.C: Adjust.
* g++.dg/init/pr35878_4.C: New.
* g++.dg/torture/pr48695.C: Adjust.
* g++.dg/tree-ssa/pr31146-2.C: Likewise.
* g++.dg/tree-ssa/pr41428.C: Adjust.

From-SVN: r254694
parent 81766d13
2017-11-13 Ville Voutilainen <ville.voutilainen@gmail.com>
Remove the null check from placement new in all modes
* init.c (build_new_1): Don't do a null check for
a namespace-scope non-replaceable placement new
in any mode unless -fcheck-new is provided.
2017-11-07 Boris Kolpackov <boris@codesynthesis.com>
* Make-lang.in (CP_PLUGIN_HEADERS): Add operators.def since included
......
......@@ -2758,7 +2758,7 @@ malloc_alignment ()
static bool
std_placement_new_fn_p (tree alloc_fn)
{
if ((cxx_dialect > cxx14) && DECL_NAMESPACE_SCOPE_P (alloc_fn))
if (DECL_NAMESPACE_SCOPE_P (alloc_fn))
{
tree first_arg = TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (alloc_fn)));
if ((TREE_VALUE (first_arg) == ptr_type_node)
......
// PR c++/35878
// { dg-do compile }
// { dg-options "-O2 -std=gnu++11 -fdump-tree-optimized" }
// { dg-final { scan-tree-dump-times "v_\[0-9]+\\(D\\) \[=!]= 0" 1 "optimized" } }
// { dg-final { scan-tree-dump-not "v_\[0-9]+\\(D\\) \[=!]= 0" "optimized" } }
#include <new>
#include <utility>
......
// PR c++/35878
// { dg-do compile }
// { dg-options "-O2 -std=gnu++11 -fcheck-new -fdump-tree-optimized" }
// { dg-final { scan-tree-dump-times "v_\[0-9]+\\(D\\) \[=!]= 0" 1 "optimized" } }
#include <new>
#include <utility>
struct s1{
int a;
int b;
int c;
};
void f1 (s1 * v, s1&& s)
{
new (v) s1(std::move(s));
}
void f2 (s1 * v, s1&& s)
{
*v = std::move(s);
}
// { dg-do run }
/* { dg-options "-fcheck-new" } */
typedef __SIZE_TYPE__ size_t;
......
/* { dg-do compile } */
/* { dg-options "-O -fno-tree-vrp -fdump-tree-forwprop1" } */
/* { dg-options "-O -fcheck-new -fno-tree-vrp -fdump-tree-forwprop1" } */
#include <new>
......@@ -20,6 +20,5 @@ double foo (void)
return v.a[2];
}
/* -std=c++17 and above doesn't emit operator new () != NULL, so there is
nothing to fold anymore. */
/* { dg-final { scan-tree-dump "Replaced .* != 0B. with .1" "forwprop1" { target c++14_down } } } */
/* GCC 8 emits operator new () != NULL with -fcheck-new. */
/* { dg-final { scan-tree-dump "Replaced .* != 0B. with .1" "forwprop1" } } */
/* { dg-do compile } */
/* { dg-options "-O -fdump-tree-ccp1-details" } */
/* { dg-options "-O -fcheck-new -fdump-tree-ccp1-details" } */
extern "C" void abort (void);
inline void *operator new (__SIZE_TYPE__, void *__p) throw () { return __p; }
......@@ -11,6 +11,5 @@ int foo(void)
return *(int *)&f;
}
/* -std=c++17 and above doesn't emit operator new () != NULL, so there is
nothing to fold anymore. */
/* { dg-final { scan-tree-dump "Folded into: if \\\(1 != 0\\\)" "ccp1" { target c++14_down } } } */
/* GCC 8 emits operator new () != NULL with -fcheck-new. */
/* { dg-final { scan-tree-dump "Folded into: if \\\(1 != 0\\\)" "ccp1" } } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment