From patchwork Thu Apr 26 14:29:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 905096 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-476858-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="YUTIm+OG"; dkim-atps=neutral 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 40Wzx92X1jz9s08 for ; Fri, 27 Apr 2018 00:30:04 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=NcmG4tPdMRlma/Vb JJtPBtpDOucIrrUbdmDgKYuJPeNEAU0gMrGbdSjsmizSl9p0ERpb5TvizIZ6xChK Y8QKwfXy5H9x1g/ZOpXYoXBPHvSGhOeGZjjvVzWC2qpomQQR9J+n+i3Rq3nRIhBN ugcK73UhT9MaEClWu8YmFO8bI0k= 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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=TBFQ0yxl1ObK4IlFj/u2H+ inxWE=; b=YUTIm+OGvJueiR2AGQX6fekAUu/lo0/lXDDM5RWSjcsytlG1tLxnqg LkyMn8RjIWvALh4Fuy2oji3M3v1KVGDotnqmJ4yRUrR1oft8M3ueoivndoX45NNs Bz3gU1eblMl8XEovPzSmce6DdUj1YlsXJyPXf+D5LsGQNcuHz1syk= Received: (qmail 90497 invoked by alias); 26 Apr 2018 14:29:56 -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 90166 invoked by uid 89); 26 Apr 2018 14:29:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=sk:gimple X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 26 Apr 2018 14:29:54 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id AC0078139B for ; Thu, 26 Apr 2018 16:29:51 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RdPlOCQOhTaW for ; Thu, 26 Apr 2018 16:29:51 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 7E60F81386 for ; Thu, 26 Apr 2018 16:29:51 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [PATCH] Do not set nothrow flag on recursive function with stack checking Date: Thu, 26 Apr 2018 16:29:22 +0200 Message-ID: <2604930.7AH0sRlHEb@polaris> MIME-Version: 1.0 Hi, when stack checking is enabled in Ada, it is supposed to be able to handle the case of a recursive function that does essentially nothing. But in this case the IPA machinery will compute that the function is nothrow, which means that the Storage_Error exception cannot be caught by the caller. Tested on x86-64/Linux, OK for the mainline? 2018-04-26 Eric Botcazou * ipa-pure-const.c (check_call): In non-IPA mode, set can_throw flag for a recursive call that can throw if stack checking is enabled. (check_stmt): Fix formatting. (propagate_nothrow): Set can_throw for a recursive call if exceptions and stack checking are enabled. (pass_nothrow::execute): Do not set the nothrow flag if there is a recursive call that can throw and stack checking is enabled. 2018-04-26 Eric Botcazou * gnat.dg/stack_check4.adb: New test. Index: ipa-pure-const.c =================================================================== --- ipa-pure-const.c (revision 259642) +++ ipa-pure-const.c (working copy) @@ -674,12 +674,19 @@ check_call (funct_state local, gcall *ca local->can_free = true; /* When not in IPA mode, we can still handle self recursion. */ - if (!ipa && callee_t + if (!ipa + && callee_t && recursive_call_p (current_function_decl, callee_t)) { if (dump_file) - fprintf (dump_file, " Recursive call can loop.\n"); + fprintf (dump_file, " recursive call can loop\n"); local->looping = true; + if (possibly_throws_externally && flag_stack_check) + { + if (dump_file) + fprintf (dump_file, " recursive call can throw\n"); + local->can_throw = true; + } } /* Either callee is unknown or we are doing local analysis. Look to see if there are any bits available for the callee (such as by @@ -795,8 +802,7 @@ check_stmt (gimple_stmt_iterator *gsip, print_gimple_stmt (dump_file, stmt, 0); } - if (gimple_has_volatile_ops (stmt) - && !gimple_clobber_p (stmt)) + if (gimple_has_volatile_ops (stmt) && !gimple_clobber_p (stmt)) { local->pure_const_state = IPA_NEITHER; if (dump_file) @@ -808,8 +814,7 @@ check_stmt (gimple_stmt_iterator *gsip, ipa ? check_ipa_load : check_load, ipa ? check_ipa_store : check_store); - if (gimple_code (stmt) != GIMPLE_CALL - && stmt_could_throw_p (stmt)) + if (gimple_code (stmt) != GIMPLE_CALL && stmt_could_throw_p (stmt)) { if (cfun->can_throw_non_call_exceptions) { @@ -1822,13 +1827,17 @@ propagate_nothrow (void) not be interposed. When callee is compiled with non-call exceptions we also must check that the declaration is bound to current - body as other semantically equivalent body may still - throw. */ + body as other semantically equivalent body may throw. + Moreover, if the call is recursive, we must consider that + the function may throw a stack overflow exception. */ if (avail <= AVAIL_INTERPOSABLE || (!TREE_NOTHROW (y->decl) && (get_function_state (y)->can_throw || (opt_for_fn (y->decl, flag_non_call_exceptions) - && !e->callee->binds_to_current_def_p (w))))) + && !e->callee->binds_to_current_def_p (w)) + || (y == w + && flag_exceptions + && flag_stack_check)))) can_throw = true; } for (ie = w->indirect_calls; ie && !can_throw; @@ -2288,7 +2297,7 @@ make_pass_warn_function_noreturn (gcc::c return new pass_warn_function_noreturn (ctxt); } -/* Simple local pass for pure const discovery reusing the analysis from +/* Simple local pass for nothrow discovery reusing the analysis from ipa_pure_const. This pass is effective when executed together with other optimization passes in early optimization pass queue. */ @@ -2352,8 +2361,9 @@ pass_nothrow::execute (function *) if (is_gimple_call (gsi_stmt (gsi))) { tree callee_t = gimple_call_fndecl (gsi_stmt (gsi)); - if (callee_t && recursive_call_p (current_function_decl, - callee_t)) + if (callee_t + && recursive_call_p (current_function_decl, callee_t) + && !flag_stack_check) continue; }