From patchwork Wed Oct 12 11:26:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 119185 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id E8350B6F6F for ; Wed, 12 Oct 2011 22:28:56 +1100 (EST) Received: (qmail 4643 invoked by alias); 12 Oct 2011 11:28:53 -0000 Received: (qmail 4632 invoked by uid 22791); 12 Oct 2011 11:28:50 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from acsinet15.oracle.com (HELO acsinet15.oracle.com) (141.146.126.227) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 12 Oct 2011 11:28:33 +0000 Received: from ucsinet23.oracle.com (ucsinet23.oracle.com [156.151.31.71]) by acsinet15.oracle.com (Switch-3.4.4/Switch-3.4.4) with ESMTP id p9CBSUIO029531 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Wed, 12 Oct 2011 11:28:32 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by ucsinet23.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id p9CBSTxT023152 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 12 Oct 2011 11:28:30 GMT Received: from abhmt110.oracle.com (abhmt110.oracle.com [141.146.116.62]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id p9CBSO41019440; Wed, 12 Oct 2011 06:28:24 -0500 Received: from [192.168.1.4] (/79.52.211.215) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 12 Oct 2011 04:28:24 -0700 Message-ID: <4E95797E.5040904@oracle.com> Date: Wed, 12 Oct 2011 13:26:54 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] PR 50594 (C++ front-end bits) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, thus, per the discussion in the audit trail, I'm proceeding with decorating with __attribute__((externally_visible)) both the 8 new and delete in , and the 4 pre-declared by the C++ front-end. The below is what I regression tested successfully, together with the library bits, on x86_64-linux. I'm also attaching, for convenience, the library work (I took the occasion to adjust noexcept vs throw(), etc, otherwise the patch would be tiny) What do you think? Thanks, Paolo. //////////////////////// 2011-10-12 Paolo Carlini PR c++/50594 * decl.c (cxx_init_decl_processing): Add __attribute__((externally_visible)) to operator new and operator delete library fn. Index: include/bits/c++config =================================================================== --- include/bits/c++config (revision 179842) +++ include/bits/c++config (working copy) @@ -103,9 +103,11 @@ # ifdef __GXX_EXPERIMENTAL_CXX0X__ # define _GLIBCXX_NOEXCEPT noexcept # define _GLIBCXX_USE_NOEXCEPT noexcept +# define _GLIBCXX_THROW(_EXC) # else # define _GLIBCXX_NOEXCEPT # define _GLIBCXX_USE_NOEXCEPT throw() +# define _GLIBCXX_THROW(_EXC) throw(_EXC) # endif #endif Index: libsupc++/del_op.cc =================================================================== --- libsupc++/del_op.cc (revision 179842) +++ libsupc++/del_op.cc (working copy) @@ -1,6 +1,7 @@ // Boilerplate support routines for -*- C++ -*- dynamic memory management. -// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2007, 2009 Free Software Foundation +// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2007, 2009, 2010, 2011 +// Free Software Foundation // // This file is part of GCC. // @@ -41,7 +42,7 @@ #include "new" _GLIBCXX_WEAK_DEFINITION void -operator delete(void* ptr) throw () +operator delete(void* ptr) _GLIBCXX_USE_NOEXCEPT { if (ptr) std::free(ptr); Index: libsupc++/new_opv.cc =================================================================== --- libsupc++/new_opv.cc (revision 179842) +++ libsupc++/new_opv.cc (working copy) @@ -1,6 +1,7 @@ // Boilerplate support routines for -*- C++ -*- dynamic memory management. -// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009 Free Software Foundation +// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009, 2010, 2011 +// Free Software Foundation // // This file is part of GCC. // @@ -27,7 +28,7 @@ #include "new" _GLIBCXX_WEAK_DEFINITION void* -operator new[] (std::size_t sz) throw (std::bad_alloc) +operator new[] (std::size_t sz) _GLIBCXX_THROW (std::bad_alloc) { return ::operator new(sz); } Index: libsupc++/new_op.cc =================================================================== --- libsupc++/new_op.cc (revision 179842) +++ libsupc++/new_op.cc (working copy) @@ -42,7 +42,7 @@ extern new_handler __new_handler; _GLIBCXX_WEAK_DEFINITION void * -operator new (std::size_t sz) throw (std::bad_alloc) +operator new (std::size_t sz) _GLIBCXX_THROW (std::bad_alloc) { void *p; Index: libsupc++/del_opv.cc =================================================================== --- libsupc++/del_opv.cc (revision 179842) +++ libsupc++/del_opv.cc (working copy) @@ -1,6 +1,7 @@ // Boilerplate support routines for -*- C++ -*- dynamic memory management. -// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009 Free Software Foundation +// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009, 2010, 2011 +// Free Software Foundation // // This file is part of GCC. // @@ -27,7 +28,7 @@ #include "new" _GLIBCXX_WEAK_DEFINITION void -operator delete[] (void *ptr) throw () +operator delete[] (void *ptr) _GLIBCXX_USE_NOEXCEPT { ::operator delete (ptr); } Index: libsupc++/del_opnt.cc =================================================================== --- libsupc++/del_opnt.cc (revision 179842) +++ libsupc++/del_opnt.cc (working copy) @@ -1,6 +1,7 @@ // Boilerplate support routines for -*- C++ -*- dynamic memory management. -// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009 Free Software Foundation +// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009, 2010, 2011 +// Free Software Foundation // // This file is part of GCC. // @@ -29,7 +30,7 @@ extern "C" void free (void *); _GLIBCXX_WEAK_DEFINITION void -operator delete (void *ptr, const std::nothrow_t&) throw () +operator delete (void *ptr, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT { free (ptr); } Index: libsupc++/new =================================================================== --- libsupc++/new (revision 179842) +++ libsupc++/new (working copy) @@ -1,7 +1,7 @@ // The -*- C++ -*- dynamic memory management header. // Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -// 2003, 2004, 2005, 2006, 2007, 2009, 2010 +// 2003, 2004, 2005, 2006, 2007, 2009, 2010, 2011 // Free Software Foundation // This file is part of GCC. @@ -90,22 +90,32 @@ * Placement new and delete signatures (take a memory address argument, * does nothing) may not be replaced by a user's program. */ -void* operator new(std::size_t) throw (std::bad_alloc); -void* operator new[](std::size_t) throw (std::bad_alloc); -void operator delete(void*) throw(); -void operator delete[](void*) throw(); -void* operator new(std::size_t, const std::nothrow_t&) throw(); -void* operator new[](std::size_t, const std::nothrow_t&) throw(); -void operator delete(void*, const std::nothrow_t&) throw(); -void operator delete[](void*, const std::nothrow_t&) throw(); +void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc) + __attribute__((__externally_visible__)); +void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc) + __attribute__((__externally_visible__)); +void operator delete(void*) _GLIBCXX_USE_NOEXCEPT + __attribute__((__externally_visible__)); +void operator delete[](void*) _GLIBCXX_USE_NOEXCEPT + __attribute__((__externally_visible__)); +void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT + __attribute__((__externally_visible__)); +void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT + __attribute__((__externally_visible__)); +void operator delete(void*, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT + __attribute__((__externally_visible__)); +void operator delete[](void*, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT + __attribute__((__externally_visible__)); // Default placement versions of operator new. -inline void* operator new(std::size_t, void* __p) throw() { return __p; } -inline void* operator new[](std::size_t, void* __p) throw() { return __p; } +inline void* operator new(std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT +{ return __p; } +inline void* operator new[](std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT +{ return __p; } // Default placement versions of operator delete. -inline void operator delete (void*, void*) throw() { } -inline void operator delete[](void*, void*) throw() { } +inline void operator delete (void*, void*) _GLIBCXX_USE_NOEXCEPT { } +inline void operator delete[](void*, void*) _GLIBCXX_USE_NOEXCEPT { } //@} } // extern "C++" Index: libsupc++/new_opvnt.cc =================================================================== --- libsupc++/new_opvnt.cc (revision 179842) +++ libsupc++/new_opvnt.cc (working copy) @@ -1,6 +1,7 @@ // Boilerplate support routines for -*- C++ -*- dynamic memory management. -// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009 Free Software Foundation +// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009, 2010, 2011 +// Free Software Foundation // // This file is part of GCC. // @@ -27,7 +28,8 @@ #include "new" _GLIBCXX_WEAK_DEFINITION void* -operator new[] (std::size_t sz, const std::nothrow_t& nothrow) throw() +operator new[] (std::size_t sz, const std::nothrow_t& nothrow) + _GLIBCXX_USE_NOEXCEPT { return ::operator new(sz, nothrow); } Index: libsupc++/new_opnt.cc =================================================================== --- libsupc++/new_opnt.cc (revision 179842) +++ libsupc++/new_opnt.cc (working copy) @@ -34,7 +34,7 @@ extern new_handler __new_handler; _GLIBCXX_WEAK_DEFINITION void * -operator new (std::size_t sz, const std::nothrow_t&) throw() +operator new (std::size_t sz, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT { void *p; Index: libsupc++/del_opvnt.cc =================================================================== --- libsupc++/del_opvnt.cc (revision 179842) +++ libsupc++/del_opvnt.cc (working copy) @@ -1,6 +1,7 @@ // Boilerplate support routines for -*- C++ -*- dynamic memory management. -// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009 Free Software Foundation +// Copyright (C) 1997, 1998, 1999, 2000, 2004, 2009, 2010, 2011 +// Free Software Foundation // // This file is part of GCC. // @@ -27,7 +28,7 @@ #include "new" _GLIBCXX_WEAK_DEFINITION void -operator delete[] (void *ptr, const std::nothrow_t&) throw () +operator delete[] (void *ptr, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT { ::operator delete (ptr); } Index: testsuite/18_support/50594.cc =================================================================== --- testsuite/18_support/50594.cc (revision 0) +++ testsuite/18_support/50594.cc (revision 0) @@ -0,0 +1,72 @@ +// { dg-options "-fwhole-program" } + +// Copyright (C) 2011 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include + +bool user_new_called; +bool user_delete_called; + +void* operator new(std::size_t n) +#ifndef __GXX_EXPERIMENTAL_CXX0X__ + throw(std::bad_alloc) +#endif +{ + user_new_called = true; + + void* p = std::malloc(n); + + if (!p) + throw std::bad_alloc(); + + return p; +} + +void operator delete(void* p) +#ifdef __GXX_EXPERIMENTAL_CXX0X__ + noexcept +#else + throw() +#endif +{ + user_delete_called = true; + + std::free(p); +} + +// libstdc++/50594 +void test01() +{ + bool test __attribute__((unused)) = true; + + { + std::string s = "Hello World."; + } + + VERIFY( user_new_called ); + VERIFY( user_delete_called ); +} + +int main() +{ + test01(); + return 0; +} Index: decl.c =================================================================== --- decl.c (revision 179842) +++ decl.c (working copy) @@ -3654,7 +3654,7 @@ cxx_init_decl_processing (void) current_lang_name = lang_name_cplusplus; { - tree newattrs; + tree newattrs, delattrs; tree newtype, deltype; tree ptr_ftype_sizetype; tree new_eh_spec; @@ -3687,9 +3687,16 @@ cxx_init_decl_processing (void) newattrs = build_tree_list (get_identifier ("alloc_size"), build_tree_list (NULL_TREE, integer_one_node)); + newattrs + = chainon (newattrs, build_tree_list + (get_identifier ("externally_visible"), NULL_TREE)); newtype = cp_build_type_attribute_variant (ptr_ftype_sizetype, newattrs); newtype = build_exception_variant (newtype, new_eh_spec); - deltype = build_exception_variant (void_ftype_ptr, empty_except_spec); + delattrs + = build_tree_list (get_identifier ("externally_visible"), + build_tree_list (NULL_TREE, integer_one_node)); + deltype = cp_build_type_attribute_variant (void_ftype_ptr, delattrs); + deltype = build_exception_variant (deltype, empty_except_spec); push_cp_library_fn (NEW_EXPR, newtype); push_cp_library_fn (VEC_NEW_EXPR, newtype); global_delete_fndecl = push_cp_library_fn (DELETE_EXPR, deltype);