public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/85780 -- alternate return and BIND(C) conflict
@ 2019-01-25  5:15 Steve Kargl
  2019-01-25  8:11 ` Paul Richard Thomas
  0 siblings, 1 reply; 2+ messages in thread
From: Steve Kargl @ 2019-01-25  5:15 UTC (permalink / raw)
  To: fortran, gcc-patches

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

All,

My original patch for this PR simply fixed an ICE, which
then allowed the code to compile.  In reality, an alternate
return is not ISO C interoperable, so an error message is
a more appropriate response.  So, I re-opened the PR.

The attached patch has been tested on x86_64-*-freebsd.
OK to commit?

2019-01-24  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85780
	* decl.c (gfc_match_subroutine): Check for conflict between BIND(C)
	and alternative return.

2019-01-24  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85780
	* gfortran.dg/pr85780.f90: Update testcase for error message.

-- 
Steve

[-- Attachment #2: pr85780.diff --]
[-- Type: text/x-diff, Size: 2314 bytes --]

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c	(revision 268256)
+++ gcc/fortran/decl.c	(working copy)
@@ -7558,6 +7558,7 @@ gfc_match_subroutine (void)
   match is_bind_c;
   char peek_char;
   bool allow_binding_name;
+  locus loc;
 
   if (gfc_current_state () != COMP_NONE
       && gfc_current_state () != COMP_INTERFACE
@@ -7623,6 +7624,8 @@ gfc_match_subroutine (void)
   /* Here, we are just checking if it has the bind(c) attribute, and if
      so, then we need to make sure it's all correct.  If it doesn't,
      we still need to continue matching the rest of the subroutine line.  */
+  gfc_gobble_whitespace ();
+  loc = gfc_current_locus;
   is_bind_c = gfc_match_bind_c (sym, allow_binding_name);
   if (is_bind_c == MATCH_ERROR)
     {
@@ -7634,6 +7637,8 @@ gfc_match_subroutine (void)
 
   if (is_bind_c == MATCH_YES)
     {
+      gfc_formal_arglist *arg;
+
       /* The following is allowed in the Fortran 2008 draft.  */
       if (gfc_current_state () == COMP_CONTAINS
 	  && sym->ns->proc_name->attr.flavor != FL_MODULE
@@ -7647,8 +7652,17 @@ gfc_match_subroutine (void)
           gfc_error ("Missing required parentheses before BIND(C) at %C");
           return MATCH_ERROR;
         }
-      if (!gfc_add_is_bind_c (&(sym->attr), sym->name,
-			      &(sym->declared_at), 1))
+
+      /* Scan the dummy arguments for an alternate return.  */
+      for (arg = sym->formal; arg; arg = arg->next)
+	if (!arg->sym)
+	  {
+	    gfc_error ("Alternate return dummy argument cannot appear in a "
+		       "SUBROUTINE with the BIND(C) attribute at %L", &loc);
+	    return MATCH_ERROR;
+	  }
+
+      if (!gfc_add_is_bind_c (&(sym->attr), sym->name, &(sym->declared_at), 1))
         return MATCH_ERROR;
     }
 
Index: gcc/testsuite/gfortran.dg/pr85780.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr85780.f90	(revision 268256)
+++ gcc/testsuite/gfortran.dg/pr85780.f90	(working copy)
@@ -1,5 +1,6 @@
 ! { dg-do compile }
-! { dg-options "-std=legacy" }
+! { dg-options "-fmax-errors=1" }
 ! PR fortran/85780
-subroutine s(*) bind(c)
+subroutine s(*) bind(c)    ! { dg-error "Alternate return dummy argument" }
 end
+! { dg-prune-output "compilation terminated" } 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] PR fortran/85780 -- alternate return and BIND(C) conflict
  2019-01-25  5:15 [PATCH] PR fortran/85780 -- alternate return and BIND(C) conflict Steve Kargl
@ 2019-01-25  8:11 ` Paul Richard Thomas
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Richard Thomas @ 2019-01-25  8:11 UTC (permalink / raw)
  To: Steve Kargl; +Cc: fortran, gcc-patches

Hi Steve,

That's OK. Thanks

Paul

On Fri, 25 Jan 2019 at 01:50, Steve Kargl
<sgk@troutmask.apl.washington.edu> wrote:
>
> All,
>
> My original patch for this PR simply fixed an ICE, which
> then allowed the code to compile.  In reality, an alternate
> return is not ISO C interoperable, so an error message is
> a more appropriate response.  So, I re-opened the PR.
>
> The attached patch has been tested on x86_64-*-freebsd.
> OK to commit?
>
> 2019-01-24  Steven G. Kargl  <kargl@gcc.gnu.org>
>
>         PR fortran/85780
>         * decl.c (gfc_match_subroutine): Check for conflict between BIND(C)
>         and alternative return.
>
> 2019-01-24  Steven G. Kargl  <kargl@gcc.gnu.org>
>
>         PR fortran/85780
>         * gfortran.dg/pr85780.f90: Update testcase for error message.
>
> --
> Steve



-- 
"If you can't explain it simply, you don't understand it well enough"
- Albert Einstein

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-01-25  7:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-25  5:15 [PATCH] PR fortran/85780 -- alternate return and BIND(C) conflict Steve Kargl
2019-01-25  8:11 ` Paul Richard Thomas

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).