From patchwork Wed Oct 13 19:23:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1540589 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=UYToNQIG; 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 4HV2X541VBz9sP7 for ; Thu, 14 Oct 2021 06:24:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5AAD8385843F for ; Wed, 13 Oct 2021 19:24:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5AAD8385843F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634153040; bh=huQAUziPCBbjBfHwkgGnLIaTtOq4n5w3oEW1FWPhL1o=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=UYToNQIGoTwHTTuwsP4AwVw+eTXMCprjvh5bgIeF0J4uhaexMyxNNxJ0n+x5VjMds a8loc/RC5e8/kOo3kyTboeAsA4NSH0SQ5Zagh8mzNR0wnNMSMDHNiLYiZ7vJOtpfdC v4a2URT4NsQHUq0kVRYoY2tTrML1nfdiQKibrtJ0= 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.19]) by sourceware.org (Postfix) with ESMTPS id 02C0D3858403; Wed, 13 Oct 2021 19:23:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 02C0D3858403 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [93.207.82.18] ([93.207.82.18]) by web-mail.gmx.net (3c-app-gmx-bs17.server.lan [172.19.170.69]) (via HTTP); Wed, 13 Oct 2021 21:23:00 +0200 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] PR fortran/102717 - ICE in gfc_simplify_reshape, at fortran/simplify.c:6843 Date: Wed, 13 Oct 2021 21:23:00 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:p4PDimOSDCZ2uwaLc42u7LkgzHebVhO+TlRU4v5uOXLMGD2wDGqndoogCk8SS24x8eetO o1VtkkqYQu+ZMcUlvoxS+ZzEdy+tNjhUCZol5be6CxgFhJ0sd5MS20N61E+D6OaKaYjTXzkgouSF DrZD39vGf9QRIxTTJL1lugrQf2eb8JFe87oPjaEA8gRx9q6qXNIE89gPYCvMIF03FfCCsYGQqNjt 0PnN/2ntP2ZVmDBSjIn9ko3jz+i7lIQUUtq/LNGLprSPCdzDtlBclb5Q9uZ2em9ikfQ9vRvXEbmZ rU= X-UI-Out-Filterresults: notjunk:1;V03:K0:9qYqUmPnn2g=:PpZu4gY3Knp//wN1j87z2U 3kGlkNLmju50p19Z7HPT+xzpTPdHUB8HGzHQKDlYaZ1odRDfVtbW7ExOLe6x8FZhGXSfufYNa OxQ90zwh2JDz0pwdVjh0QTVSYwy6Mp81bpd25Q4TAEG7CwWDF/+x9NZrG46zps8+sk10S9oHi MGJXXqDntGrLvWn/6sSNNTf8/6CnVIhQLOb9JjXIWCsknYhj3lIkmnq2YdzhvPqjAex1kiiY6 xNzVEB5NTmC6E3CyLtxG47nJ45T0vwJdMRz1XerztotZDC6VnEJp678O1OwIm/klCjGN65P6A QcJdN4t2Tbmk9A/ymApfSbrJnZBRr+GtNJSFcsrJKBqMiar0yU8xNFRwkP4YoaaMjZGDGpuin GFacwNz9UBobuZz9RyzxkdqXcBkV+z1oIWL42gjJdE/ILcJRAnBC4ZV1O5a8PKPzMQj8wL57s HOXb/4mDIgfsvAcnn+hGp6kCvQqJaga5o/pueILWrcaY2Uo7z3Ms2oKhbBY7jUvutmakXvXUs RFyq1VoKyRrYXdz0us5TPfR6XdgPGkuJUTQzn93w/KfuSq5pfkKCaLZYhmRSWWUVzBROadUz4 lxB2JR+u+4ksPBm4w5X5nDBO/k1q0fjFduk4s9thzGcRYm0fkuaqEksgbRgplya9R54jjkHyE MQO1ZSZ6Y2aR445z2b1ukAElqBmABw712Mzurh0cvL6BZzmOVv88KppEKRVKJlLgYWTgS1G7T nkjBOD1Q8JW/HS53LkMsR1GMc4ose2QyAV+YfLK0zh0vyGp0h0Dziq8N8up3U/BVfWiIdnTYg b+ZgZ7H 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, when simplifying RESHAPE we hit a gcc_assert for negative entries in the SHAPE array. Obvious solution: replace gcc_assert by an error message. Regtested on x86_64-pc-linux-gnu. OK for mainline? As this is a safe fix, I'd like to backport to suitable branches. Thanks, Harald Fortran: generate error message for negative elements in SHAPE array gcc/fortran/ChangeLog: PR fortran/102717 * simplify.c (gfc_simplify_reshape): Replace assert by error message for negative elements in SHAPE array. gcc/testsuite/ChangeLog: PR fortran/102717 * gfortran.dg/reshape_shape_2.f90: New test. diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index f40e4930b58..d675f2c3aef 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -6840,7 +6840,13 @@ gfc_simplify_reshape (gfc_expr *source, gfc_expr *shape_exp, gfc_extract_int (e, &shape[rank]); gcc_assert (rank >= 0 && rank < GFC_MAX_DIMENSIONS); - gcc_assert (shape[rank] >= 0); + if (shape[rank] < 0) + { + gfc_error ("The SHAPE array for the RESHAPE intrinsic at %L has a " + "negative value %d for dimension %d", + &shape_exp->where, shape[rank], rank+1); + return &gfc_bad_expr; + } rank++; } diff --git a/gcc/testsuite/gfortran.dg/reshape_shape_2.f90 b/gcc/testsuite/gfortran.dg/reshape_shape_2.f90 new file mode 100644 index 00000000000..8f1757687bc --- /dev/null +++ b/gcc/testsuite/gfortran.dg/reshape_shape_2.f90 @@ -0,0 +1,7 @@ +! { dg-do compile } +! PR fortran/102717 + +program p + integer, parameter :: a(1) = 2 + integer, parameter :: b(2) = reshape([3,4], -[a]) ! { dg-error "negative" } +end