public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Paul Richard Thomas <paul.richard.thomas@gmail.com>
To: "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [Patch, fortran] PR96325 - Unclassifiable statement with syntax similar to a type-bound procedure call is accepted
Date: Sat, 1 Aug 2020 11:23:03 +0100	[thread overview]
Message-ID: <CAGkQGiLyH+xDomCKLoXnMiQCJ8PDiEBHfKWF1xKHovrsRa=dGg@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 509 bytes --]

The attached patch regtests on FC31/x86_64 - OK for trunk?

Cheers

Paul

Commit message:

This patch fixes PR96325. See the explanatory comment in the testcase.

2020-08-01  Paul Thomas  <pault@gcc.gnu.org>

gcc/fortran
PR target/96325
* primary.c (gfc_match_varspec): In the case that a component
reference is added to an intrinsic type component, emit the
error message in this function.

gcc/testsuite/
PR target/96325
* gfortran.dg/pr96325.f90: New test.
* gfortran.dg/pr91589.f90: Update error message.

[-- Attachment #2: submit.diff --]
[-- Type: text/x-patch, Size: 1657 bytes --]

diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c
index c0f66d3df22..a58a25924da 100644
--- a/gcc/fortran/primary.c
+++ b/gcc/fortran/primary.c
@@ -2023,7 +2023,8 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag,
 {
   char name[GFC_MAX_SYMBOL_LEN + 1];
   gfc_ref *substring, *tail, *tmp;
-  gfc_component *component;
+  gfc_component *component = NULL;
+  gfc_component *previous = NULL;
   gfc_symbol *sym = primary->symtree->n.sym;
   gfc_expr *tgt_expr = NULL;
   match m;
@@ -2343,15 +2344,19 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag,
 	  break;
 	}
 
+      previous = component;
+
       if (!inquiry && !intrinsic)
 	component = gfc_find_component (sym, name, false, false, &tmp);
       else
 	component = NULL;
 
-      /* In some cases, returning MATCH_NO gives a better error message. Most
-	 cases return "Unclassifiable statement at..."  */
       if (intrinsic && !inquiry)
-	return MATCH_NO;
+       {
+	  gfc_error ("%qs at %C is not an inquiry reference to an intrinsic "
+		     "type component %qs", name, previous->name);
+	  return MATCH_ERROR;
+       }
       else if (component == NULL && !inquiry)
 	return MATCH_ERROR;
 
diff --git a/gcc/testsuite/gfortran.dg/pr91589.f90 b/gcc/testsuite/gfortran.dg/pr91589.f90
index d02cb64bfc2..375d895e0b7 100644
--- a/gcc/testsuite/gfortran.dg/pr91589.f90
+++ b/gcc/testsuite/gfortran.dg/pr91589.f90
@@ -10,6 +10,6 @@ program p
       integer :: a
    end type
    type(t) :: x = t(1)
-   call sub (x%a%a)   ! { dg-error "Syntax error in argument list" }
+   call sub (x%a%a)   ! { dg-error "is not an inquiry reference" }
 end
 

[-- Attachment #3: pr96325.f90 --]
[-- Type: text/x-fortran, Size: 475 bytes --]

! { dg-do run }
!
! Test the fix for PR96325 in which the typebound procedure reference
! 'foo' was applied to an intrinsic type component without generating
! an error. The result of the expression was the value of the arg..
!
! Contributed by Gerhardt Steinmetz  <gscfq@t-online.de>
!
   implicit none

   type t2
      integer r1
   end type

   type(t2) :: t
   integer :: a

   a = t%r1%foo(1)     { dg-error "is not an inquiry reference" }
   if (a == 42) stop

   end

             reply	other threads:[~2020-08-01 10:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-01 10:23 Paul Richard Thomas [this message]
2020-08-01 18:13 ` Thomas Koenig
2020-08-02 14:30 dhumieres.dominique

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGkQGiLyH+xDomCKLoXnMiQCJ8PDiEBHfKWF1xKHovrsRa=dGg@mail.gmail.com' \
    --to=paul.richard.thomas@gmail.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).