From patchwork Tue Apr 26 19:10:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 53241 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 649103857C50 for ; Tue, 26 Apr 2022 19:11:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp.smtpout.orange.fr (smtp01.smtpout.orange.fr [80.12.242.123]) by sourceware.org (Postfix) with ESMTPS id 904013858C53 for ; Tue, 26 Apr 2022 19:10:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 904013858C53 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orange.fr Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orange.fr Received: from [192.168.1.17] ([86.253.179.215]) by smtp.orange.fr with ESMTPA id jQa6ncN4HiK8njQa6n57F9; Tue, 26 Apr 2022 21:10:45 +0200 X-ME-Helo: [192.168.1.17] X-ME-Auth: MDU4MTIxYWM4YWI0ZGE4ZTUwZWZmNTExZmI2ZWZlMThkM2ZhYiE5OWRkOGM= X-ME-Date: Tue, 26 Apr 2022 21:10:45 +0200 X-ME-IP: 86.253.179.215 Message-ID: Date: Tue, 26 Apr 2022 21:10:38 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 From: Mikael Morin Subject: [PATCH v2] fortran: Avoid infinite self-recursion [PR105381] To: Jakub Jelinek , Tobias Burnus References: <8f082ce4-a6a9-72c1-a882-4663426adaff@orange.fr> <4567d0f0-3077-d582-e2d2-b0169c322009@codesourcery.com> <737d7a95-33f0-4264-4ba7-caed687c3092@orange.fr> Content-Language: fr In-Reply-To: <737d7a95-33f0-4264-4ba7-caed687c3092@orange.fr> X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, BODY_8BITS, FREEMAIL_FROM, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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 , Harald Anlauf , gfortran Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Le 26/04/2022 à 19:12, Mikael Morin a écrit : > Le 26/04/2022 à 15:32, Jakub Jelinek a écrit : >> or one can repeat it like: >>      if (DECL_P (expr) >>     && DECL_LANG_SPECIFIC (expr) >>     && GFC_DECL_SAVED_DESCRIPTOR (expr) >>     && GFC_DECL_SAVED_DESCRIPTOR (expr) != expr) >>        return non_negative_strides_array_p (GFC_DECL_SAVED_DESCRIPTOR >> (expr)); > > I think I’ll use that. Here it comes. Regression tested again. OK? From 9da696478832bb3fe5ac25542ad9226ce3235368 Mon Sep 17 00:00:00 2001 From: Mikael Morin Date: Tue, 26 Apr 2022 13:05:32 +0200 Subject: [PATCH v2] fortran: Avoid infinite self-recursion [PR105381] Dummy array decls are local decls different from the argument decl accessible through GFC_DECL_SAVED_DESCRIPTOR. If the argument decl has a DECL_LANG_SPECIFIC set, it is copied over to the local decl at the time the latter is created, so that the DECL_LANG_SPECIFIC object is shared between local dummy decl and argument decl, and thus the GFC_DECL_SAVED_DESCRIPTOR of the argument decl is the argument decl itself. The r12-8230-g7964ab6c364c410c34efe7ca2eba797d36525349 change introduced the non_negative_strides_array_p predicate which recurses through GFC_DECL_SAVED_DESCRIPTOR to avoid seeing dummy decls as purely local decls. As the GFC_DECL_SAVED_DESCRIPTOR of the argument decl is itself, this can cause infinite recursion. This change adds a check to avoid infinite recursion. PR fortran/102043 PR fortran/105381 gcc/fortran/ChangeLog: * trans-array.cc (non_negative_strides_array_p): Inline variable orig_decl and merge nested if conditions. Add condition to not recurse if the next argument is the same as the current. gcc/testsuite/ChangeLog: * gfortran.dg/character_array_dummy_1.f90: New test. --- gcc/fortran/trans-array.cc | 7 ++++--- .../gfortran.dg/character_array_dummy_1.f90 | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/character_array_dummy_1.f90 diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index e4b6270ccf8..05134952db4 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -3696,9 +3696,10 @@ non_negative_strides_array_p (tree expr) /* If the array was originally a dummy with a descriptor, strides can be negative. */ if (DECL_P (expr) - && DECL_LANG_SPECIFIC (expr)) - if (tree orig_decl = GFC_DECL_SAVED_DESCRIPTOR (expr)) - return non_negative_strides_array_p (orig_decl); + && DECL_LANG_SPECIFIC (expr) + && GFC_DECL_SAVED_DESCRIPTOR (expr) + && GFC_DECL_SAVED_DESCRIPTOR (expr) != expr) + return non_negative_strides_array_p (GFC_DECL_SAVED_DESCRIPTOR (expr)); return true; } diff --git a/gcc/testsuite/gfortran.dg/character_array_dummy_1.f90 b/gcc/testsuite/gfortran.dg/character_array_dummy_1.f90 new file mode 100644 index 00000000000..da5ed636f4f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/character_array_dummy_1.f90 @@ -0,0 +1,21 @@ +! { dg-do compile } +! +! PR fortran/105381 +! Infinite recursion with array references of character dummy arguments. +! +! Contributed by Harald Anlauf + +MODULE m + implicit none + integer, parameter :: ncrit = 8 + integer, parameter :: nterm = 7 +contains + + subroutine new_thin_rule (rule1) + character(*),intent(in) ,optional :: rule1(ncrit) + character(len=8) :: rules (ncrit,nterm) + rules = '' + if (present (rule1)) rules(:,1) = rule1 ! <-- compile time hog + end subroutine new_thin_rule + +end module m -- 2.35.1