From patchwork Fri Sep 16 21:13:21 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 115061 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 43691B71AB for ; Sat, 17 Sep 2011 07:13:48 +1000 (EST) Received: (qmail 26447 invoked by alias); 16 Sep 2011 21:13:45 -0000 Received: (qmail 26184 invoked by uid 22791); 16 Sep 2011 21:13:43 -0000 X-SWARE-Spam-Status: No, hits=-6.6 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_CX, TW_FN 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 Sep 2011 21:13:24 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p8GLDO3Z015312 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 16 Sep 2011 17:13:24 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p8GLDNZS028548 for ; Fri, 16 Sep 2011 17:13:23 -0400 Received: from [0.0.0.0] ([10.3.113.16]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p8GLDMt1024334 for ; Fri, 16 Sep 2011 17:13:22 -0400 Message-ID: <4E73BBF1.2050806@redhat.com> Date: Fri, 16 Sep 2011 17:13:21 -0400 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:6.0.2) Gecko/20110906 Thunderbird/6.0.2 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/50424 (wrong code with throwing default argument) 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 We collect information about whether a function can throw as we compile the function: if we build up a call that can throw, then the current function can throw, too. But we weren't doing the same for default arguments used in a call, which might themselves contain calls that can throw. Tested x86_64-pc-linux-gnu, applying to trunk and a smaller patch to 4.6. commit d4880772f234b9c86b0af79954ea88f2134fbaa4 Author: Jason Merrill Date: Fri Sep 16 16:14:59 2011 -0400 PR c++/50424 * tree.c (bot_manip): Set cp_function_chain->can_throw. diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 1fa32a0..7e7b34b 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -1861,7 +1861,11 @@ bot_manip (tree* tp, int* walk_subtrees, void* data) } /* Make a copy of this node. */ - return copy_tree_r (tp, walk_subtrees, NULL); + t = copy_tree_r (tp, walk_subtrees, NULL); + if (TREE_CODE (*tp) == CALL_EXPR && !TREE_NOTHROW (*tp) + && cfun && cp_function_chain) + cp_function_chain->can_throw = 1; + return t; } /* Replace all remapped VAR_DECLs in T with their new equivalents. diff --git a/gcc/testsuite/g++.dg/eh/defarg1.C b/gcc/testsuite/g++.dg/eh/defarg1.C new file mode 100644 index 0000000..5c6e4df --- /dev/null +++ b/gcc/testsuite/g++.dg/eh/defarg1.C @@ -0,0 +1,10 @@ +// PR c++/50424 +// { dg-do run } + +int f() { throw 1; } +void g( int = f() ) { } +void h() { g(); } +int main() +{ + try { h(); } catch (int) { } +}