public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Cesar Philippidis <cesar_philippidis@mentor.com>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
	Fortran List	<fortran@gcc.gnu.org>
Subject: [PATCH] Fix PR77765
Date: Thu, 29 Jun 2017 15:55:00 -0000	[thread overview]
Message-ID: <bed70e00-5717-6174-c0cc-696ced9753c5@mentor.com> (raw)

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

PR77765 exposed an ICE triggered in gfortran's acc routine parser by an
uninitialized proc_name. That situation occurred because the function
containing the acc routine directive has an error, so
gfc_current_ns->proc_name was never set.

Although it could be argued that the acc routine parser should not run
if any errors have been detected inside the routine containing such a
directive, this patch just teaches gfc_match_oacc_routine to check for
the existence of gfc_current_ns->proc_name before comparing the
procedure's name with the routine name specified by the user.

Is this patch OK for trunk and gcc7?

Thanks,
Cesar

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

2017-06-29  Cesar Philippidis  <cesar@codesourcery.com>

	PR fortran/77765
	gcc/fortran/
	* openmp.c (gfc_match_oacc_routine): Check if proc_name exist before
	comparing the routine name against it.

	gcc/testsuite/
	* gfortran.dg/goacc/pr77765.f90: New test.


diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index 1d191d2..236ecb2 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -2474,7 +2474,8 @@ gfc_match_oacc_routine (void)
 	  if (st)
 	    {
 	      sym = st->n.sym;
-	      if (strcmp (sym->name, gfc_current_ns->proc_name->name) == 0)
+	      if (gfc_current_ns->proc_name != NULL
+		  && strcmp (sym->name, gfc_current_ns->proc_name->name) == 0)
 	        sym = NULL;
 	    }
 	  else if (isym == NULL)
diff --git a/gcc/testsuite/gfortran.dg/goacc/pr77765.f90 b/gcc/testsuite/gfortran.dg/goacc/pr77765.f90
new file mode 100644
index 0000000..3819cf7
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/pr77765.f90
@@ -0,0 +1,19 @@
+! Test the presence of an ACC ROUTINE directive inside a function
+! containg an error.
+
+! { dg-do compile }
+
+module m
+contains
+  recursive function f(x)
+  end function f
+  recursive function f(x)
+    !$acc routine (f)
+  end function f
+end module m
+
+! { dg-error "Procedure 'f' at .1. is already defined" "" { target *-*-* } 8 }
+! { dg-error "Duplicate RECURSIVE attribute specified" "" { target *-*-* } 8 }
+! { dg-error ".1." "" { target *-*-* } 10 }
+! { dg-error "Unexpected ..ACC ROUTINE" "" { target *-*-* } 11 }
+! { dg-error "Expecting END MODULE statement" "" { target *-*-* } 12 }

             reply	other threads:[~2017-06-29 15:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-29 15:55 Cesar Philippidis [this message]
2017-06-29 17:36 ` Jakub Jelinek

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=bed70e00-5717-6174-c0cc-696ced9753c5@mentor.com \
    --to=cesar_philippidis@mentor.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).