public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/99256] New: ICE in variable_check, at fortran/check.c:1012
@ 2021-02-24 17:31 gscfq@t-online.de
  2021-02-25 18:40 ` [Bug fortran/99256] " kargl at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: gscfq@t-online.de @ 2021-02-24 17:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99256

            Bug ID: 99256
           Summary: ICE in variable_check, at fortran/check.c:1012
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gscfq@t-online.de
  Target Milestone: ---

Affects versions down to at least r5 :


$ cat z1.f90
program p
   call move_alloc (*1, *1)
 1 stop
end


$ gfortran-11-20210221 -c z1.f90
f951: internal compiler error: Segmentation fault
0xc060ef crash_signal
        ../../gcc/toplev.c:327
0x6551b4 variable_check
        ../../gcc/fortran/check.c:1012
0x65c328 gfc_check_move_alloc(gfc_expr*, gfc_expr*)
        ../../gcc/fortran/check.c:4213
0x6a420c do_check
        ../../gcc/fortran/intrinsic.c:5129
0x6a420c gfc_intrinsic_sub_interface(gfc_code*, int)
        ../../gcc/fortran/intrinsic.c:5124
0x6fb649 resolve_unknown_s
        ../../gcc/fortran/resolve.c:3621
0x6fb649 resolve_call
        ../../gcc/fortran/resolve.c:3737
0x6f84dc gfc_resolve_code(gfc_code*, gfc_namespace*)
        ../../gcc/fortran/resolve.c:12032
0x6fa9a7 resolve_codes
        ../../gcc/fortran/resolve.c:17378
0x6faa6e gfc_resolve(gfc_namespace*)
        ../../gcc/fortran/resolve.c:17413
0x6e2fb4 resolve_all_program_units
        ../../gcc/fortran/parse.c:6290
0x6e2fb4 gfc_parse_file()
        ../../gcc/fortran/parse.c:6542
0x72f98f gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:212

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

* [Bug fortran/99256] ICE in variable_check, at fortran/check.c:1012
  2021-02-24 17:31 [Bug fortran/99256] New: ICE in variable_check, at fortran/check.c:1012 gscfq@t-online.de
@ 2021-02-25 18:40 ` kargl at gcc dot gnu.org
  2021-02-25 18:49 ` sgk at troutmask dot apl.washington.edu
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: kargl at gcc dot gnu.org @ 2021-02-25 18:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99256

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P4
   Last reconfirmed|                            |2021-02-25
                 CC|                            |kargl at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from kargl at gcc dot gnu.org ---
An interesting bug.  This catches the invalid alternate return, but
there is no locus available to actually point at the offending line
of code.

e is null, so e->where does not work.

gfc_current_locus seems to point at the line 'program p'.

In check_variable(), looking at gfc_current_intrinsic_arg[n]->actual,
there is locus information.

However, there is gfc_current_intrinsic_arg[n]->actual->label->where but
this points to the line '1 stop'.  IOW, it points to where the labeled 
statement is not the where the alternate return is used.  So, the offending
line of code isn't printed.

diff --git a/gcc/fortran/check.c b/gcc/fortran/check.c
index 82db8e4e1b2..63138cfa9bc 100644
--- a/gcc/fortran/check.c
+++ b/gcc/fortran/check.c
@@ -1009,6 +1009,14 @@ kind_value_check (gfc_expr *e, int n, int k)
 static bool
 variable_check (gfc_expr *e, int n, bool allow_proc)
 {
+  /* Expecting a variable, not an alternate return.  */
+  if (!e)
+    {
+      gfc_error ("%qs argument of %qs intrinsic must be a variable",
+                gfc_current_intrinsic_arg[n]->name, gfc_current_intrinsic);
+      return false;
+    }
+
   if (e->expr_type == EXPR_VARIABLE
       && e->symtree->n.sym->attr.intent == INTENT_IN
       && (gfc_current_intrinsic_arg[n]->intent == INTENT_OUT

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

* [Bug fortran/99256] ICE in variable_check, at fortran/check.c:1012
  2021-02-24 17:31 [Bug fortran/99256] New: ICE in variable_check, at fortran/check.c:1012 gscfq@t-online.de
  2021-02-25 18:40 ` [Bug fortran/99256] " kargl at gcc dot gnu.org
@ 2021-02-25 18:49 ` sgk at troutmask dot apl.washington.edu
  2021-12-12 21:47 ` anlauf at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: sgk at troutmask dot apl.washington.edu @ 2021-02-25 18:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99256

--- Comment #2 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Thu, Feb 25, 2021 at 06:40:13PM +0000, kargl at gcc dot gnu.org wrote:
> 
> In check_variable(), looking at gfc_current_intrinsic_arg[n]->actual,
> there is locus information.

there is *no* locus info.

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

* [Bug fortran/99256] ICE in variable_check, at fortran/check.c:1012
  2021-02-24 17:31 [Bug fortran/99256] New: ICE in variable_check, at fortran/check.c:1012 gscfq@t-online.de
  2021-02-25 18:40 ` [Bug fortran/99256] " kargl at gcc dot gnu.org
  2021-02-25 18:49 ` sgk at troutmask dot apl.washington.edu
@ 2021-12-12 21:47 ` anlauf at gcc dot gnu.org
  2022-01-13 22:39 ` anlauf at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-12-12 21:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99256

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gcc dot gnu.org

--- Comment #3 from anlauf at gcc dot gnu.org ---
We could get approximate locus info with e.g.

diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c
index 3682f9ae21f..78dfdbe7c92 100644
--- a/gcc/fortran/intrinsic.c
+++ b/gcc/fortran/intrinsic.c
@@ -5108,6 +5108,15 @@ gfc_intrinsic_sub_interface (gfc_code *c, int
error_flag)
   if (!do_ts29113_check (isym, c->ext.actual))
     goto fail;

+  gfc_actual_arglist *actual;
+  for (actual = c->ext.actual; actual; actual = actual->next)
+    if (actual->label)
+      {
+       gfc_error ("Label %d not allowed as argument of intrinsic %qs at %L",
+                  actual->label->value, name, &c->loc);
+       goto fail;
+      }
+
   if (isym->check.f1 != NULL)
     {
       if (!do_check (isym, c->ext.actual))

which regtests ok.

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

* [Bug fortran/99256] ICE in variable_check, at fortran/check.c:1012
  2021-02-24 17:31 [Bug fortran/99256] New: ICE in variable_check, at fortran/check.c:1012 gscfq@t-online.de
                   ` (2 preceding siblings ...)
  2021-12-12 21:47 ` anlauf at gcc dot gnu.org
@ 2022-01-13 22:39 ` anlauf at gcc dot gnu.org
  2022-01-13 23:08 ` kargl at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-01-13 22:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99256

--- Comment #4 from anlauf at gcc dot gnu.org ---
(In reply to anlauf from comment #3)

Even simpler fix, as intrinsics do not accept alternate return specifiers:

diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c
index a7ecdb401ef..4e5ec966d94 100644
--- a/gcc/fortran/intrinsic.c
+++ b/gcc/fortran/intrinsic.c
@@ -4420,7 +4420,7 @@ do_sort:
   FOR_EACH_VEC_ELT (dummy_args, idx, f)
     {
       a = ordered_actual_args[idx];
-      if (a && a->label != NULL && f->ts.type)
+      if (a && a->label != NULL)
        {
          gfc_error ("ALTERNATE RETURN not permitted at %L", where);
          return false;

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

* [Bug fortran/99256] ICE in variable_check, at fortran/check.c:1012
  2021-02-24 17:31 [Bug fortran/99256] New: ICE in variable_check, at fortran/check.c:1012 gscfq@t-online.de
                   ` (3 preceding siblings ...)
  2022-01-13 22:39 ` anlauf at gcc dot gnu.org
@ 2022-01-13 23:08 ` kargl at gcc dot gnu.org
  2022-01-14 20:48 ` cvs-commit at gcc dot gnu.org
  2022-01-14 20:57 ` anlauf at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: kargl at gcc dot gnu.org @ 2022-01-13 23:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99256

--- Comment #5 from kargl at gcc dot gnu.org ---
(In reply to anlauf from comment #4)
> (In reply to anlauf from comment #3)
> 
> Even simpler fix, as intrinsics do not accept alternate return specifiers:
> 
> diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c
> index a7ecdb401ef..4e5ec966d94 100644
> --- a/gcc/fortran/intrinsic.c
> +++ b/gcc/fortran/intrinsic.c
> @@ -4420,7 +4420,7 @@ do_sort:
>    FOR_EACH_VEC_ELT (dummy_args, idx, f)
>      {
>        a = ordered_actual_args[idx];
> -      if (a && a->label != NULL && f->ts.type)
> +      if (a && a->label != NULL)
>         {
>           gfc_error ("ALTERNATE RETURN not permitted at %L", where);
>           return false;

If this survives regression testing, it certainly seems to fall into the
obviously correct category.  I think you can commit the patch.

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

* [Bug fortran/99256] ICE in variable_check, at fortran/check.c:1012
  2021-02-24 17:31 [Bug fortran/99256] New: ICE in variable_check, at fortran/check.c:1012 gscfq@t-online.de
                   ` (4 preceding siblings ...)
  2022-01-13 23:08 ` kargl at gcc dot gnu.org
@ 2022-01-14 20:48 ` cvs-commit at gcc dot gnu.org
  2022-01-14 20:57 ` anlauf at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-14 20:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99256

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:70e24c9682ddbcade0301665bccd8e7f928d0082

commit r12-6596-g70e24c9682ddbcade0301665bccd8e7f928d0082
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Fri Jan 14 21:48:15 2022 +0100

    Fortran: always reject alternate return specifier as argument of intrinsics

    The intrinsics MOVE_ALLOC, C_F_POINTER, and C_F_PROCPOINTER require
    deferred checks of part of their actual argument types which may be of
    "any" type.  This however excludes alternate return specifiers which
    therefore must be unconditionally rejected for all standard intrinsics.

    gcc/fortran/ChangeLog:

            PR fortran/99256
            * intrinsic.c: Do not check formal argument type when checking
            arguments of intrinsics for alternate return specifiers.

    gcc/testsuite/ChangeLog:

            PR fortran/99256
            * gfortran.dg/altreturn_11.f90: New test.

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

* [Bug fortran/99256] ICE in variable_check, at fortran/check.c:1012
  2021-02-24 17:31 [Bug fortran/99256] New: ICE in variable_check, at fortran/check.c:1012 gscfq@t-online.de
                   ` (5 preceding siblings ...)
  2022-01-14 20:48 ` cvs-commit at gcc dot gnu.org
@ 2022-01-14 20:57 ` anlauf at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: anlauf at gcc dot gnu.org @ 2022-01-14 20:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99256

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |12.0

--- Comment #7 from anlauf at gcc dot gnu.org ---
Committed as obvious, see also

https://gcc.gnu.org/pipermail/fortran/2022-January/057398.html

Closing.  Thanks for the report!

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

end of thread, other threads:[~2022-01-14 20:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-24 17:31 [Bug fortran/99256] New: ICE in variable_check, at fortran/check.c:1012 gscfq@t-online.de
2021-02-25 18:40 ` [Bug fortran/99256] " kargl at gcc dot gnu.org
2021-02-25 18:49 ` sgk at troutmask dot apl.washington.edu
2021-12-12 21:47 ` anlauf at gcc dot gnu.org
2022-01-13 22:39 ` anlauf at gcc dot gnu.org
2022-01-13 23:08 ` kargl at gcc dot gnu.org
2022-01-14 20:48 ` cvs-commit at gcc dot gnu.org
2022-01-14 20:57 ` anlauf at gcc dot gnu.org

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