From patchwork Tue Feb 11 15:25:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mark Eggleston X-Patchwork-Id: 1236353 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519346-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=codethink.co.uk Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=DBU4Itqy; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48H66r6N3nz9sP7 for ; Wed, 12 Feb 2020 02:25:56 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=wuv8ahlouBSj+jj/pqTHZFjn9AGSCH6j2yVh9joQDc/xXHAsSz m0LGT7lu26Y1OWuj1zlRhe/vKFQEF7GjGU8J80w0qgDh8GhOUN16kh7RHnibZSYa dud/NxHcuiWNXOy+eH59Z9xLlKLdH0bPKi0GJCWrRk4l5ckTToQVKT8x4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=kGhRyaqTdz33h88pmJGdb7WN48o=; b=DBU4ItqylZqvTEcw5NZ2 TufM+KNwKHW/jRng/cxslWOOR7yDmPnDGCq2Da9wEhq0SchjaJGzjw7CeevLBfN9 Q+Rr7XkltcBddJ33uY215/kvKajQY3wYu0CSRhRrLod0HGcnKZJxPgK4coBAf4RL j5cN7ebzmweLOMpzIP0PgzA= Received: (qmail 84848 invoked by alias); 11 Feb 2020 15:25:48 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 84713 invoked by uid 89); 11 Feb 2020 15:25:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_COUK, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: imap3.hz.codethink.co.uk Received: from imap3.hz.codethink.co.uk (HELO imap3.hz.codethink.co.uk) (176.9.8.87) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Feb 2020 15:25:44 +0000 Received: from [167.98.27.226] (helo=[10.35.5.172]) by imap3.hz.codethink.co.uk with esmtpsa (Exim 4.92 #3 (Debian)) id 1j1XPy-0003Jz-N4; Tue, 11 Feb 2020 15:25:42 +0000 To: gcc-patches , fortran From: Mark Eggleston Subject: [9/10 Regression, PATCH] fortran: ICE in gfc_validate_kind(): Got bad kind [PR93580] Message-ID: <0f6bcd37-600e-e5b8-38be-9bbb498eae92@codethink.co.uk> Date: Tue, 11 Feb 2020 15:25:42 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 Please find attached a patch, it is based on Steve Kargl's patch in PR93580 adding  a check for %len and test case. The commit message in the patch includes change logs as I believe that is the intended way forward. One thing I'm unsure of it how handle multiple authors, it was easy in the ChangeLog files but it is not obvious for git commit messages. OK for master and gcc 9 branch? gcc/fortran/ChangeLog:     Steven G. Kargl     Mark Eggleston     PR fortran/93580     * primary.c (gfc_match_varspec): If the symbol following %     is re or im and the primary expression type is not BT_COMPLEX     issue an error. If the symbol is len and the primary     expression type is not BT_CHARACTER is an error. gcc/testsuite/ChangeLog:     Mark Eggleston     PR fortran/93580     * gfortran.dg/dg/pr93580.f90: New test. From 2d4fddda1ccd981c9956f798b3ed4871d8fcb4f1 Mon Sep 17 00:00:00 2001 From: Mark Eggleston Date: Wed, 5 Feb 2020 10:38:37 +0000 Subject: [PATCH] fortran: ICE in gfc_validate_kind(): Got bad kind [PR93580] Caused by using invalid part_refs in kind specifications, e.g. %re or %im on non-complex expressions and %len on non character expressions. Check whether %re, %im and %len are valid when checking kind specification. The original patch from Steven G. Kargl only checked for %re and %im. gcc/fortran/ChangeLog: PR fortran/93580 * primary.c (gfc_match_varspec): If the symbol following % is re or im and the primary expression type is not BT_COMPLEX issue an error. If the symbol is len and the primary expression type is not BT_CHARACTER is an error. gcc/testsuite/ChangeLog: PR fortran/93580 * gfortran.dg/dg/pr93580.f90: New test. --- gcc/fortran/primary.c | 24 ++++++++++++++++++++++-- gcc/testsuite/gfortran.dg/pr93580.f90 | 13 +++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr93580.f90 diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c index bd50827bb15..d73898473df 100644 --- a/gcc/fortran/primary.c +++ b/gcc/fortran/primary.c @@ -2241,8 +2241,28 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag, if (inquiry) sym = NULL; - if (sep == '%' && primary->ts.type != BT_UNKNOWN) - intrinsic = true; + if (sep == '%') + { + if (tmp) + { + if ((tmp->u.i == INQUIRY_RE || tmp->u.i == INQUIRY_IM) + && primary->ts.type != BT_COMPLEX) + { + gfc_error ("The RE or IM part_ref at %C must be " + "applied to a COMPLEX expression"); + return MATCH_ERROR; + } + else if (tmp->u.i == INQUIRY_LEN + && primary->ts.type != BT_CHARACTER) + { + gfc_error ("The LEN part_ref at %C must be applied " + "to a CHARACTER expression"); + return MATCH_ERROR; + } + } + if (primary->ts.type != BT_UNKNOWN) + intrinsic = true; + } } else inquiry = false; diff --git a/gcc/testsuite/gfortran.dg/pr93580.f90 b/gcc/testsuite/gfortran.dg/pr93580.f90 new file mode 100644 index 00000000000..4feaa112914 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr93580.f90 @@ -0,0 +1,13 @@ +! { dg-do compile } +! PR fortran/93580 + +program p + integer, parameter :: n = 4 + complex(n%re) :: x ! { dg-error "The RE or IM part_ref at" } + complex(n%im) :: y ! { dg-error "The RE or IM part_ref at" } + complex(n%len) :: z ! { dg-error "The LEN part_ref at" } + character(n%im) :: a ! { dg-error "The RE or IM part_ref at" } + character(n%re) :: b ! { dg-error "The RE or IM part_ref at" } + character(n%len) :: c ! { dg-error "The LEN part_ref at" } +end + -- 2.11.0