public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Cesar Philippidis <cesar@codesourcery.com>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
	Fortran List	<fortran@gcc.gnu.org>
Subject: [gomp4] Fix an ICE involving OpenACC routines inside broken fortran functions.
Date: Thu, 27 Apr 2017 22:54:00 -0000	[thread overview]
Message-ID: <305d82b4-08de-fed7-b4f4-ec1c059e0ad3@codesourcery.com> (raw)

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

I encountered an ICE when the fortran FE tries to parse an OpenACC
routine directive when the containing function has a syntax error. E.g.

  integer function f1

is missing an argument list, so the fortran FE will not create a
function symbol for f1. Consequently, the OpenACC routine parser cannot
register the routine directive with any function, so it hit a
gcc_unreachable.

This patch replaces that gcc_unreachable with a match_error. While the
syntax of the routine directive may be correct, it is still an error to
have a dangling acc routine directive not associated with a function.

I've applied this patch to gomp-4_0-branch.

Cesar

[-- Attachment #2: gomp4-broken-routine-ice.diff --]
[-- Type: text/x-patch, Size: 1234 bytes --]

2017-04-27  Cesar Philippidis  <cesar@codesourcery.com>

	gcc/fortran/
	* openmp.c (gfc_match_oacc_routine): Don't match OpenACC routines
	when the current function failed to parse due to a syntax error.

	gcc/testsuite/
	* gfortran.dg/goacc/routine-10.f90: New test.


diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index 0aecda4..72c6669 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -2576,7 +2576,9 @@ gfc_match_oacc_routine (void)
 	goto cleanup;
     }
   else
-    gcc_unreachable ();
+    /* Something has gone wrong.  Perhaps there was a syntax error
+       in the program-stmt.  */
+    goto cleanup;
 
   if (n)
     n->clauses = c;
diff --git a/gcc/testsuite/gfortran.dg/goacc/routine-10.f90 b/gcc/testsuite/gfortran.dg/goacc/routine-10.f90
new file mode 100644
index 0000000..4d8b5ba
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/goacc/routine-10.f90
@@ -0,0 +1,8 @@
+! Ensure that GFortran doesn't ICE with incomplete function
+! definitions.
+
+! { dg-do compile }
+
+integer function f1 ! { dg-error "Expected formal argument list in function definition" }
+  !$acc routine ! { dg-error "Unclassifiable OpenACC directive" }
+end function f1 ! { dg-error "Expecting END PROGRAM statement" }

         reply	other threads:[~2017-04-27 22:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-02 15:06 [patch,openacc] Check clauses with intrinsic function specified in !$ACC ROUTINE ( NAME ) Cesar Philippidis
2017-04-27 22:54 ` Cesar Philippidis [this message]
2016-08-12 16:16   ` [PR fortran/72741] Handle intrinsic functions " Thomas Schwinge
2019-02-28 20:37     ` [PR72741, PR89433] Accept intrinsic symbols in Fortran OpenACC 'routine' directives Thomas Schwinge

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=305d82b4-08de-fed7-b4f4-ec1c059e0ad3@codesourcery.com \
    --to=cesar@codesourcery.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).