From patchwork Tue Jun 16 21:59:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 1310724 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Itz+lk/M; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49mhvg1rSMz9sSf for ; Wed, 17 Jun 2020 08:00:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1471D383E82C; Tue, 16 Jun 2020 22:00:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1471D383E82C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592344812; bh=ved/YBvg1mrEYMQiYajB3FBOdmd2cIEJcQxXSzjzRvA=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Itz+lk/MKVhTiHOpK/pqRjcsmIqFzHM7ObhVPzs7KT8pO19atnuRb+whDApUHZRW1 uUPTnp25+cOhfBSUncfotz5Lqh3Y+oU2N7KqEv/CniK6YWKDYox4yrpWfXqYCXq9w5 4/x68a0H6EeTQHZQ5kSwKCSoepjbTYZO7JFoIDUk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [IPv6:2001:67c:2050::465:102]) by sourceware.org (Postfix) with ESMTPS id 69BD0386F447 for ; Tue, 16 Jun 2020 22:00:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 69BD0386F447 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 49mhvX0ryfzKmgv; Wed, 17 Jun 2020 00:00:08 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id TOxHRlR3S7bz; Wed, 17 Jun 2020 00:00:04 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [committed] d: Move generation of array bounds error to own function. Date: Tue, 16 Jun 2020 23:59:25 +0200 Message-Id: <20200616215933.3858164-2-ibuclaw@gdcproject.org> In-Reply-To: <20200616215933.3858164-1-ibuclaw@gdcproject.org> References: <20200616215933.3858164-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: C9E851761 X-Rspamd-Score: -0.69 / 15.00 / 15.00 X-Spam-Status: No, score=-16.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_ABUSE_SURBL autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch moves a couple code duplications into its own routine, the checkAction global parameter is now initialized and properly adjusted. Bootstrapped and regression tested on x86_64-linux-gnu, and committed to master. Regards Iain gcc/d/ChangeLog: * d-codegen.cc (build_array_bounds_call): New function. (build_bounds_condition): Use build_array_bounds_call. * d-lang.cc (d_init_options): Explicitly set default check action to CHECKACTION_D. (d_post_options): Set check action to CHECKACTION_C if the flag -fno-druntime was seen. * d-tree.h (build_array_bounds_call): Declare. * expr.cc (ExprVisitor::visit (AssertExp *)): Use build_array_bounds_call. --- gcc/d/d-codegen.cc | 24 +++++++++++++++++++++--- gcc/d/d-lang.cc | 3 ++- gcc/d/d-tree.h | 1 + gcc/d/expr.cc | 4 +--- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index d31638e2c1d..9d13e1263a9 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -1712,6 +1712,26 @@ void_okay_p (tree t) return t; } +/* Builds a CALL_EXPR at location LOC in the source file to execute when an + array bounds check fails. */ + +tree +build_array_bounds_call (const Loc &loc) +{ + switch (global.params.checkAction) + { + case CHECKACTION_D: + return d_assert_call (loc, LIBCALL_ARRAY_BOUNDS); + + case CHECKACTION_C: + case CHECKACTION_halt: + return build_call_expr (builtin_decl_explicit (BUILT_IN_TRAP), 0); + + default: + gcc_unreachable (); + } +} + /* Builds a bounds condition checking that INDEX is between 0 and LEN. The condition returns the INDEX if true, or throws a RangeError. If INCLUSIVE, we allow INDEX == LEN to return true also. */ @@ -1731,9 +1751,7 @@ build_bounds_condition (const Loc& loc, tree index, tree len, bool inclusive) tree condition = fold_build2 (inclusive ? GT_EXPR : GE_EXPR, d_bool_type, index, len); /* Terminate the program with a trap if no D runtime present. */ - tree boundserr = (global.params.checkAction == CHECKACTION_D) - ? d_assert_call (loc, LIBCALL_ARRAY_BOUNDS) - : build_call_expr (builtin_decl_explicit (BUILT_IN_TRAP), 0); + tree boundserr = build_array_bounds_call (loc); return build_condition (TREE_TYPE (index), condition, boundserr, index); } diff --git a/gcc/d/d-lang.cc b/gcc/d/d-lang.cc index 5266a6550dc..085d8393b5a 100644 --- a/gcc/d/d-lang.cc +++ b/gcc/d/d-lang.cc @@ -285,6 +285,7 @@ d_init_options (unsigned int, cl_decoded_option *decoded_options) global.params.useOut = CHECKENABLEdefault; global.params.useArrayBounds = CHECKENABLEdefault; global.params.useSwitchError = CHECKENABLEdefault; + global.params.checkAction = CHECKACTION_D; global.params.useModuleInfo = true; global.params.useTypeInfo = true; global.params.useExceptions = true; @@ -775,7 +776,7 @@ d_post_options (const char ** fn) if (!global_options_set.x_flag_exceptions) global.params.useExceptions = false; - global.params.checkAction = CHECKACTION_halt; + global.params.checkAction = CHECKACTION_C; } /* Keep in sync with existing -fbounds-check flag. */ diff --git a/gcc/d/d-tree.h b/gcc/d/d-tree.h index 3338e88b278..dd38b732837 100644 --- a/gcc/d/d-tree.h +++ b/gcc/d/d-tree.h @@ -560,6 +560,7 @@ extern tree build_memref (tree, tree, tree); extern tree build_array_set (tree, tree, tree); extern tree build_array_from_val (Type *, tree); extern tree void_okay_p (tree); +extern tree build_array_bounds_call (const Loc &); extern tree build_bounds_condition (const Loc &, tree, tree, bool); extern bool array_bounds_check (void); extern tree bind_expr (tree, tree); diff --git a/gcc/d/expr.cc b/gcc/d/expr.cc index 06cd83a737d..bf9bb45690a 100644 --- a/gcc/d/expr.cc +++ b/gcc/d/expr.cc @@ -1218,9 +1218,7 @@ public: if (!e->indexIsInBounds && array_bounds_check ()) { - tree tassert = (global.params.checkAction == CHECKACTION_D) - ? d_assert_call (e->loc, LIBCALL_ARRAY_BOUNDS) - : build_call_expr (builtin_decl_explicit (BUILT_IN_TRAP), 0); + tree tassert = build_array_bounds_call (e->loc); result = d_save_expr (result); result = build_condition (TREE_TYPE (result),