From patchwork Tue Apr 21 07:10:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 463004 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2E7A0140142 for ; Tue, 21 Apr 2015 17:10:59 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=bjBGkkOR; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; q=dns; s=default; b=x50lP4lbpRx8ptsQljaZo+NogiZtJ16vT/vPrYW0Na5 V62DXE4T2do89YGm1fY/6N2gmgI/69UbVZG2gX2oyCdMgIZcXLUonXdGltH0ncL7 u2DRE0ABZqNWidGHXLbD6Naj+fzpDCT4+zvh/p1wogQuYrAAlQ4/R6Nz9Ay4orZU = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:cc:subject:content-type; s=default; bh=M4I5vMrvoMwECpyiuejCm4KquiU=; b=bjBGkkOR5I3/YisUV VZaedpAqu3c9DKkDvc3240NpMM/PJhn+j999nfF4o4qtPn86t2zEfbl/9r5QWGU1 robEvjJIvTSM/iA3cnwqXx7D5r0rbuV3lBbLQlSPpc74spNMQyuLkKek8MU2ttvy kgNrhdWDC+fHABatyBgURplslQ= Received: (qmail 88487 invoked by alias); 21 Apr 2015 07:10:50 -0000 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 Received: (qmail 87431 invoked by uid 89); 21 Apr 2015 07:10:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 21 Apr 2015 07:10:47 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-FEM-01.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1YkSKR-0006cX-4K from Tom_deVries@mentor.com ; Tue, 21 Apr 2015 00:10:43 -0700 Received: from [127.0.0.1] (137.202.0.76) by SVR-IES-FEM-01.mgc.mentorg.com (137.202.0.104) with Microsoft SMTP Server id 14.3.224.2; Tue, 21 Apr 2015 08:10:41 +0100 Message-ID: <5535F7EF.1000305@mentor.com> Date: Tue, 21 Apr 2015 09:10:39 +0200 From: Tom de Vries User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Richard Biener CC: GCC Patches Subject: [PATCH][PR65802] Mark ifn_va_arg with ECF_NOTHROW Hi, this patch fixes PR65802. The problem described in PR65802 is that when compiling the test-case (included in the patch below) at -O0, the compiler runs into a gcc_assert ICE in redirect_eh_edge_1 during pass_cleanup_eh: ... gcc_assert (lookup_stmt_eh_lp (throw_stmt) == old_lp_nr); ... In more detail, during compilation the ifn_va_arg is marked at as a throwing function. That causes exception handling code to be generated, with exception handling edges: ... ;; basic block 2, loop depth 0, count 0, freq 0, maybe hot ;; prev block 0, next block 3, flags: (NEW, REACHABLE) ;; pred: ENTRY (FALLTHRU) [LP 1] # .MEM_5 = VDEF <.MEM_4(D)> # USE = anything # CLB = anything _6 = VA_ARG (&cD.2333, 0B); ;; succ: 7 (EH) ;; 3 (FALLTHRU) ... After pass_lower_vaarg, the expansion of ifn_va_arg is spread over several basic blocks: ... ;; basic block 2, loop depth 0, count 0, freq 0, maybe hot ;; prev block 0, next block 11, flags: (NEW, REACHABLE) ;; pred: ENTRY (FALLTHRU) ;; succ: 11 [100.0%] (FALLTHRU) ;; basic block 11, loop depth 0, count 0, freq 0, maybe hot ;; prev block 2, next block 12, flags: (NEW) ;; pred: 2 [100.0%] (FALLTHRU) # VUSE <.MEM_4(D)> _22 = cD.2333.gp_offsetD.5; if (_22 >= 48) goto (); else goto (); ;; succ: 13 (TRUE_VALUE) ;; 12 (FALSE_VALUE) ;; basic block 12, loop depth 0, count 0, freq 0, maybe hot ;; prev block 11, next block 13, flags: (NEW) ;; pred: 11 (FALSE_VALUE) : # VUSE <.MEM_4(D)> _23 = cD.2333.reg_save_areaD.8; # VUSE <.MEM_4(D)> _24 = cD.2333.gp_offsetD.5; _25 = (sizetype) _24; addr.1_26 = _23 + _25; # VUSE <.MEM_4(D)> _27 = cD.2333.gp_offsetD.5; _28 = _27 + 8; # .MEM_29 = VDEF <.MEM_4(D)> cD.2333.gp_offsetD.5 = _28; goto (); ;; succ: 14 (FALLTHRU) ;; basic block 13, loop depth 0, count 0, freq 0, maybe hot ;; prev block 12, next block 14, flags: (NEW) ;; pred: 11 (TRUE_VALUE) : # VUSE <.MEM_4(D)> _30 = cD.2333.overflow_arg_areaD.7; addr.1_31 = _30; _32 = _30 + 8; # .MEM_33 = VDEF <.MEM_4(D)> cD.2333.overflow_arg_areaD.7 = _32; ;; succ: 14 (FALLTHRU) ;; basic block 14, loop depth 0, count 0, freq 0, maybe hot ;; prev block 13, next block 15, flags: (NEW) ;; pred: 12 (FALLTHRU) ;; 13 (FALLTHRU) # .MEM_20 = PHI <.MEM_29(12), .MEM_33(13)> # addr.1_21 = PHI : # VUSE <.MEM_20> _6 = MEM[(intD.9 * * {ref-all})addr.1_21]; ;; succ: 15 (FALLTHRU) ;; basic block 15, loop depth 0, count 0, freq 0, maybe hot ;; prev block 14, next block 3, flags: (NEW) ;; pred: 14 (FALLTHRU) ;; succ: 7 (EH) ;; 3 (FALLTHRU) ... And an ICE is triggered in redirect_eh_edge_1, because the code expects the last statement in a BB with an outgoing EH edge to be a throwing statement. That's obviously not the case, since bb15 is empty. But also all the other statements in the expansion are non-throwing. Looking at the representation before the ifn_va_arg, VA_ARG_EXPR is non-throwing (even with -fnon-call-exceptions). And looking at the situation before the introduction of ifn_va_arg, the expansion of VA_ARG_EXPR also didn't contain any throwing statements. This patch fixes the ICE by marking ifn_va_arg with ECF_NOTHROW. Bootstrapped and reg-tested on x86_64. OK for trunk? Thanks, - Tom Mark ifn_va_arg with ECF_NOTHROW 2015-04-20 Tom de Vries PR tree-optimization/65802 * internal-fn.def (VA_ARG): Add ECF_NOTROW to flags. * g++.dg/pr65802.C: New test. --- gcc/internal-fn.def | 2 +- gcc/testsuite/g++.dg/pr65802.C | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/pr65802.C diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def index f557c64..7e19313 100644 --- a/gcc/internal-fn.def +++ b/gcc/internal-fn.def @@ -62,4 +62,4 @@ DEF_INTERNAL_FN (ADD_OVERFLOW, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL) DEF_INTERNAL_FN (SUB_OVERFLOW, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL) DEF_INTERNAL_FN (MUL_OVERFLOW, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL) DEF_INTERNAL_FN (TSAN_FUNC_EXIT, ECF_NOVOPS | ECF_LEAF | ECF_NOTHROW, NULL) -DEF_INTERNAL_FN (VA_ARG, 0, NULL) +DEF_INTERNAL_FN (VA_ARG, ECF_NOTHROW, NULL) diff --git a/gcc/testsuite/g++.dg/pr65802.C b/gcc/testsuite/g++.dg/pr65802.C new file mode 100644 index 0000000..26e5317 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr65802.C @@ -0,0 +1,29 @@ +// { dg-do compile } +// { dg-options "-O0" } + +typedef int tf (); + +struct S +{ + tf m_fn1; +} a; + +void +fn1 () +{ + try + { + __builtin_va_list c; + { + int *d = __builtin_va_arg (c, int *); + int **e = &d; + __asm__("" : "=d"(e)); + a.m_fn1 (); + } + a.m_fn1 (); + } + catch (...) + { + + } +} -- 1.9.1