From patchwork Fri Jan 31 21:24:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 315841 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 9D3F22C00AE for ; Sat, 1 Feb 2014 08:24:37 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=VZgc8PBj8Jxkf7w6TUkxt9G63PM/K Cs24CS3XTm8M+8BFbT+JU38LWPF7U1+/gDeRmFAPVdoGjZH1CGLWbEkoCv1Pn1bT HC7kSOJBPijP6g8pWu/Twnd7T7gZCizpNrrGvtOHdXP3wqICbSzo+J+bO6sNx5nu kA2gwLbgcWPiVQ= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=aKTGA0O6giPR8TS0WcMXJ2V+g8c=; b=kZJ fLBZ4Nrr+8WysNIkDHnNpTqi8l3CACyZYf6mCp5iaf2E7wyjlaR/DHfLeQ0PjjE2 Om6QxrI6SvR96IPSiy/MEyjB3y0z3JPDqfTQaQAG9K+4mUAjZ3USHavVO73/8+w1 mUMmvhAqMb4FCLlLnFB1QTTRcvvI5lHEhVUQDMtw= Received: (qmail 30634 invoked by alias); 31 Jan 2014 21:24:28 -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 30624 invoked by uid 89); 31 Jan 2014 21:24:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.9 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 31 Jan 2014 21:24:26 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s0VLOPu5005944 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 31 Jan 2014 16:24:25 -0500 Received: from tucnak.zalov.cz (vpn1-6-223.ams2.redhat.com [10.36.6.223]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s0VLON5v000436 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 31 Jan 2014 16:24:24 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.14.7/8.14.7) with ESMTP id s0VLOMds031534; Fri, 31 Jan 2014 22:24:22 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.14.7/8.14.7/Submit) id s0VLOM0l031533; Fri, 31 Jan 2014 22:24:22 +0100 Date: Fri, 31 Jan 2014 22:24:22 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix __builtin_setjmp handling (PR tree-optimization/60003) Message-ID: <20140131212422.GZ892@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Hi! As described in the PR, __builtin_setjmp_receiver isn't declared to returns_twice, and thus after dce cfun->calls_setjmp might be no longer true. At RTL __builtin_setjmp_receiver is handled as non-local label, so this patch just forces cfun->has_nonlocal_label already in GIMPLE, so that e.g. the inliner still sees stmt_can_make_nonlocal_goto. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2014-01-31 Jakub Jelinek PR tree-optimization/60003 * gimple-low.c (lower_builtin_setjmp): Set cfun->has_nonlocal_label. * profile.c (branch_prob): Use gimple_call_builtin_p to check for BUILT_IN_SETJMP_RECEIVER. * tree-inline.c (copy_bb): Call notice_special_calls. * gcc.c-torture/execute/pr60003.c: New test. Jakub --- gcc/gimple-low.c.jj 2014-01-29 12:43:25.000000000 +0100 +++ gcc/gimple-low.c 2014-01-31 10:02:38.843026680 +0100 @@ -709,6 +709,12 @@ lower_builtin_setjmp (gimple_stmt_iterat tree dest, t, arg; gimple g; + /* __builtin_setjmp_{setup,receiver} aren't ECF_RETURNS_TWICE and for RTL + these builtins are modelled as non-local label jumps to the label + that is passed to these two builtins, so pretend we have a non-local + label during GIMPLE passes too. See PR60003. */ + cfun->has_nonlocal_label = true; + /* NEXT_LABEL is the label __builtin_longjmp will jump to. Its address is passed to both __builtin_setjmp_setup and __builtin_setjmp_receiver. */ FORCED_LABEL (next_label) = 1; --- gcc/profile.c.jj 2014-01-29 12:43:25.000000000 +0100 +++ gcc/profile.c 2014-01-31 10:18:00.450198256 +0100 @@ -1104,7 +1104,6 @@ branch_prob (void) { gimple_stmt_iterator gsi; gimple first; - tree fndecl; gsi = gsi_start_nondebug_after_labels_bb (bb); gcc_checking_assert (!gsi_end_p (gsi)); @@ -1114,10 +1113,7 @@ branch_prob (void) special and don't expect anything to be inserted before them. */ if (is_gimple_call (first) - && (((fndecl = gimple_call_fndecl (first)) != NULL - && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL - && (DECL_FUNCTION_CODE (fndecl) - == BUILT_IN_SETJMP_RECEIVER)) + && (gimple_call_builtin_p (first, BUILT_IN_SETJMP_RECEIVER) || (gimple_call_flags (first) & ECF_RETURNS_TWICE) || (gimple_call_internal_p (first) && (gimple_call_internal_fn (first) --- gcc/tree-inline.c.jj 2014-01-29 12:43:24.000000000 +0100 +++ gcc/tree-inline.c 2014-01-31 10:19:13.849815593 +0100 @@ -1745,7 +1745,6 @@ copy_bb (copy_body_data *id, basic_block if (is_gimple_call (stmt)) { struct cgraph_edge *edge; - int flags; switch (id->transform_call_graph_edges) { @@ -1868,11 +1867,7 @@ copy_bb (copy_body_data *id, basic_block } } - flags = gimple_call_flags (stmt); - if (flags & ECF_MAY_BE_ALLOCA) - cfun->calls_alloca = true; - if (flags & ECF_RETURNS_TWICE) - cfun->calls_setjmp = true; + notice_special_calls (stmt); } maybe_duplicate_eh_stmt_fn (cfun, stmt, id->src_cfun, orig_stmt, --- gcc/testsuite/gcc.c-torture/execute/pr60003.c.jj 2014-01-31 10:05:15.095205547 +0100 +++ gcc/testsuite/gcc.c-torture/execute/pr60003.c 2014-01-31 10:04:59.000000000 +0100 @@ -0,0 +1,48 @@ +/* PR tree-optimization/60003 */ + +extern void abort (void); + +unsigned long long jmp_buf[5]; + +__attribute__((noinline, noclone)) void +baz (void) +{ + __builtin_longjmp (&jmp_buf, 1); +} + +void +bar (void) +{ + baz (); +} + +__attribute__((noinline, noclone)) int +foo (int x) +{ + int a = 0; + + if (__builtin_setjmp (&jmp_buf) == 0) + { + while (1) + { + a = 1; + bar (); /* OK if baz () instead */ + } + } + else + { + if (a == 0) + return 0; + else + return x; + } +} + +int +main () +{ + if (foo (1) == 0) + abort (); + + return 0; +}