From patchwork Sun Apr 19 16:04:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Jos=C3=A9_Rui_Faustino_de_Sousa?= X-Patchwork-Id: 1272957 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=8.43.85.97; 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=Bk3mgg8O; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 494vm96JcXz9s71 for ; Mon, 20 Apr 2020 02:04:39 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A24043851427; Sun, 19 Apr 2020 16:04:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A24043851427 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587312269; bh=6jlcMySLk8u/0XGj+b6VC4M+fJ70pm6TJ8hrm0D0iig=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Bk3mgg8OtaqLly3vMaqMyeBnoYcbAnJQy9PUoDnilFavbOHGQYLufmhLCtPX78m/C l7Ok4bqjc0XzkHyoA84zj4wNcQfJFBQUWzIflYyyc3eFBWj+mI5n2JpaTcjrq1OgAC J7YnuduyGkZwbGgTfZfBFMkPOOrLjEA0J7NsS9KQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 74D193858D31; Sun, 19 Apr 2020 16:04:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 74D193858D31 Received: by mail-wm1-x330.google.com with SMTP id y24so8435825wma.4; Sun, 19 Apr 2020 09:04:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=6jlcMySLk8u/0XGj+b6VC4M+fJ70pm6TJ8hrm0D0iig=; b=E7eMdS8v0hjdvSu6/4Hs1wYL44G0pdcjZDdrxa/xERcC65fTXC8hgwrqoMtOGQouik JbY5633oqGV/rWUwqHBC9/EKvSF45RZ8tv9hVICzyg8QYl20PKgB2/9Ddpf3pQFY9Uus 2+8MrUpL9vv3Ab3CbkK1Ck4wmyAWw8x5iQ4iCLtE9EOg2zuQW/PKwcfwfKdWLzNZXskG RBijLNYcYsYz/kXAxF7CpLXT0VY1aWfNP85PR5nMevuNM4D0bi4j2gyAdiSDV0o/9ajp ALpPDgSkiEnE54Nacqzg1j5ffjRwhFos/VQ5NCwqK9rPyd9MDCSdpgJt+WjZjfbyLMvq MsNA== X-Gm-Message-State: AGi0Puab4AxZthm8jCCE4Oh01wdgKrukgFaqBa767zFGyDCBihBnEyN8 o0fD5ZcUMf6qK+pQYJvPPNvQ0dKV X-Google-Smtp-Source: APiQypJsRTKG4BEzh+ff2JcaVzcKiWqsPNOsQ9ccp/QEEgY2BBPn/6E+hpstUAveNvYpGSZlxe8dtA== X-Received: by 2002:a1c:7d04:: with SMTP id y4mr13112255wmc.10.1587312264717; Sun, 19 Apr 2020 09:04:24 -0700 (PDT) Received: from ?IPv6:2001:8a0:7d46:6200:8cbe:1327:47ef:ce15? ([2001:8a0:7d46:6200:8cbe:1327:47ef:ce15]) by smtp.googlemail.com with ESMTPSA id w6sm37884744wrm.86.2020.04.19.09.04.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 19 Apr 2020 09:04:23 -0700 (PDT) To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [Patch, fortran] PR fortran/90350 - ubound ICE on assumed size array even though explicit bound is specified Message-ID: Date: Sun, 19 Apr 2020 16:04:21 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-22.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: =?utf-8?q?Jos=C3=A9_Rui_Faustino_de_Sousa_via_Gcc-patches?= From: =?utf-8?q?Jos=C3=A9_Rui_Faustino_de_Sousa?= Reply-To: =?utf-8?q?Jos=C3=A9_Rui_Faustino_de_Sousa?= Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi all! Proposed patch to Bug 90350 - ubound ICE on assumed size array even though explicit bound is specified Patch tested only on x86_64-pc-linux-gnu. Bumped into the same problem. Probably a better fix would be to add an extra step to the reference chain reflecting that array-section are explicit-shape arrays not whatever that was sectioned. But, although this pattern of problem shows up in the code in other places, it may be more trouble than it is worth... Thank you very much. Best regards, José Rui 2020-4-19 José Rui Faustino de Sousa PR fortran/90350 * simplify.c (simplify_bound): In the case of assumed-size arrays check if the reference is to a full array. 2020-4-19 José Rui Faustino de Sousa PR fortran/90350 * PR90350.f90: New test. diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index d5703e3..4818368 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -4157,6 +4157,7 @@ simplify_bound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind, int upper) { gfc_ref *ref; gfc_array_spec *as; + ar_type type = AR_UNKNOWN; int d; if (array->ts.type == BT_CLASS) @@ -4180,6 +4181,7 @@ simplify_bound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind, int upper) switch (ref->type) { case REF_ARRAY: + type = ref->u.ar.type; switch (ref->u.ar.type) { case AR_ELEMENT: @@ -4233,7 +4235,10 @@ simplify_bound (gfc_expr *array, gfc_expr *dim, gfc_expr *kind, int upper) int k; /* UBOUND(ARRAY) is not valid for an assumed-size array. */ - if (upper && as && as->type == AS_ASSUMED_SIZE) + if (upper + && type == AR_FULL + && as + && as->type == AS_ASSUMED_SIZE) { /* An error message will be emitted in check_assumed_size_reference (resolve.c). */ diff --git a/gcc/testsuite/gfortran.dg/PR90350.f90 b/gcc/testsuite/gfortran.dg/PR90350.f90 new file mode 100644 index 0000000..2e2cf10 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/PR90350.f90 @@ -0,0 +1,19 @@ +! { dg-do compile } +! +! Test the fix for PR90350 +! +! Contributed by +! + +program artificial +implicit none +integer :: arr(-10:10) + call asub(arr,size(arr)) +end program artificial +subroutine asub(arr,n) +integer,intent(in) :: arr(*) +integer,intent(in) :: n + write(*,*)'UPPER=',ubound(arr(:n)) + write(*,*)'LOWER=',lbound(arr(:n)) + write(*,*)'SIZE=',size(arr(:n)) +end subroutine asub