From patchwork Fri Jul 16 16:52:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 59116 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 A6730B6F11 for ; Sat, 17 Jul 2010 02:52:44 +1000 (EST) Received: (qmail 3103 invoked by alias); 16 Jul 2010 16:52:41 -0000 Received: (qmail 3092 invoked by uid 22791); 16 Jul 2010 16:52:40 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, TW_CX, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 16 Jul 2010 16:52:32 +0000 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o6GGqVcM012751 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 16 Jul 2010 12:52:31 -0400 Received: from redhat.com (vpn-10-125.rdu.redhat.com [10.11.10.125]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o6GGqRoS004334 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Fri, 16 Jul 2010 12:52:30 -0400 Date: Fri, 16 Jul 2010 12:52:27 -0400 From: Aldy Hernandez To: gcc-patches@gcc.gnu.org, rth@redhat.com Subject: [trans-mem] make work with C++ Message-ID: <20100716165227.GA21636@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-08-17) 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. was out of sync with the decls we were building in the C++ FE. In fixing this, I realized we were calling declare_nothrow_library_fn/etc regardless of if we had a global definition. This caused an ICE because somewhere down the call chain, we replaced olddecl with newdecl, and poisoned the old one. The way the library building works in the C++ FE is that we first check get_global_value_if_present() and only build the library decl if there's no previous definition (presumably in the header files). Tested on x86 32/64. OK for branch? libitm/ * libitm.h (_ITM_cxa_allocate_exception): Add malloc attribute. (_ITM_cxa_throw): Change argument type. * eh_cpp.cc (__cxa_throw): Same. (_ITM_cxa_throw): Same. gcc/ * cp/except.c (do_begin_catch): Do not build TM library call if already defined. (do_end_catch): Same. (do_allocate_exception): Same. (build_throw): Same. Index: libitm/libitm.h =================================================================== --- libitm/libitm.h (revision 162234) +++ libitm/libitm.h (working copy) @@ -33,7 +33,10 @@ #include #ifdef __cplusplus +#define THROW throw() extern "C" { +#else +#define THROW #endif #ifdef __i386__ @@ -278,8 +281,8 @@ extern void *_ITM_getTMCloneSafe (void * extern void _ITM_registerTMCloneTable (void *, size_t); extern void _ITM_deregisterTMCloneTable (void *); -extern void *_ITM_cxa_allocate_exception (size_t); -extern void _ITM_cxa_throw (void *obj, void *tinfo, void *dest); +extern void *_ITM_cxa_allocate_exception (size_t) THROW __attribute__((malloc)); +extern void _ITM_cxa_throw (void *obj, void *tinfo, void (*)(void*)); extern void *_ITM_cxa_begin_catch (void *exc_ptr); extern void _ITM_cxa_end_catch (void); extern void _ITM_commitTransactionEH(void *exc_ptr) ITM_REGPARM; Index: libitm/eh_cpp.cc =================================================================== --- libitm/eh_cpp.cc (revision 162234) +++ libitm/eh_cpp.cc (working copy) @@ -34,7 +34,7 @@ using namespace GTM; extern "C" { extern void *__cxa_allocate_exception (size_t) WEAK; -extern void __cxa_throw (void *, void *, void *) WEAK; +extern void __cxa_throw (void *, void *, void (*) (void*)) WEAK; extern void *__cxa_begin_catch (void *) WEAK; extern void *__cxa_end_catch (void) WEAK; extern void __cxa_tm_cleanup (void *, void *, unsigned int) WEAK; @@ -51,7 +51,7 @@ _ITM_cxa_allocate_exception (size_t size } void -_ITM_cxa_throw (void *obj, void *tinfo, void *dest) +_ITM_cxa_throw (void *obj, void *tinfo, void (*dest)(void*)) { gtm_tx()->cxa_unthrown = NULL; __cxa_throw (obj, tinfo, dest); Index: libitm/testsuite/libitm.c++/throwdown.C =================================================================== --- libitm/testsuite/libitm.c++/throwdown.C (revision 0) +++ libitm/testsuite/libitm.c++/throwdown.C (revision 0) @@ -0,0 +1,13 @@ +// { dg-do compile } + +#include + +static void throwit() { + throw 1; +} + +void tranfunc() { + __transaction { + throwit(); + } +} Index: gcc/cp/except.c =================================================================== --- gcc/cp/except.c (revision 161318) +++ gcc/cp/except.c (working copy) @@ -209,7 +209,9 @@ do_begin_catch (void) if (flag_tm) { tree fn2 = get_identifier ("_ITM_cxa_begin_catch"); - fn2 = declare_nothrow_library_fn (fn2, ptr_type_node, ptr_type_node); + if (!get_global_value_if_present (fn2, &fn2)) + fn2 = declare_nothrow_library_fn (fn2, ptr_type_node, + ptr_type_node); record_tm_replacement (fn, fn2); } } @@ -257,8 +259,11 @@ do_end_catch (tree type) if (flag_tm) { tree fn2 = get_identifier ("_ITM_cxa_end_catch"); - fn2 = push_void_library_fn (fn2, void_list_node); - TREE_NOTHROW (fn2) = 0; + if (!get_global_value_if_present (fn2, &fn2)) + { + fn2 = push_void_library_fn (fn2, void_list_node); + TREE_NOTHROW (fn2) = 0; + } record_tm_replacement (fn, fn2); } } @@ -576,7 +581,9 @@ do_allocate_exception (tree type) if (flag_tm) { tree fn2 = get_identifier ("_ITM_cxa_allocate_exception"); - fn2 = declare_nothrow_library_fn (fn2, ptr_type_node, size_type_node); + if (!get_global_value_if_present (fn2, &fn2)) + fn2 = declare_nothrow_library_fn (fn2, ptr_type_node, + size_type_node); record_tm_replacement (fn, fn2); } } @@ -718,7 +725,8 @@ build_throw (tree exp) if (flag_tm) { tree fn2 = get_identifier ("_ITM_cxa_throw"); - fn2 = push_throw_library_fn (fn2, tmp); + if (!get_global_value_if_present (fn2, &fn2)) + fn2 = push_throw_library_fn (fn2, tmp); record_tm_replacement (fn, fn2); } }