From patchwork Tue Feb 21 21:18:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 60263 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp229623wrd; Tue, 21 Feb 2023 13:25:09 -0800 (PST) X-Google-Smtp-Source: AK7set99/I8WpavBBiYNzM0xZkvhJITxkaAZ16GMpG/KSrDq4KxgPkbZbEz6lDDbzx5I7a/Wnwmv X-Received: by 2002:a05:6402:8c6:b0:4ac:be53:178e with SMTP id d6-20020a05640208c600b004acbe53178emr4769803edz.6.1677014709504; Tue, 21 Feb 2023 13:25:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677014709; cv=none; d=google.com; s=arc-20160816; b=hWnb3r5s15CknxQLuAeAjyJSvX8jrtI9YciPj/QNopTNv+648zDAAiwd0rvTDzSWqh +MhY6mp71APFybJd1/hkMhFAArG7K6a5rL0fRl8/61hUuPCa8Thl9y/+HOP0DIRp65qf oJELK8pX6FEI3JhH5PLT0yPBovTROLrApw2D/TGq5p+GUTdu5V2nU4ajs+pi2H1zJXqg n0xBYw7hdQtA18DOrcmB1Won6Uu8OEdAwAstDeTVfrbB9ahQ9Dk3Q/1xgpiJOTwL10oV 67EdjGdBISKPNqcXpXfl5WHX4rUQttOx6/CtYwmWsmrlR1L2jTwNBJcCRLn747FHXZTb LD7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:ui-outboundreport :sensitivity:importance:date:subject:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=xjITqjC+TAsFUs1/+PgBVcRNpb+0WeyFCinnCTIwYso=; b=jydmX0+40cwyrcQo8DAw3TQVwbLTnveF6bK0dYUOwNGH+E9wGWZFhCzqqz0FVHJea+ TlMuty65b0aOvSVQqEnsZeoxOH0DKm2vbHdbaae1YG/Z7KBrFbGLF7e2lPIhUC1HLOM5 jkWFgrTa2DKIJ1DVSJyrAJ0HpCp6nzTPiMtuTmnzum/wd5WWYAgbVGP611uXKx1OOyBa RDjQTrJ5uxQZrQtPZ/2UIwNT1d9vsLKvyBzi5vMcDoCLuE85yG+QsoCmecKKZxgB/IHa lw1xbqAA6h3RFKjTB2ElPMvVM4moQMSeWPuwquuwJ3bFqdr6+o+3KX3tfXExmflZkziJ lM7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=AijzQ7td; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ay27-20020a056402203b00b004ad8da3f37bsi11102235edb.323.2023.02.21.13.25.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 13:25:09 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=AijzQ7td; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 574D43858431 for ; Tue, 21 Feb 2023 21:25:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 574D43858431 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677014708; bh=xjITqjC+TAsFUs1/+PgBVcRNpb+0WeyFCinnCTIwYso=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=AijzQ7tdfT3YAnWZB5/kJTcORLwIEoXb2PVRhzyV/SmLRMSjgMfJWIVH6fBCZcCUD jBgpvsxXDjA4E12MAk9teLCfxQVLsWufII23Pe0Bj8iByaWKHMBx9H+WnJ3FES3cDI jqiUXqdn2L5SYItTsgFLUSAsWLicQLALBarQJ6ro= 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 B48213858D35; Tue, 21 Feb 2023 21:24:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B48213858D35 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [79.251.13.208] ([79.251.13.208]) by web-mail.gmx.net (3c-app-gmx-bs33.server.lan [172.19.170.85]) (via HTTP); Tue, 21 Feb 2023 22:18:58 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: reject invalid CHARACTER length of derived type components [PR96024] Date: Tue, 21 Feb 2023 22:18:58 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:3K7oFZa9dnTRaIPtR+Uy+CK5B13+Cz2T3rrTyd+eYPi5Vlp3ftqj3iRzNJXZSm4zW+Zpj 4QiFRn9U8ANZ1FlGGn1Etrc6eAVSfHkPuwV4hVAhMKeftc3+OcQ7Z9q8CUdTWXswy+gP30WaKm2P mbSUInRUuCIUMe+/9CBJ+B4Lo2Io3sDMNHenjivnu7FnLn1p0strlyfHy6l0Hy1NmGF6v3eDRKFL XAP/rxqMzRdwIE/8qQcR2G/YuWUGK0w/yAtU4ZZe4HZw4wdg858aOOdyBkN70pvgm+HtGv9v7d3W zg= UI-OutboundReport: notjunk:1;M01:P0:9y4bBcsFReA=;Wai11xYUSIKzE2zQiA/22kmhrHT 8tbp4tUxFhfJeRDiMsRsCtsMUOxRYH+CtwHm1wZWidpABP7Dpw8Nygk5Ab/I+BWpInA8EAzIu 0K8x9VjYZNhE73VPlxnUT/LHhb/K9vgTGMNCJFmIvVjz7YKux/HuN3bK+GGi995Zm+JiOLr77 9n7nWoXFHakrlN6oegUuAasBg21zA3UojCFSzce5h3Xj4I6s8EID0MBNbrDqFDYgKfXdGzX17 epbmXS+AlMTXxEepc9PyTOmklIfoDtr/WHkQHqJI8rts13sNQCW+HlpHKnIe1AMydZXljOBfN ZqiBipUIZUExb61uUxlhVuJ+Ak6cIBi4f/4kIOXBsan1NDREwtQlSot5Ng174stfSa6XtedBx ljF78wFroepX2FtrK5PUm25rAA/fP9BA1NObV3V/F4qzwNwck3G8Zs9r62PNiBZKxMwK0lp28 pnWdWFPhrMehF/vrbBz6FWVFzelpcQe6l08VOR2XUKN+HRmOFMHVsPh3Ai3GVbc+tNnue4uaU KL9IxsoStBpAnTOOHXxUih0Ni62VuWqdHryHFvQ/DY2haRXdA7/I1PubtkO8MfKDXLt5vRDkV r6D9OYYGiWzXypyuFPx6PENk69cSLz566hEPn877bHkSi8AKccXhVL22kxC3kF57DeFwFP8nH aM1w+HD8Nbrs81GCheFiuy7MX5HKbgPU4OnOo3kkZz/pgm1xq3y3RzSSWdSLXgNnBNzkH6wRY lQZ9h4FDFT1kxXGR/04V31k0s/VqXFec/A5fZwfptJ+1Z80fEgPTprOG3ySoszL6OqpEJe6JJ tTA8Du9dC0XD3yvltU878/3A== X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758477376166110029?= X-GMAIL-MSGID: =?utf-8?q?1758477376166110029?= Dear all, the attached simple patch detects and rejects CHARACTER components of derived types whose length specification is non-integer. Regtested on x86_64-pc-linux-gnu. OK for mainline? This PR is also marked as a 10/11/12/13 regression, so I would like to backport this as far as it seems reasonable. Thanks, Harald From 0a392415cb5d5486e3e660880c81d6fdbbb47285 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Tue, 21 Feb 2023 22:06:33 +0100 Subject: [PATCH] Fortran: reject invalid CHARACTER length of derived type components [PR96024] gcc/fortran/ChangeLog: PR fortran/96024 * resolve.cc (resolve_component): The type of a CHARACTER length expression must be INTEGER. gcc/testsuite/ChangeLog: PR fortran/96024 * gfortran.dg/pr96024.f90: New test. --- gcc/fortran/resolve.cc | 13 +++++++++++++ gcc/testsuite/gfortran.dg/pr96024.f90 | 11 +++++++++++ 2 files changed, 24 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pr96024.f90 diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 427f901a438..2780c82c798 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -14892,6 +14892,19 @@ resolve_component (gfc_component *c, gfc_symbol *sym) c->ts.u.cl->length ? &c->ts.u.cl->length->where : &c->loc); return false; } + + if (c->ts.u.cl->length && c->ts.u.cl->length->ts.type != BT_INTEGER) + { + if (!c->ts.u.cl->length->error) + { + gfc_error ("Character length expression of component %qs at %L " + "must be of INTEGER type, found %s", + c->name, &c->ts.u.cl->length->where, + gfc_basic_typename (c->ts.u.cl->length->ts.type)); + c->ts.u.cl->length->error = 1; + } + return false; + } } if (c->ts.type == BT_CHARACTER && c->ts.deferred diff --git a/gcc/testsuite/gfortran.dg/pr96024.f90 b/gcc/testsuite/gfortran.dg/pr96024.f90 new file mode 100644 index 00000000000..2c914a997f2 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr96024.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! PR fortran/96024 - ICE in mio_name_expr_t +! Contributed by G.Steinmetz + +module m + implicit none + type t + character(char(1)) :: a ! { dg-error "must be of INTEGER type" } + end type + type(t) :: z = t('a') +end -- 2.35.3