From patchwork Tue Apr 26 18:35:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 53240 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 8D1843857811 for ; Tue, 26 Apr 2022 18:35:24 +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 CE3A33858C83 for ; Tue, 26 Apr 2022 18:35:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CE3A33858C83 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 jQ1enc7KPiK8njQ1en529J; Tue, 26 Apr 2022 20:35:03 +0200 X-ME-Helo: [192.168.1.17] X-ME-Auth: MDU4MTIxYWM4YWI0ZGE4ZTUwZWZmNTExZmI2ZWZlMThkM2ZhYiE5OWRkOGM= X-ME-Date: Tue, 26 Apr 2022 20:35:03 +0200 X-ME-IP: 86.253.179.215 Message-ID: Date: Tue, 26 Apr 2022 20:35:02 +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] fortran: Compare non-constant bound expressions. [PR105379] To: gcc-patches , gfortran Content-Language: fr X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, 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: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hello, this fixes a regression caused by my recent PR103662 patch. Regression tested on x86_64-pc-linux-gnu. OK for master? From d7309a471c42e51e84c37d5d4a3fd5bb0ed67405 Mon Sep 17 00:00:00 2001 From: Mikael Morin Date: Mon, 25 Apr 2022 19:47:04 +0200 Subject: [PATCH] fortran: Compare non-constant bound expressions. [PR105379] Starting with r12-8235-gfa5cd7102da676dcb1757b1288421f5f3439ae0e, class descriptor types are compared to detect duplicate declarations. This caused ICEs as the comparison of array spec supported only constant explicit bounds, but dummy class variable descriptor types can have a _data field with non-constant array spec bounds. This change adds support for non-constant bounds. For that, gfc_dep_compare_expr is used. It does probably more than strictly necessary, but using it avoids rewriting a specific comparison function, making mistakes and forgetting cases. PR fortran/103662 PR fortran/105379 gcc/fortran/ChangeLog: * array.cc (compare_bounds): Use bool as return type. Support non-constant expressions. (gfc_compare_array_spec): Update call to compare_bounds. gcc/testsuite/ChangeLog: * gfortran.dg/class_dummy_8.f90: New test. * gfortran.dg/class_dummy_9.f90: New test. --- gcc/fortran/array.cc | 27 ++++++++++++--------- gcc/testsuite/gfortran.dg/class_dummy_8.f90 | 20 +++++++++++++++ gcc/testsuite/gfortran.dg/class_dummy_9.f90 | 20 +++++++++++++++ 3 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/class_dummy_8.f90 create mode 100644 gcc/testsuite/gfortran.dg/class_dummy_9.f90 diff --git a/gcc/fortran/array.cc b/gcc/fortran/array.cc index 90ea812d699..bbdb5b392fc 100644 --- a/gcc/fortran/array.cc +++ b/gcc/fortran/array.cc @@ -957,23 +957,28 @@ gfc_copy_array_spec (gfc_array_spec *src) } -/* Returns nonzero if the two expressions are equal. Only handles integer - constants. */ +/* Returns nonzero if the two expressions are equal. + We should not need to support more than constant values, as that’s what is + allowed in derived type component array spec. However, we may create types + with non-constant array spec for dummy variable class container types, for + which the _data component holds the array spec of the variable declaration. + So we have to support non-constant bounds as well. */ -static int +static bool compare_bounds (gfc_expr *bound1, gfc_expr *bound2) { if (bound1 == NULL || bound2 == NULL - || bound1->expr_type != EXPR_CONSTANT - || bound2->expr_type != EXPR_CONSTANT || bound1->ts.type != BT_INTEGER || bound2->ts.type != BT_INTEGER) gfc_internal_error ("gfc_compare_array_spec(): Array spec clobbered"); - if (mpz_cmp (bound1->value.integer, bound2->value.integer) == 0) - return 1; - else - return 0; + /* What qualifies as identical bounds? We could probably just check that the + expressions are exact clones. We avoid rewriting a specific comparison + function and re-use instead the rather involved gfc_dep_compare_expr which + is just a bit more permissive, as it can also detect identical values for + some mismatching expressions (extra parenthesis, swapped operands, unary + plus, etc). It probably only makes a difference in corner cases. */ + return gfc_dep_compare_expr (bound1, bound2) == 0; } @@ -1006,10 +1011,10 @@ gfc_compare_array_spec (gfc_array_spec *as1, gfc_array_spec *as2) if (as1->type == AS_EXPLICIT) for (i = 0; i < as1->rank + as1->corank; i++) { - if (compare_bounds (as1->lower[i], as2->lower[i]) == 0) + if (!compare_bounds (as1->lower[i], as2->lower[i])) return 0; - if (compare_bounds (as1->upper[i], as2->upper[i]) == 0) + if (!compare_bounds (as1->upper[i], as2->upper[i])) return 0; } diff --git a/gcc/testsuite/gfortran.dg/class_dummy_8.f90 b/gcc/testsuite/gfortran.dg/class_dummy_8.f90 new file mode 100644 index 00000000000..0976a725866 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/class_dummy_8.f90 @@ -0,0 +1,20 @@ +! { dg-do compile } +! +! PR fortran/105379 +! Type comparison of class containers used to trigger an ICE when one of the +! class containers had a non-constant array spec. +! +! Contributed by Gerhard Steinmetz . + +program p + type t + end type +contains + subroutine s1(x) + class(t) :: x(3) + end + subroutine s2(n, x) + integer :: n + class(t) :: x(n) + end +end diff --git a/gcc/testsuite/gfortran.dg/class_dummy_9.f90 b/gcc/testsuite/gfortran.dg/class_dummy_9.f90 new file mode 100644 index 00000000000..0fd98c05be2 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/class_dummy_9.f90 @@ -0,0 +1,20 @@ +! { dg-do compile } +! +! PR fortran/105379 +! Type comparison of class containers used to trigger an ICE when one of the +! class containers had a non-constant array spec. +! +! Contributed by Gerhard Steinmetz . + +program p + type t + end type + integer :: m = 3 +contains + subroutine s1(x) + class(t) :: x(3) + end + subroutine s3(x) + class(t) :: x(m) + end +end -- 2.35.1