public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, fortran] Fix PR 89496, error with alternate return
@ 2019-02-25 22:28 Thomas König
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas König @ 2019-02-25 22:28 UTC (permalink / raw)
  To: fortran, gcc-patches

Hello world,

the attached patch fixes a regression introduced by my recent patch for
PR 87689, where the alternate return arguments were not handled
correctly.

Some experimentation resulted in a test case which actually segfaulted
on a normal compiler, instead of just being visible on an instrumened
one.  The test case also checks that the alternate return runs
correctly (and uses the "dg-do  run" hack :-)

I also checked this with -flto and by inspecting the output of
-fdump-fortran-original.

Thanks to Martin Liska for the bug report.

Regression-tested.  OK for trunk?

Regards

	Thomas

2019-02-25  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/89496
	* trans-types.c (get_formal_from_actual_arglist): If
	the actual arglist has no expression, the corresponding
	formal arglist is an alternate return.

2019-02-25  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/89496
	* gfortran.dg/altreturn_9_0.f90: New file.
	* gfortran.dg/altreturn_9_1.f90: New file.

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

* Re: [patch, fortran] Fix PR 89496, error with alternate return
  2019-02-26  7:19 ` Thomas Koenig
@ 2019-02-26  8:26   ` Janne Blomqvist
  0 siblings, 0 replies; 4+ messages in thread
From: Janne Blomqvist @ 2019-02-26  8:26 UTC (permalink / raw)
  To: Thomas Koenig; +Cc: gfortran, gcc-patches

On Tue, Feb 26, 2019 at 9:19 AM Thomas Koenig <tkoenig@netcologne.de> wrote:
>
> Hi Dominique,
>
>
> > AFAICT there is no patch attached.
>
> I guess that would have helped :-)
>
> Here it is.

Ok, thanks.


-- 
Janne Blomqvist

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

* Re: [patch, fortran] Fix PR 89496, error with alternate return
  2019-02-25 23:13 Dominique d'Humières
@ 2019-02-26  7:19 ` Thomas Koenig
  2019-02-26  8:26   ` Janne Blomqvist
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Koenig @ 2019-02-26  7:19 UTC (permalink / raw)
  To: gfortran; +Cc: gcc-patches

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

Hi Dominique,


> AFAICT there is no patch attached.

I guess that would have helped :-)

Here it is.


2019-02-25  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/89496
         * trans-types.c (get_formal_from_actual_arglist): If
         the actual arglist has no expression, the corresponding
         formal arglist is an alternate return.

2019-02-25  Thomas Koenig  <tkoenig@gcc.gnu.org>

         PR fortran/89496
         * gfortran.dg/altreturn_9_0.f90: New file.
         * gfortran.dg/altreturn_9_1.f90: New file.

[-- Attachment #2: altreturn_9_1.f90 --]
[-- Type: text/x-fortran, Size: 162 bytes --]

! { dg-do compile }
! { dg-options "-std=gnu" }
! See altreturn_9_0.f90
subroutine sub(i, *, j)
  if (i == 10 .and. j == 20) return 1
  return
end subroutine sub

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

! { dg-do  run }
! { dg-options -std=gnu }
! { dg-additional-sources altreturn_9_1.f90 }
! PR 89496 - wrong type for alternate return was generated

program main
  call sub(10, *10, 20)
  stop 1
10 continue
end program main

[-- Attachment #4: pr2.diff --]
[-- Type: text/x-patch, Size: 818 bytes --]

Index: trans-types.c
===================================================================
--- trans-types.c	(Revision 269161)
+++ trans-types.c	(Arbeitskopie)
@@ -2988,9 +2988,9 @@ get_formal_from_actual_arglist (gfc_symbol *sym, g
   f = &sym->formal;
   for (a = actual_args; a != NULL; a = a->next)
     {
+      (*f) = gfc_get_formal_arglist ();
       if (a->expr)
 	{
-	  (*f) = gfc_get_formal_arglist ();
 	  snprintf (name, GFC_MAX_SYMBOL_LEN, "_formal_%d", var_num ++);
 	  gfc_get_symbol (name, NULL, &s);
 	  if (a->expr->ts.type == BT_PROCEDURE)
@@ -3012,6 +3012,9 @@ get_formal_from_actual_arglist (gfc_symbol *sym, g
 	  s->attr.intent = INTENT_UNKNOWN;
 	  (*f)->sym = s;
 	}
+      else  /* If a->expr is NULL, this is an alternate rerturn.  */
+	(*f)->sym = NULL;
+
       f = &((*f)->next);
     }
 }

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

* Re: [patch, fortran] Fix PR 89496, error with alternate return
@ 2019-02-25 23:13 Dominique d'Humières
  2019-02-26  7:19 ` Thomas Koenig
  0 siblings, 1 reply; 4+ messages in thread
From: Dominique d'Humières @ 2019-02-25 23:13 UTC (permalink / raw)
  To: Thomas Koenig; +Cc: gfortran

Hi Thomas,

AFAICT there is no patch attached.

TIA

Dominique

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

end of thread, other threads:[~2019-02-26  8:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-25 22:28 [patch, fortran] Fix PR 89496, error with alternate return Thomas König
2019-02-25 23:13 Dominique d'Humières
2019-02-26  7:19 ` Thomas Koenig
2019-02-26  8:26   ` Janne Blomqvist

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