From patchwork Fri Oct 22 19:36:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1545093 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=swzCP96q; dkim-atps=neutral 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+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HbZP02NKxz9sRN for ; Sat, 23 Oct 2021 06:37:06 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6FAF6385783B for ; Fri, 22 Oct 2021 19:37:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6FAF6385783B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634931422; bh=sVEab/ieiczLRl9LNoaeaIEgyRMNKKZ8lwBt8V8Y3gk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=swzCP96q9/DYoE9AJg0hbFsKWnBwo2Y2ORhY9LjuVNrn3PD46qmhJ925kzuss8k5a HIWvTeldcsHh6qNJ7Dwyb2+q9qtyorIPjHr7GZMBSQnX33YRwB87eWh0myOnHXJ6Eq 9Ps66+5oh01+Qmtusw4uEpoxXojxDaH2fbaAHwzA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by sourceware.org (Postfix) with ESMTPS id BBF813858416; Fri, 22 Oct 2021 19:36:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BBF813858416 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [79.251.6.32] ([79.251.6.32]) by web-mail.gmx.net (3c-app-gmx-bs21.server.lan [172.19.170.73]) (via HTTP); Fri, 22 Oct 2021 21:36:23 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] PR fortran/102816 - [12 Regression] ICE in resolve_structure_cons, at fortran/resolve.c:1467 Date: Fri, 22 Oct 2021 21:36:23 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:la8YlypeSImOCFOtmcFiJg0hrCqLw1FBTy1v6jZoOzZvuWwfE7V5fsAxJYG5V2WBnuuSI D4xN+68mpVIlQR/glWWIHQrmeqCNRuQ8RN4m+AM+HB1lmx9fL+bzkRCG+SxokM4d5NsTx2RC/DQ0 yf4d3r04dODSMkFOn9K3VDgh6DxeTLX6d6tE3ePjs1UMQ8LWzpDmd8ZStIzMsBVQ7mHphspypkM5 tckPoX7isIQm5eEN1PPuUegGpuZg/4XdXJjuHciKAWKlHEXP9qirNBtIFWtcyNACTUmp60QzOzyM Gs= X-UI-Out-Filterresults: notjunk:1;V03:K0:mUhyk1lkxk8=:ir+8rkWSktjvLxuVkxnzF0 jNx5abV3hnFIeYgDCNsKCcdeZD9dVjXFeT3k0SsKbjcZCeTugNudZT4Q0eHyR/sbaFwJod4w6 uVShGAnIRni2Ai0y+b7v61PZz4bYpEfCBcYtRAeP1ntnCfOMHo/bIdb6RBwuqe124l0ejgjO0 cOoH5TuyE9zDgD/X9sRa9vtcwWrb1SmGvh9ALk/nB2vKjDetUNI3YAgi9xQnAr5m7WOO1A1mw xyCTGtLmPHsz/LQzo67FFABO8M4zHFuON6uhXT7YeG2zr/bUPOXutzA5uFjiDASQDPlFCnFqV 9F7mBJE5TIYZwv+UAzzYRiOcfR3o4KZa4LqgoimgeaZUNu300qx9hwj2VNd5J3xGFTHKRiybd n8k+6FhvgNst4wP+i/ZSkAfd/uZkNKG9Flf2pgopeyNsB8WD+BD1yvy063T6IvVmakLhXR9el mn1iCeL5Zodxsv/w05yg0o8A0z3THrpXFTRBWBfuAvjyXKWQusi59rPjibeAEwpZE13Ile7hm BTqD25UAUVx3DKNw1wHdiXeeXX3p3pjAD+AVoNjWbfywEkPtb78DQMvFx4wRshRa3RN/I5u79 tWHPIFBvwdvxYY3TStta8sfOazb1bTAF/PXC+ia1AwaENE97ZyUqbdmgFvKnlU0HWikpiVRxq cpeb7skG62GW8G8d1IVllX6V1qGP5vVRKhiil5t7jqkbw0yAV34VBUcuk7494r4moeEgANBwm 6wHYSvjIq1Fau6WGhOUBHWpbGel2+OkwX4aO7PWXXIal0Amf3xBdwGGiTcRcsZ8w1xDI/Y4r2 V+gkVFI X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, 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: , X-Patchwork-Original-From: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Dear Fortranners, the recently introduced shape validation for array components in DT constructors did not properly deal with invalid code created by ingenious testers. Obvious solution: replace the gcc_assert by a suitable error message. Regarding the error message: before the shape validation, gfortran would emit the same error message twice referring to the same line, namely the bad declaration of the component. With the attached patch we get one error message for the bad declaration of the component, and one for the structure constructor referring to that DT component. One could easily change that and make the second message refer to the same as the declaration, giving two errors for the same line. Comments / opinions? Regtested on x86_64-pc-linux-gnu. OK? Thanks, Harald Fortran: error recovery on initializing invalid derived type array component gcc/fortran/ChangeLog: PR fortran/102816 * resolve.c (resolve_structure_cons): Reject invalid array spec of a DT component referred in a structure constructor. gcc/testsuite/ChangeLog: PR fortran/102816 * gfortran.dg/pr102816.f90: New test. diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 5ccd9072c24..dc4ca5ef818 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -1463,8 +1463,15 @@ resolve_structure_cons (gfc_expr *expr, int init) mpz_init (len); for (int n = 0; n < rank; n++) { - gcc_assert (comp->as->upper[n]->expr_type == EXPR_CONSTANT - && comp->as->lower[n]->expr_type == EXPR_CONSTANT); + if (comp->as->upper[n]->expr_type != EXPR_CONSTANT + || comp->as->lower[n]->expr_type != EXPR_CONSTANT) + { + gfc_error ("Bad array spec of component %qs referred in " + "structure constructor at %L", + comp->name, &cons->expr->where); + t = false; + break; + }; mpz_set_ui (len, 1); mpz_add (len, len, comp->as->upper[n]->value.integer); mpz_sub (len, len, comp->as->lower[n]->value.integer); diff --git a/gcc/testsuite/gfortran.dg/pr102816.f90 b/gcc/testsuite/gfortran.dg/pr102816.f90 new file mode 100644 index 00000000000..46831743b2b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr102816.f90 @@ -0,0 +1,9 @@ +! { dg-do compile } +! PR fortran/102816 + +program p + type t + integer :: a([2]) ! { dg-error "must be scalar" } + end type + type(t) :: x = t([3, 4]) ! { dg-error "Bad array spec of component" } +end