From patchwork Thu Jan 6 20:11:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandra Loosemore X-Patchwork-Id: 49667 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 573A13858032 for ; Thu, 6 Jan 2022 20:12:47 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id 7A99E3858430; Thu, 6 Jan 2022 20:11:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7A99E3858430 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com IronPort-SDR: fFbTTlAq51dsIIJhv/ikn/YqUIiAYGOmopw8Dv7xAP8eP8lG/uDJVE1WhRTTsRzplAERGOkkFe 868VAZr/VPoPVknUAku/Yp0FWo9BZvegZ4gD0012f4A2XyL1jm70u+Qh6eUXVopyokmZPajeQL TjR6Nq3nwMRi0afd0IiNMDMIun4jhUszupbu5OOW8WgY73vnS4gIg8mYz0PVWOyCH0LkBuhMPC qsRiiW3RZeqISUnJB0X2xb/m7v1NDCANjP6SnWeNhhFnZUOhL6MaXhq6wNseO6aWTMNhu2CVhN UKiHe9L/184ByhEqb2lGzQKP X-IronPort-AV: E=Sophos;i="5.88,267,1635235200"; d="scan'208";a="70332004" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 06 Jan 2022 12:11:32 -0800 IronPort-SDR: SJpQPnaLGuiNSIFKIkgUOsU++PWNG5XVMb+rJfkC1js/4BxY1nn7Vf5grkQLJuw8cG97rZVmpC BBaGovuOMqIzQPNRZgbePB3QcO1eLdaULBEeWQIjuB7jCz0wzAkFGMFkhw+gtRTcg6WcOmdgT8 e/OPLdx52AWQy4ChDI7mXfSkkJIwfZ1GHKZ9IoVvQ9ySwDYqLv/t+h7f6+kIIw0coXhu1kE7Ly 41Bm7Gp7QHuqvbSwHBgP1njjdPS9p7lOtyFZrKeDByXMEuw1dBlCV0sn9OoP4G6Of3dvqi7PqY rds= To: "fortran@gcc.gnu.org" From: Sandra Loosemore Subject: [PATCH] Fortran: Fix handling of optional argument to SIZE intrinsic [PR103898] Message-ID: Date: Thu, 6 Jan 2022 13:11:28 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 Content-Language: en-US X-ClientProxiedBy: SVR-ORW-MBX-07.mgc.mentorg.com (147.34.90.207) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: , Cc: "gcc-patches@gcc.gnu.org" Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This patch fixes an ICE introduced with the recent-ish rewrite to inline the SIZE intrinsic, using a helper function to do the bulk of the work in producing the expansion. It turns out to be a simple think-o type mistake in the wrapper around the helper rather than anything deeply wrong with the logic. OK to check in? -Sandra commit 0e5b74440572f988dd96a6e9c33c11b59323d6cf Author: Sandra Loosemore Date: Thu Jan 6 11:23:18 2022 -0800 Fortran: Fix handling of optional argument to SIZE intrinsic [PR103898] This patch fixes a think-o in the code that triggered an ICE in the test case. 2021-01-06 Sandra Loosemore gcc/fortran/ * trans-intrinsic.c (gfc_conv_intrinsic_size): Make size_var actually be a variable and fix surrounding code. gcc/testsuite/ * gfortran.dg/pr103898.f90: New test. diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index 41252c9..aae34b0 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -8006,10 +8006,14 @@ gfc_conv_intrinsic_size (gfc_se * se, gfc_expr * expr) cond = gfc_evaluate_now (cond, &se->pre); /* 'block2' contains the arg2 absent case, 'block' the arg2 present case; size_var can be used in both blocks. */ - tree size_var = gfc_tree_array_size (&block2, arg1, e, NULL_TREE); + tree size_var = gfc_create_var (TREE_TYPE (size), "size"); tmp = fold_build2_loc (input_location, MODIFY_EXPR, TREE_TYPE (size_var), size_var, size); gfc_add_expr_to_block (&block, tmp); + size = gfc_tree_array_size (&block2, arg1, e, NULL_TREE); + tmp = fold_build2_loc (input_location, MODIFY_EXPR, + TREE_TYPE (size_var), size_var, size); + gfc_add_expr_to_block (&block2, tmp); tmp = build3_v (COND_EXPR, cond, gfc_finish_block (&block), gfc_finish_block (&block2)); gfc_add_expr_to_block (&se->pre, tmp); diff --git a/gcc/testsuite/gfortran.dg/pr103898.f90 b/gcc/testsuite/gfortran.dg/pr103898.f90 new file mode 100644 index 0000000..6b4bb30 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr103898.f90 @@ -0,0 +1,15 @@ +! { dg-do compile } + +! This test used to ICE during gimplification (PR103898). + +Module g +contains + function mysize(array, dim) + integer :: mysize + integer, dimension(:), intent(in) :: array + integer, optional, intent(in) :: dim + if (present(dim)) then + mysize = size(array, dim=dim) + endif + end function mysize +end module