From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32180 invoked by alias); 5 Sep 2019 04:51:03 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 32167 invoked by uid 89); 5 Sep 2019 04:51:02 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-8.2 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS autolearn=ham version=3.3.1 spammy=Gerhard, gfc_error, match_error, x86_64-*-freebsd X-HELO: troutmask.apl.washington.edu Received: from troutmask.apl.washington.edu (HELO troutmask.apl.washington.edu) (128.95.76.21) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Sep 2019 04:51:01 +0000 Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.15.2/8.15.2) with ESMTPS id x854owrF005980 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Wed, 4 Sep 2019 21:50:58 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.15.2/8.15.2/Submit) id x854owLr005979; Wed, 4 Sep 2019 21:50:58 -0700 (PDT) (envelope-from sgk) Date: Thu, 05 Sep 2019 04:51:00 -0000 From: Steve Kargl To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] PR fortran/91660 -- Improve and restore error messages Message-ID: <20190905045058.GA5972@troutmask.apl.washington.edu> Reply-To: sgk@troutmask.apl.washington.edu MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="17pEHd4RhPHOinZp" Content-Disposition: inline User-Agent: Mutt/1.12.1 (2019-06-15) X-SW-Source: 2019-09/txt/msg00236.txt.bz2 --17pEHd4RhPHOinZp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 655 Built and regression tested on x86_64-*-freebsd. The patch restores an improved error message for a malformed type-spec. See pr91660_1.f90 for code demonstrating problem. While here, improve the error messages for other malformed type-specs. Sett pr91660_2.f90. OK to commit? 2019-09-04 Steven G. Kargl PR fortran/91660 * decl.c (gfc_match_decl_type_spec): Improve and restore error message for malformed types-spec. 2019-09-04 Steven G. Kargl PR fortran/91660 * gfortran.dg/pdt_4.f03: Fix invalid code. * gfortran.dg/pr91660_1.f90: New test. * gfortran.dg/pr91660_2.f90: Ditto. -- Steve --17pEHd4RhPHOinZp Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="pr91660.diff" Content-length: 3595 Index: gcc/fortran/decl.c =================================================================== --- gcc/fortran/decl.c (revision 275390) +++ gcc/fortran/decl.c (working copy) @@ -4023,7 +4023,6 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implic return MATCH_YES; } - m = gfc_match (" type ("); matched_type = (m == MATCH_YES); if (matched_type) @@ -4071,7 +4070,10 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implic m = MATCH_YES; if (matched_type && m == MATCH_YES && gfc_match_char (')') != MATCH_YES) - m = MATCH_ERROR; + { + gfc_error ("Malformed type-spec at %C"); + return MATCH_ERROR; + } return m; } @@ -4094,8 +4096,12 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implic && !gfc_notify_std (GFC_STD_F2008, "TYPE with " "intrinsic-type-spec at %C")) return MATCH_ERROR; + if (matched_type && gfc_match_char (')') != MATCH_YES) - return MATCH_ERROR; + { + gfc_error ("Malformed type-spec at %C"); + return MATCH_ERROR; + } ts->type = BT_REAL; ts->kind = gfc_default_double_kind; @@ -4125,7 +4131,10 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implic return MATCH_ERROR; if (matched_type && gfc_match_char (')') != MATCH_YES) - return MATCH_ERROR; + { + gfc_error ("Malformed type-spec at %C"); + return MATCH_ERROR; + } ts->type = BT_COMPLEX; ts->kind = gfc_default_double_kind; @@ -4146,7 +4155,13 @@ gfc_match_decl_type_spec (gfc_typespec *ts, int implic if (m == MATCH_ERROR) return m; - m = gfc_match_char (')'); + gfc_gobble_whitespace (); + if (gfc_peek_ascii_char () != ')') + { + gfc_error ("Malformed type-spec at %C"); + return MATCH_ERROR; + } + m = gfc_match_char (')'); /* Burn closing ')'. */ } if (m != MATCH_YES) Index: gcc/testsuite/gfortran.dg/pdt_4.f03 =================================================================== --- gcc/testsuite/gfortran.dg/pdt_4.f03 (revision 275390) +++ gcc/testsuite/gfortran.dg/pdt_4.f03 (working copy) @@ -97,9 +97,9 @@ contains type (mytype(4, *)) :: arg ! OK end subroutine subroutine bar(arg) ! { dg-error "is neither allocatable nor a pointer" } - type (thytype(8, :, 4) :: arg + type (thytype(8, :, 4)) :: arg end subroutine subroutine foobar(arg) ! OK - type (thytype(8, *, 4) :: arg + type (thytype(8, *, 4)) :: arg end subroutine end Index: gcc/testsuite/gfortran.dg/pr91660_1.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr91660_1.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr91660_1.f90 (working copy) @@ -0,0 +1,9 @@ +! { dg-do compile } +! PR fortran/91660 +! Code contributed by Gerhard Steinmetz +program p + type t + end type + type (t x ! { dg-error "Malformed type-spec" } + x = t() ! { dg-error "Cannot convert" } +end Index: gcc/testsuite/gfortran.dg/pr91660_2.f90 =================================================================== --- gcc/testsuite/gfortran.dg/pr91660_2.f90 (nonexistent) +++ gcc/testsuite/gfortran.dg/pr91660_2.f90 (working copy) @@ -0,0 +1,9 @@ +! { dg-do compile } +! PR fortran/91660 +program foo + type(doubleprecision :: x ! { dg-error "Malformed type-spec" } + type(double precision :: y ! { dg-error "Malformed type-spec" } + type(character(len=3) :: a ! { dg-error "Malformed type-spec" } + type(doublecomplex :: b ! { dg-error "Malformed type-spec" } + type(double complex :: c ! { dg-error "Malformed type-spec" } +end program foo --17pEHd4RhPHOinZp--