public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/98016] New: Host association problem
@ 2020-11-26 12:23 juergen.reuter at desy dot de
  2020-11-26 13:02 ` [Bug fortran/98016] " tkoenig at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: juergen.reuter at desy dot de @ 2020-11-26 12:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98016
           Summary: Host association problem
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: juergen.reuter at desy dot de
  Target Milestone: ---

Discussed on c.l.f. today, the following value from host association is falsely
rejected by gfortran, persistent since at least v4.8.5:
program p
  real :: y(3)
  n=3
  y = func(0.)
  stop
contains
  function func(x) result (y)
    real y(n)
    y=x
  end function func
end program p

Rejected with message:
8.11:

    real y(n)
           1
Error: Variable 'n' cannot appear in the expression at (1)

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

* [Bug fortran/98016] Host association problem
  2020-11-26 12:23 [Bug fortran/98016] New: Host association problem juergen.reuter at desy dot de
@ 2020-11-26 13:02 ` tkoenig at gcc dot gnu.org
  2020-11-26 14:43 ` juergen.reuter at desy dot de
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2020-11-26 13:02 UTC (permalink / raw)
  To: gcc-bugs

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

Thomas Koenig <tkoenig at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-11-26
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |WAITING
                 CC|                            |tkoenig at gcc dot gnu.org

--- Comment #1 from Thomas Koenig <tkoenig at gcc dot gnu.org> ---
Seems to be fixed on current trunk:

$ cat bug.f90 
program p
  real :: y(3)
  n=3
  y = func(0.)
  stop
contains
  function func(x) result (y)
    real y(n)
    y=x
  end function func
end program p
$ gfortran bug.f90 
$ gfortran -v
Es werden eingebaute Spezifikationen verwendet.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/home/ig25/lib/gcc/x86_64-pc-linux-gnu/11.0.0/lto-wrapper
Ziel: x86_64-pc-linux-gnu
Konfiguriert mit: ../trunk/configure --prefix=/home/ig25
--enable-languages=c,c++,fortran
Thread-Modell: posix
Unterstützte LTO-Kompressionsalgorithmen: zlib
gcc-Version 11.0.0 20201112 (experimental) [master revision
d33bc98f5bc:79fa060941e:87b7d45e358e4df93b6a93b2e7a55b123ea76f5d] (GCC) 

Can you confirm that?  If so, we can commit a test case and close.

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

* [Bug fortran/98016] Host association problem
  2020-11-26 12:23 [Bug fortran/98016] New: Host association problem juergen.reuter at desy dot de
  2020-11-26 13:02 ` [Bug fortran/98016] " tkoenig at gcc dot gnu.org
@ 2020-11-26 14:43 ` juergen.reuter at desy dot de
  2020-11-26 14:48 ` juergen.reuter at desy dot de
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: juergen.reuter at desy dot de @ 2020-11-26 14:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jürgen Reuter <juergen.reuter at desy dot de> ---
(In reply to Thomas Koenig from comment #1)

> gcc-Version 11.0.0 20201112 (experimental) [master revision
> d33bc98f5bc:79fa060941e:87b7d45e358e4df93b6a93b2e7a55b123ea76f5d] (GCC) 
> 
> Can you confirm that?  If so, we can commit a test case and close.

Hm, no, just made git pull, and recompiled:
$ gfortran clf_20201126.f90 
clf_20201126.f90:8:16:

    8 |     dimension y(n)
      |                1
Error: Variable ‘n’ cannot appear in the expression at (1)
$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/scratch/reuter/local/libexec/gcc/x86_64-pc-linux-gnu/11.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=/scratch/reuter/local/
--with-gmp=/scratch/reuter/local --with-mpfr=/scratch/reuter/local
--with-mpc=/scratch/reuter/local --disable-multilib
--enable-languages=c,c++,fortran,lto
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.0.0 20201126 (experimental) (GCC) 

Still present.

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

* [Bug fortran/98016] Host association problem
  2020-11-26 12:23 [Bug fortran/98016] New: Host association problem juergen.reuter at desy dot de
  2020-11-26 13:02 ` [Bug fortran/98016] " tkoenig at gcc dot gnu.org
  2020-11-26 14:43 ` juergen.reuter at desy dot de
@ 2020-11-26 14:48 ` juergen.reuter at desy dot de
  2020-11-26 15:13 ` dominiq at lps dot ens.fr
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: juergen.reuter at desy dot de @ 2020-11-26 14:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jürgen Reuter <juergen.reuter at desy dot de> ---
Ah wait, the version I committed works, the original version from c.l.f. still
fails, because it uses implicit typing, so not real :: y(3)
and real :: y(n), but 
dimension y(3)

$ cat clf_20201126.f90
program is_it_valid
  dimension y(3)
  n=3
  y=func(0.)
  stop
contains
  function func(x) result (y)
    dimension y(n)
    y=x
  end function func
end program is_it_valid

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

* [Bug fortran/98016] Host association problem
  2020-11-26 12:23 [Bug fortran/98016] New: Host association problem juergen.reuter at desy dot de
                   ` (2 preceding siblings ...)
  2020-11-26 14:48 ` juergen.reuter at desy dot de
@ 2020-11-26 15:13 ` dominiq at lps dot ens.fr
  2020-11-26 17:33 ` kargl at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: dominiq at lps dot ens.fr @ 2020-11-26 15:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
I confirm that the test in comment O compiles without any error.
However if I replace

    real y(n)

with

    dimension y(n)

I get the error

Error: Variable 'n' cannot appear in the expression at (1)

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

* [Bug fortran/98016] Host association problem
  2020-11-26 12:23 [Bug fortran/98016] New: Host association problem juergen.reuter at desy dot de
                   ` (3 preceding siblings ...)
  2020-11-26 15:13 ` dominiq at lps dot ens.fr
@ 2020-11-26 17:33 ` kargl at gcc dot gnu.org
  2020-11-29 16:08 ` pault at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: kargl at gcc dot gnu.org @ 2020-11-26 17:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from kargl at gcc dot gnu.org ---
Index: gcc/gcc/fortran/expr.c
===================================================================
--- gcc/gcc/fortran/expr.c      (revision 280157)
+++ gcc/gcc/fortran/expr.c      (working copy)
@@ -3380,24 +3382,41 @@ check_restricted (gfc_expr *e)
         This mechanism also does the same for the specification expressions
         of array-valued functions.  */
       if (e->error
-           || sym->attr.in_common
-           || sym->attr.use_assoc
-           || sym->attr.dummy
-           || sym->attr.implied_index
-           || sym->attr.flavor == FL_PARAMETER
-           || is_parent_of_current_ns (sym->ns)
-           || (sym->ns->proc_name != NULL
-                 && sym->ns->proc_name->attr.flavor == FL_MODULE)
-           || (gfc_is_formal_arg () && (sym->ns == gfc_current_ns)))
+         || sym->attr.in_common
+         || sym->attr.use_assoc
+         || sym->attr.dummy
+         || sym->attr.implied_index
+         || sym->attr.flavor == FL_PARAMETER
+         || is_parent_of_current_ns (sym->ns)
+         || (sym->ns->proc_name != NULL
+             && sym->ns->proc_name->attr.flavor == FL_MODULE)
+         || (gfc_is_formal_arg () && (sym->ns == gfc_current_ns)))
        {
          t = true;
          break;
        }

-      gfc_error ("Variable %qs cannot appear in the expression at %L",
-                sym->name, &e->where);
-      /* Prevent a repetition of the error.  */
-      e->error = 1;
+      for (gfc_namespace *ns = sym->ns->parent; ns; ns = ns->parent)
+       if (sym->ns == ns)
+         {
+           t = true;
+           break;
+         }
+
+      for (gfc_namespace *ns = sym->ns->contained->parent; ns; ns =
ns->parent)
+       if (sym->ns == ns)
+         {
+           t = true;
+           break;
+         }
+
+      if (!t)
+       {
+         gfc_error ("Variable %qs cannot appear in the expression at %L",
+                    sym->name, &e->where);
+         /* Prevent a repetition of the error.  */
+         e->error = 1;
+       }
       break;

     case EXPR_NULL:

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

* [Bug fortran/98016] Host association problem
  2020-11-26 12:23 [Bug fortran/98016] New: Host association problem juergen.reuter at desy dot de
                   ` (4 preceding siblings ...)
  2020-11-26 17:33 ` kargl at gcc dot gnu.org
@ 2020-11-29 16:08 ` pault at gcc dot gnu.org
  2020-12-01 10:58 ` drikosev at gmail dot com
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2020-11-29 16:08 UTC (permalink / raw)
  To: gcc-bugs

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

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pault at gcc dot gnu.org
           Assignee|unassigned at gcc dot gnu.org      |pault at gcc dot gnu.org
             Status|WAITING                     |NEW

--- Comment #6 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 49645
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49645&action=edit
Fix for the PR

This fix is rather different to Steve's. It exploits the existing mechanism for
formal arguments. In this context, the function result is equivalent to formal
arguments.

It even regtests OK :-)

Unless there are objections, I will commit as 'obvious' after I fix the last of
the nits with PR83118 or, at least, towards the end of the week.

Cheers

Paul

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

* [Bug fortran/98016] Host association problem
  2020-11-26 12:23 [Bug fortran/98016] New: Host association problem juergen.reuter at desy dot de
                   ` (5 preceding siblings ...)
  2020-11-29 16:08 ` pault at gcc dot gnu.org
@ 2020-12-01 10:58 ` drikosev at gmail dot com
  2020-12-03 13:34 ` pault at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: drikosev at gmail dot com @ 2020-12-01 10:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Ev Drikos <drikosev at gmail dot com> ---
Created attachment 49659
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49659&action=edit
attachment for pr98016-07

(In reply to Paul Thomas from comment #6)
> Created attachment 49645 [details]
> Fix for the PR
> 
> Unless there are objections, ...

Not an objection, rather just an observation:

1. This code is inside "resolve_symbol" and the
   following double declaration seems redundant:

   bool saved_specification_expr

   The reason I'm mentioning it is that I debugged
   the example with gcc-4.8 and the debugger makes
   this call:

   gfc_resolve_array_spec (sym->as, check_constant)

   So, the declaration below could be at the top of
   the function declarations like the code below

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

* [Bug fortran/98016] Host association problem
  2020-11-26 12:23 [Bug fortran/98016] New: Host association problem juergen.reuter at desy dot de
                   ` (6 preceding siblings ...)
  2020-12-01 10:58 ` drikosev at gmail dot com
@ 2020-12-03 13:34 ` pault at gcc dot gnu.org
  2020-12-05 14:14 ` cvs-commit at gcc dot gnu.org
  2020-12-05 14:16 ` pault at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2020-12-03 13:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Paul Thomas <pault at gcc dot gnu.org> ---
(In reply to Ev Drikos from comment #7)
> Created attachment 49659 [details]
> attachment for pr98016-07
> 
> (In reply to Paul Thomas from comment #6)
> > Created attachment 49645 [details]
> > Fix for the PR
> > 
> > Unless there are objections, ...
> 
> Not an objection, rather just an observation:
> 
> 1. This code is inside "resolve_symbol" and the
>    following double declaration seems redundant:
> 
>    bool saved_specification_expr
> 
>    The reason I'm mentioning it is that I debugged
>    the example with gcc-4.8 and the debugger makes
>    this call:
> 
>    gfc_resolve_array_spec (sym->as, check_constant)
> 
>    So, the declaration below could be at the top of
>    the function declarations like the code below
Hi There,

The multiple declarations (5 in resolve.c) come about because of the
possibility of rather torturous recursion paths. I guess that we could replace
the boolean with a counter but this doesn't seem to be much of an improvement.

I am just now preparing for a commit this evening.

Thanks for the comment.

Paul

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

* [Bug fortran/98016] Host association problem
  2020-11-26 12:23 [Bug fortran/98016] New: Host association problem juergen.reuter at desy dot de
                   ` (7 preceding siblings ...)
  2020-12-03 13:34 ` pault at gcc dot gnu.org
@ 2020-12-05 14:14 ` cvs-commit at gcc dot gnu.org
  2020-12-05 14:16 ` pault at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-05 14:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Paul Thomas <pault@gcc.gnu.org>:

https://gcc.gnu.org/g:7ae210d5db5eb96989b2f639e65678b5597e61f0

commit r11-5759-g7ae210d5db5eb96989b2f639e65678b5597e61f0
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Sat Dec 5 14:14:19 2020 +0000

    Fortran: flag formal argument before resolving an array spec [PR98016].

    2020-12-05  Paul Thomas  <pault@gcc.gnu.org>

    gcc/fortran
            PR fortran/98016
            * resolve.c (resolve_symbol): Set formal_arg_flag before
            resolving an array spec and restore value afterwards.

    gcc/testsuite/
            PR fortran/98016
            * gfortran.dg/pr98016.f90: New test.

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

* [Bug fortran/98016] Host association problem
  2020-11-26 12:23 [Bug fortran/98016] New: Host association problem juergen.reuter at desy dot de
                   ` (8 preceding siblings ...)
  2020-12-05 14:14 ` cvs-commit at gcc dot gnu.org
@ 2020-12-05 14:16 ` pault at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: pault at gcc dot gnu.org @ 2020-12-05 14:16 UTC (permalink / raw)
  To: gcc-bugs

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

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #10 from Paul Thomas <pault at gcc dot gnu.org> ---
Fixed on master. Closing.

Thanks for posting it Juergen.

Paul

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

end of thread, other threads:[~2020-12-05 14:16 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-26 12:23 [Bug fortran/98016] New: Host association problem juergen.reuter at desy dot de
2020-11-26 13:02 ` [Bug fortran/98016] " tkoenig at gcc dot gnu.org
2020-11-26 14:43 ` juergen.reuter at desy dot de
2020-11-26 14:48 ` juergen.reuter at desy dot de
2020-11-26 15:13 ` dominiq at lps dot ens.fr
2020-11-26 17:33 ` kargl at gcc dot gnu.org
2020-11-29 16:08 ` pault at gcc dot gnu.org
2020-12-01 10:58 ` drikosev at gmail dot com
2020-12-03 13:34 ` pault at gcc dot gnu.org
2020-12-05 14:14 ` cvs-commit at gcc dot gnu.org
2020-12-05 14:16 ` pault 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).