From patchwork Tue Jul 7 02:34:02 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry DeLisle X-Patchwork-Id: 138629 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B18974BA2E1B for ; Tue, 7 Jul 2026 02:35:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B18974BA2E1B Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=MLlbOGWx X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id BBB314BA2E0B for ; Tue, 7 Jul 2026 02:34:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BBB314BA2E0B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BBB314BA2E0B Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783391651; cv=none; b=ErGzcIeUQxhxLztkj8BraUsYylp0l3bZodGbd4CyENiUZFyFi9tV/ImdfNZKHGVLKasVKdxW7ga5WHhI2sDOxo4KeabM7ptT9Psz5N0F4JFuyeKeGbl3preDl2RgWmMuRvoyZC325qhHH0j5h60HQTHTL6u2J9p0HTYpSpd5/hc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783391651; c=relaxed/simple; bh=Uhn1QGDMDNpWhWqd/gkpgqO4mis4IbVnHfzGAPT+ZEA=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=gpRts27QBmbgORkq5Vz7LV1kfDp1cL0bCN5tL4Ic8yq2Bvt2RVDkFB5uWaw1uT2+WlFMCYdfw6PJF1aJxdgaedM0Xnr299sAlAmp6qgKo9sffbckmw8TCpAUcLFm7fLOu+0HOjLJ0NkxP1M5XK+XSvUSkFY8V56UQTBPJW97sYs= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=MLlbOGWx DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBB314BA2E0B Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-84780c95e2eso2884840b3a.3 for ; Mon, 06 Jul 2026 19:34:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783391644; x=1783996444; darn=gcc.gnu.org; h=autocrypt:subject:from:to:content-language:user-agent:mime-version :date:message-id:content-type:from:to:cc:subject:date:message-id :reply-to:content-type; bh=VTe33kASFD7bcA8Vy1A/eKMF+RAcvaVmQN6ANwX84Vo=; b=MLlbOGWxlFJ4TIjDnp35hd0AYnxIy5FpauSl4JboIjFsXwNklGj4IU6PdaKCHCXZTJ /6fRIL2aW5+cvQDFF2u6pwnRjcQZ6D3KFLdk+0MIgRgvoXng/yYvG2f9Fq4UG072mz7U wi1SVlmilh3PYTD2ZsCT90OWqo4xLByOGAzo6wLljjOvEvzomrsNvmXScq4GISJsr461 4AwD0/JvnQRqb+dAqVj4tSjSINlnxklFOero6XOBSwb0grGTYs9wiOkrd7xF8bWPlEwR 0c18NGFaPP5yicFkyglHRvJcei4bJPi0yLoiaCRjFP6zYIorGu+RqmdEEu2W9/EotvQ6 wFHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783391644; x=1783996444; h=autocrypt:subject:from:to:content-language:user-agent:mime-version :date:message-id:content-type:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=VTe33kASFD7bcA8Vy1A/eKMF+RAcvaVmQN6ANwX84Vo=; b=eDdRWFvBQnDKd75wUxTq8HpFQPILTdLS0hChVETK7QmdOhj/LHsPAvETvNiEi0zxoT Ejb66XA7SHc+qkYOy0l2iL9sFv+uRpgnbxTcAIr9EgnQyczN65Vf6M+8qCbVOeWLXlLm dPXR8SvZybp00DZ8gbr/GKjvR2hIKTRP5DYFGyp+1TWkyyhNqNz3AW0VBKStPcyclf1k yBL5UIRyOLHNqfvetOnSr8slVgXny2PwGUMTrQCZWFuo2Dib4O2ZfaMzIOf0c7PfKbJJ mqzfFXMch7qb+CMPK0k4A2fQ62WSyC+fLmtV4brjP467MpfitmRynXoaqSQ74O/KGSVa Jy8A== X-Forwarded-Encrypted: i=1; AHgh+Rpp1YcgT+ITKHYy5OCeHQ73Fr5BqXO6VKuuiSxQeY0WQ2b3lEcH9h5CxLb2q2wtYVgqfRPTDKueSxbADQ==@gcc.gnu.org X-Gm-Message-State: AOJu0YwWp7hSTIEqynByHBJpXCpPd8/1k5o/W7cljnkZTAOtBWk0PDnh fUjdHCSSSgdmONRBIfP8lwzeDCikJyOaDq8vFD9ryYLMskzI6ZP5dBU9 X-Gm-Gg: AfdE7cl95vH1MIQTKSpeA2ZeqbR+2dN1hiqC3G0CVSrFsq0RKrPe7QBHcqy1UyQAueA wE1Vrw9JKYIqgw+rO/tFA04xNJexhC7o1gkOeyzjfW3jU3Boo1WbYWCJiBfeVB1fM9cmUYxvRcg N3MUcsp3dRhB0b1m3vmZyj8pH2S1C/lqxgv/kzHoqNY1lGkpGZSpePLDWLL5HjNsYs8GUFjyTn7 afLchLVeTs7YGDi5nvkYgT4cdAgiCATBh5ZmaPYwb+RF/XFjhL/PnfiZ9NvC6mZd4F8V6jSClyY telTRGDlnUi8qbOdTkpztzvb6OlarYrtDXVVKc9BwCyGJHBNF5ieS3MalVUryESpegXsKT7gSxT sv1w1guAz5j50lzLaVn1hY1ksk2VWtzXCpfnKEHRXj0tsshCXGvFB2QHGcRXNfWLTGnq8/WASgA t8nIRC1LdgPEOsCeg= X-Received: by 2002:a05:6a00:3e08:b0:845:d6a5:716b with SMTP id d2e1a72fcca58-84826c0e68amr3196421b3a.23.1783391644219; Mon, 06 Jul 2026 19:34:04 -0700 (PDT) Received: from [10.168.168.66] ([50.54.170.7]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-847f6d49614sm4596066b3a.35.2026.07.06.19.34.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 06 Jul 2026 19:34:03 -0700 (PDT) Message-ID: Date: Mon, 6 Jul 2026 19:34:02 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: gfortran , gcc-patches From: Jerry D Subject: [PATCH] Fortran [PR103367] Followup patch to fix related test cases Autocrypt: addr=jvdelisle2@gmail.com; keydata= xjMEY5TlkxYJKwYBBAHaRw8BAQdAyrkRDhmJhSTTlV/50gJLlvliU6/Lm5C9ViKV8T9y1GnN HkplcnJ5IEQgPGp2ZGVsaXNsZTJAZ21haWwuY29tPsKJBBMWCAAxFiEEOFR0TS0390uh8dRV uWXAJaWpwWoFAmOU5ZMCGwMECwkIBwUVCAkKCwUWAgMBAAAKCRC5ZcAlpanBalsJAP4wdCiH 2Of9oZv1QWgZ/AVdbWFM3Fv47/WZQHOXfoZ9HgD6AkXrKeJ+6usST7PEaDJjptaViT1fLiYY V/6XaOKSsgLOOARjlOWTEgorBgEEAZdVAQUBAQdAdA7PczYnl07vnOT9oP/wvvMDd4HP09Zl g3LzwXQJWT8DAQgHwngEGBYIACAWIQQ4VHRNLTf3S6Hx1FW5ZcAlpanBagUCY5TlkwIbDAAK CRC5ZcAlpanBasF/AQCa5WjlsVpLsEiggZyT18MOJNAdeRd7wkGDUrwedHrvawD/cE1H+/Ms L1ZwvQiLfGdx8crigQqWTQyos4kH8Wx82wc= X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 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 Hi all, A number of test cases, which are variations on the original reported problems on this PR, arrived on bugzilla. While working on there bugs I noticed some failures that I had originally seen on this one. This prompted me to get digging. The result after several iterations is the attached patch. Regression tested on x86_64. OK for mainline? and later we need to backport to fix the holes. Regards, Jerry --- fortran: [PR103367] Followup patch to fix related test cases PR fortran/103367 gcc/fortran/ChangeLog: * expr.cc (simplify_const_ref): Hoist the call to remove_subobject_ref up a level. * primary.cc (gfc_match_rvalue): Don't copy the value expr if the type is an EXPR_VARIABLE. not * trans-array.cc (gfc_conv_array_initializer): Only copy the expr value if it does not have a ref. gcc/testsuite/ChangeLog: * gfortran.dg/pr103367_2.f90: New test. * gfortran.dg/pr103367_3.f90: New test. * gfortran.dg/pr103367_4.f90: New test. --- From ef05aae9fd868870fd427f53731676642d45b29d Mon Sep 17 00:00:00 2001 From: Jerry DeLisle Date: Mon, 6 Jul 2026 18:30:05 -0700 Subject: [PATCH] fortran: [PR103367] Followup patch to fix related test cases PR fortran/103367 gcc/fortran/ChangeLog: * expr.cc (simplify_const_ref): Hoist the call to remove_subobject_ref up a level. * primary.cc (gfc_match_rvalue): Don't copy the value expr if the type is an EXPR_VARIABLE. not * trans-array.cc (gfc_conv_array_initializer): Only copy the expr value if it does not have a ref. gcc/testsuite/ChangeLog: * gfortran.dg/pr103367_2.f90: New test. * gfortran.dg/pr103367_3.f90: New test. * gfortran.dg/pr103367_4.f90: New test. --- gcc/fortran/expr.cc | 24 ++++++++++----- gcc/fortran/primary.cc | 3 +- gcc/fortran/trans-array.cc | 3 +- gcc/testsuite/gfortran.dg/pr103367_2.f90 | 37 ++++++++++++++++++++++++ gcc/testsuite/gfortran.dg/pr103367_3.f90 | 11 +++++++ gcc/testsuite/gfortran.dg/pr103367_4.f90 | 14 +++++++++ 6 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr103367_2.f90 create mode 100644 gcc/testsuite/gfortran.dg/pr103367_3.f90 create mode 100644 gcc/testsuite/gfortran.dg/pr103367_4.f90 diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc index 9fb152074db..946fa86a822 100644 --- a/gcc/fortran/expr.cc +++ b/gcc/fortran/expr.cc @@ -2162,16 +2162,26 @@ simplify_const_ref (gfc_expr *p) switch (p->ref->type) { case REF_ARRAY: - switch (p->ref->u.ar.type) + /* , parameter :: x() = scalar_expr + will generate this. */ + if (p->expr_type != EXPR_ARRAY) { - case AR_ELEMENT: - /* , parameter :: x() = scalar_expr - will generate this. */ - if (p->expr_type != EXPR_ARRAY) + if (p->ref->u.ar.type == AR_ELEMENT) { - remove_subobject_ref (p, NULL); - break; + int dim; + for (dim = 0; dim < p->ref->u.ar.dimen; dim++) + if (!p->ref->u.ar.start[dim] + || p->ref->u.ar.start[dim]->expr_type != EXPR_CONSTANT) + return true; } + + remove_subobject_ref (p, NULL); + break; + } + + switch (p->ref->u.ar.type) + { + case AR_ELEMENT: if (!find_array_element (p->value.constructor, &p->ref->u.ar, &cons)) return false; diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc index da517f8394f..d167036b808 100644 --- a/gcc/fortran/primary.cc +++ b/gcc/fortran/primary.cc @@ -4025,7 +4025,8 @@ gfc_match_rvalue (gfc_expr **result) end up here. Unfortunately, sym->value->expr_type is set to EXPR_CONSTANT, and so the if () branch would be followed without the !sym->as check. */ - if (sym->value && sym->value->expr_type != EXPR_ARRAY && !sym->as) + if (sym->value && sym->value->expr_type != EXPR_ARRAY + && sym->value->expr_type != EXPR_VARIABLE && !sym->as) e = gfc_copy_expr (sym->value); else { diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index d1153f5565c..11cf2ba2e86 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -6683,7 +6683,8 @@ gfc_conv_array_initializer (tree type, gfc_expr * expr) if (expr->expr_type == EXPR_VARIABLE && expr->symtree->n.sym->attr.flavor == FL_PARAMETER - && expr->symtree->n.sym->value) + && expr->symtree->n.sym->value + && !expr->ref) expr = expr->symtree->n.sym->value; /* After parameter substitution the expression should be a constant, array diff --git a/gcc/testsuite/gfortran.dg/pr103367_2.f90 b/gcc/testsuite/gfortran.dg/pr103367_2.f90 new file mode 100644 index 00000000000..6a3c4f6357b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr103367_2.f90 @@ -0,0 +1,37 @@ +! { dg-do compile } +subroutine s1 + type t + integer :: a(1,2) = 3 + end type + type(t), parameter :: x(1) = t(4) + integer, parameter :: y(1,2) = (x(1)%a(m,1)) ! { dg-error "does not reduce to a constant expression" } + print *, y +end + +subroutine s2 + type t + integer :: a(2) = 3! + end type + type(t), parameter :: x(1) = t(4) + integer, parameter :: y = x(1)%a(m) ! { dg-error "non-constant initialization expression" } + print *, y +end + +subroutine s3 + type t + integer :: a(1,2) = 3 + end type + type(t), parameter :: x(1) = t(4) + integer, parameter :: y(1,2) = (x(b)%a) ! { dg-error "does not reduce to a constant expression" } + print *, y +end + +subroutine s4 + type t + integer :: a(1,2) = 3 + end type + type(t), parameter :: x(1) = t(4) + integer :: y(1,2) = x(b)%a ! { dg-error "does not reduce to a constant expression" } + print *, y +end +! { dg-prune-output "Legacy Extension: REAL array index" } diff --git a/gcc/testsuite/gfortran.dg/pr103367_3.f90 b/gcc/testsuite/gfortran.dg/pr103367_3.f90 new file mode 100644 index 00000000000..6c83e88b28d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr103367_3.f90 @@ -0,0 +1,11 @@ +! { dg-do run } +! PR103367 Test case from the PR, previously segfaulted. +program p + type t + integer :: a(1,2) = 3 + end type + type(t), parameter :: x(1) = t(4) + integer, parameter :: y(2) = x(1)%a(1,:) + if (any (y /= [4, 4])) stop 1 +end + diff --git a/gcc/testsuite/gfortran.dg/pr103367_4.f90 b/gcc/testsuite/gfortran.dg/pr103367_4.f90 new file mode 100644 index 00000000000..e0c052692cd --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr103367_4.f90 @@ -0,0 +1,14 @@ +! { dg-do run } +! PR103367, this test previously +! Test case from the PR segfaulted at compile time. +program p + type inner + integer :: n = 3 + end type + type outer + type(inner) :: a(2) = inner(1) + end type + type(outer), parameter :: x(1) = outer(inner(4)) + integer, parameter :: y(2) = x(1)%a%n + if (any (y /= [4, 4])) stop 1 +end -- 2.54.0