From: Ville Voutilainen Date: Mon, 13 Nov 2017 17:02:06 +0000 (+0200) Subject: Remove the null check from placement new in all modes X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8f2b097ed54816d28cd51254c8e4616404ae348e;p=gcc.git 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 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index df912013756..73fa99967ed 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2017-11-13 Ville Voutilainen + + 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 * Make-lang.in (CP_PLUGIN_HEADERS): Add operators.def since included diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 9e6e3aff779..1fcd91d108d 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -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) diff --git a/gcc/testsuite/g++.dg/init/pr35878_1.C b/gcc/testsuite/g++.dg/init/pr35878_1.C index e2fc4933425..7fb3221a327 100644 --- a/gcc/testsuite/g++.dg/init/pr35878_1.C +++ b/gcc/testsuite/g++.dg/init/pr35878_1.C @@ -1,7 +1,7 @@ // 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 #include diff --git a/gcc/testsuite/g++.dg/init/pr35878_4.C b/gcc/testsuite/g++.dg/init/pr35878_4.C new file mode 100644 index 00000000000..bd275655a63 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/pr35878_4.C @@ -0,0 +1,23 @@ +// 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 +#include + +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); +} diff --git a/gcc/testsuite/g++.dg/torture/pr48695.C b/gcc/testsuite/g++.dg/torture/pr48695.C index 44e6c771dba..2f2953d9999 100644 --- a/gcc/testsuite/g++.dg/torture/pr48695.C +++ b/gcc/testsuite/g++.dg/torture/pr48695.C @@ -1,4 +1,5 @@ // { dg-do run } +/* { dg-options "-fcheck-new" } */ typedef __SIZE_TYPE__ size_t; diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr31146-2.C b/gcc/testsuite/g++.dg/tree-ssa/pr31146-2.C index 500d8b639ee..9fb5dc1b60c 100644 --- a/gcc/testsuite/g++.dg/tree-ssa/pr31146-2.C +++ b/gcc/testsuite/g++.dg/tree-ssa/pr31146-2.C @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-O -fno-tree-vrp -fdump-tree-forwprop1" } */ +/* { dg-options "-O -fcheck-new -fno-tree-vrp -fdump-tree-forwprop1" } */ #include @@ -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" } } */ diff --git a/gcc/testsuite/g++.dg/tree-ssa/pr41428.C b/gcc/testsuite/g++.dg/tree-ssa/pr41428.C index c0a5eb627be..7aff519e746 100644 --- a/gcc/testsuite/g++.dg/tree-ssa/pr41428.C +++ b/gcc/testsuite/g++.dg/tree-ssa/pr41428.C @@ -1,5 +1,5 @@ /* { 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" } } */