public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/101632] New: NON_RECURSIVE procedure prefix is unsupported.  F2018 defaults to recursive procedures.
@ 2021-07-26 19:11 kargl at gcc dot gnu.org
  2021-07-26 19:14 ` [Bug fortran/101632] " kargl at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: kargl at gcc dot gnu.org @ 2021-07-26 19:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101632
           Summary: NON_RECURSIVE procedure prefix is unsupported.  F2018
                    defaults to recursive procedures.
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kargl at gcc dot gnu.org
  Target Milestone: ---

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

* [Bug fortran/101632] NON_RECURSIVE procedure prefix is unsupported.  F2018 defaults to recursive procedures.
  2021-07-26 19:11 [Bug fortran/101632] New: NON_RECURSIVE procedure prefix is unsupported. F2018 defaults to recursive procedures kargl at gcc dot gnu.org
@ 2021-07-26 19:14 ` kargl at gcc dot gnu.org
  2021-07-26 19:15 ` kargl at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: kargl at gcc dot gnu.org @ 2021-07-26 19:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from kargl at gcc dot gnu.org ---
F2018 introduced the NON_RECURSIVE prefix for procedures and also made
procedures recursive by default.  This code is conforming to F2018.

module bah

   contains
      !
      ! non_recursive is F2018.
      !
      non_recursive function foo(i) result(k)
         integer k
         integer, intent(in) :: i
         k = i
      end function foo
      !
      ! Recursive has been around for awhile, and still in F2018
      !
      recursive function fib1(i) result(k)
         integer k
         integer, intent(in) :: i
         if (i <= 1) then
            k = i
         else
            k = fib1(i-1) + fib1(i - 2)
         end if
      end function fib1
      !
      ! This is recursive by default.
      !
      function fib2(i) result(k)
         integer k
         integer, intent(in) :: i
         if (i <= 1) then
            k = i
         else
            k = fib2(i-1) + fib2(i - 2)
         end if
      end function fib2

end module bah

program bar
   use bah
   integer i
   i = 9
   print *, fib1(i), fib2(i)
end program bar

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

* [Bug fortran/101632] NON_RECURSIVE procedure prefix is unsupported.  F2018 defaults to recursive procedures.
  2021-07-26 19:11 [Bug fortran/101632] New: NON_RECURSIVE procedure prefix is unsupported. F2018 defaults to recursive procedures kargl at gcc dot gnu.org
  2021-07-26 19:14 ` [Bug fortran/101632] " kargl at gcc dot gnu.org
@ 2021-07-26 19:15 ` kargl at gcc dot gnu.org
  2021-07-28  5:08 ` sgk at troutmask dot apl.washington.edu
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: kargl at gcc dot gnu.org @ 2021-07-26 19:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from kargl at gcc dot gnu.org ---
Created attachment 51207
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51207&action=edit
Diff that implements F2018 NON_RECURSIVE and makes things recursive by default.

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

* [Bug fortran/101632] NON_RECURSIVE procedure prefix is unsupported.  F2018 defaults to recursive procedures.
  2021-07-26 19:11 [Bug fortran/101632] New: NON_RECURSIVE procedure prefix is unsupported. F2018 defaults to recursive procedures kargl at gcc dot gnu.org
  2021-07-26 19:14 ` [Bug fortran/101632] " kargl at gcc dot gnu.org
  2021-07-26 19:15 ` kargl at gcc dot gnu.org
@ 2021-07-28  5:08 ` sgk at troutmask dot apl.washington.edu
  2021-08-03 14:37 ` jb at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: sgk at troutmask dot apl.washington.edu @ 2021-07-28  5:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Mon, Jul 26, 2021 at 07:15:53PM +0000, kargl at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101632
> 
> --- Comment #2 from kargl at gcc dot gnu.org ---
> Created attachment 51207
>   --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51207&action=edit
> Diff that implements F2018 NON_RECURSIVE and makes things recursive by default.
> 

Better patch.

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 413c7a75e0c..35ab2655a3b 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -6353,6 +6353,17 @@ gfc_match_prefix (gfc_typespec *ts)
          found_prefix = true;
        }

+      if (gfc_match ("non_recursive% ") == MATCH_YES)
+       {
+         if (!gfc_notify_std (GFC_STD_F2018, "NON_RECURSIVE procedure at %C"))
+           goto error;
+
+         if (!gfc_add_non_recursive (&current_attr, NULL))
+           goto error;
+
+         found_prefix = true;
+       }
+
       /* IMPURE is a somewhat special case, as it needs not set an actual
         attribute but rather only prevents ELEMENTAL routines from being
         automatically PURE.  */
@@ -6381,6 +6392,15 @@ gfc_match_prefix (gfc_typespec *ts)
        goto error;
     }

+  /* If neither NON_RECURSIVE nor RECURSIVE has been seen and the F2018
+     standard is in play, then mark the  the procedure as recursive.  */
+  if ((gfc_option.allow_std & GFC_STD_F2018)
+      && !current_attr.non_recursive && !current_attr.recursive)
+    {
+      if (!gfc_add_recursive (&current_attr, NULL))
+       goto error;
+    }
+
   /* At this point, the next item is not a prefix.  */
   gcc_assert (gfc_matching_prefix);

@@ -6447,6 +6467,9 @@ copy_prefix (symbol_attribute *dest, locus *where)
   if (current_attr.recursive && !gfc_add_recursive (dest, where))
     return false;

+  if (current_attr.non_recursive && !gfc_add_non_recursive (dest, where))
+    return false;
+
   return true;
 }

diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h
index f4a50d74f14..72ed9c6ee3d 100644
--- a/gcc/fortran/gfortran.h
+++ b/gcc/fortran/gfortran.h
@@ -842,7 +842,7 @@ typedef struct
   unsigned is_iso_c:1;         /* Symbol is from iso_c_binding.  */

   /* Function/subroutine attributes */
-  unsigned sequence:1, elemental:1, pure:1, recursive:1;
+  unsigned sequence:1, elemental:1, pure:1, recursive:1, non_recursive:1;
   unsigned unmaskable:1, masked:1, contained:1, mod_proc:1, abstract:1;

   /* Set if this is a module function or subroutine. Note that it is an
@@ -3223,6 +3223,7 @@ bool gfc_add_sequence (symbol_attribute *, const char *,
locus *);
 bool gfc_add_elemental (symbol_attribute *, locus *);
 bool gfc_add_pure (symbol_attribute *, locus *);
 bool gfc_add_recursive (symbol_attribute *, locus *);
+bool gfc_add_non_recursive (symbol_attribute *, locus *);
 bool gfc_add_function (symbol_attribute *, const char *, locus *);
 bool gfc_add_subroutine (symbol_attribute *, const char *, locus *);
 bool gfc_add_volatile (symbol_attribute *, const char *, locus *);
diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
index 6d61bf4982b..f456a02847c 100644
--- a/gcc/fortran/symbol.c
+++ b/gcc/fortran/symbol.c
@@ -410,24 +410,24 @@ gfc_check_function_type (gfc_namespace *ns)
 bool
 gfc_check_conflict (symbol_attribute *attr, const char *name, locus *where)
 {
-  static const char *dummy = "DUMMY", *save = "SAVE", *pointer = "POINTER",
-    *target = "TARGET", *external = "EXTERNAL", *intent = "INTENT",
-    *intent_in = "INTENT(IN)", *intrinsic = "INTRINSIC",
-    *intent_out = "INTENT(OUT)", *intent_inout = "INTENT(INOUT)",
-    *allocatable = "ALLOCATABLE", *elemental = "ELEMENTAL",
-    *privat = "PRIVATE", *recursive = "RECURSIVE",
-    *in_common = "COMMON", *result = "RESULT", *in_namelist = "NAMELIST",
-    *publik = "PUBLIC", *optional = "OPTIONAL", *entry = "ENTRY",
-    *function = "FUNCTION", *subroutine = "SUBROUTINE",
-    *dimension = "DIMENSION", *in_equivalence = "EQUIVALENCE",
-    *use_assoc = "USE ASSOCIATED", *cray_pointer = "CRAY POINTER",
-    *cray_pointee = "CRAY POINTEE", *data = "DATA", *value = "VALUE",
-    *volatile_ = "VOLATILE", *is_protected = "PROTECTED",
-    *is_bind_c = "BIND(C)", *procedure = "PROCEDURE",
-    *proc_pointer = "PROCEDURE POINTER", *abstract = "ABSTRACT",
-    *asynchronous = "ASYNCHRONOUS", *codimension = "CODIMENSION",
-    *contiguous = "CONTIGUOUS", *generic = "GENERIC", *automatic =
"AUTOMATIC",
-    *pdt_len = "LEN", *pdt_kind = "KIND";
+  static const char *abstract = "ABSTRACT", *allocatable = "ALLOCATABLE",
+    *asynchronous = "ASYNCHRONOUS", *automatic = "AUTOMATIC",
+    *codimension = "CODIMENSION", *contiguous = "CONTIGUOUS",
+    *cray_pointee = "CRAYPOINTEE", *cray_pointer = "CRAYPOINTER",
+    *data = "DATA", *dimension = "DIMENSION", *dummy = "DUMMY",
+    *elemental = "ELEMENTAL", *entry = "ENTRY", *external = "EXTERNAL",
+    *function = "FUNCTION", *generic = "GENERIC", *in_common = "COMMON",
+    *in_equivalence = "EQUIVALENCE", *in_namelist = "NAMELIST",
+    *intent = "INTENT", *intent_in = "INTENT(IN)",
+    *intent_inout = "INTENT(INOUT)", *intent_out = "INTENT(OUT)",
+    *intrinsic = "INTRINSIC", *is_bind_c = "BIND(C)",
+    *is_protected = "PROTECTED", *non_recursive = "NON_RECURSIVE",
+    *optional = "OPTIONAL", *pdt_kind = "KIND", *pdt_len="LEN",
+    *pointer="POINTER", *privat="PRIVATE", *proc_pointer="PROCEDUREPOINTER",
+    *procedure="PROCEDURE", *publik="PUBLIC", *recursive="RECURSIVE",
+    *result="RESULT", *save="SAVE", *subroutine="SUBROUTINE",
+    *target="TARGET", *use_assoc="USEASSOCIATED", *value="VALUE",
+    *volatile_="VOLATILE";
   static const char *threadprivate = "THREADPRIVATE";
   static const char *omp_declare_target = "OMP DECLARE TARGET";
   static const char *omp_declare_target_link = "OMP DECLARE TARGET LINK";
@@ -570,6 +570,7 @@ gfc_check_conflict (symbol_attribute *attr, const char
*name, locus *where)
   conf_std (allocatable, function, GFC_STD_F2003);
   conf_std (allocatable, result, GFC_STD_F2003);
   conf_std (elemental, recursive, GFC_STD_F2018);
+  conf (non_recursive, recursive);

   conf (in_common, dummy);
   conf (in_common, allocatable);
@@ -1650,6 +1651,24 @@ gfc_add_recursive (symbol_attribute *attr, locus *where)
 }


+bool
+gfc_add_non_recursive (symbol_attribute *attr, locus *where)
+{
+
+  if (check_used (attr, NULL, where))
+    return false;
+
+  if (attr->non_recursive)
+    {
+      duplicate_attr ("NON_RECURSIVE", where);
+      return false;
+    }
+
+  attr->non_recursive = 1;
+  return gfc_check_conflict (attr, NULL, where);
+}
+
+
 bool
 gfc_add_entry (symbol_attribute *attr, const char *name, locus *where)
 {
@@ -2148,6 +2167,8 @@ gfc_copy_attr (symbol_attribute *dest, symbol_attribute
*src, locus *where)
     goto fail;
   if (src->recursive && !gfc_add_recursive (dest, where))
     goto fail;
+  if (src->non_recursive && !gfc_add_non_recursive (dest, where))
+    goto fail;

   if (src->flavor != FL_UNKNOWN
       && !gfc_add_flavor (dest, src->flavor, NULL, where))

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

* [Bug fortran/101632] NON_RECURSIVE procedure prefix is unsupported.  F2018 defaults to recursive procedures.
  2021-07-26 19:11 [Bug fortran/101632] New: NON_RECURSIVE procedure prefix is unsupported. F2018 defaults to recursive procedures kargl at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-07-28  5:08 ` sgk at troutmask dot apl.washington.edu
@ 2021-08-03 14:37 ` jb at gcc dot gnu.org
  2021-08-03 15:14 ` sgk at troutmask dot apl.washington.edu
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jb at gcc dot gnu.org @ 2021-08-03 14:37 UTC (permalink / raw)
  To: gcc-bugs

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

Janne Blomqvist <jb at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jb at gcc dot gnu.org
         Depends on|                            |91413

--- Comment #4 from Janne Blomqvist <jb at gcc dot gnu.org> ---
In PR91413 we discussed the issue of stack overflows if recursive is made the
default. Some decision and solution on that issue is needed.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91413
[Bug 91413] [F2018]: Procedures are recursive by default; switching from stack
to static allocation is not safe

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

* [Bug fortran/101632] NON_RECURSIVE procedure prefix is unsupported.  F2018 defaults to recursive procedures.
  2021-07-26 19:11 [Bug fortran/101632] New: NON_RECURSIVE procedure prefix is unsupported. F2018 defaults to recursive procedures kargl at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-08-03 14:37 ` jb at gcc dot gnu.org
@ 2021-08-03 15:14 ` sgk at troutmask dot apl.washington.edu
  2021-11-06 21:09 ` anlauf at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: sgk at troutmask dot apl.washington.edu @ 2021-08-03 15:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Tue, Aug 03, 2021 at 02:37:40PM +0000, jb at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101632
> 
> Janne Blomqvist <jb at gcc dot gnu.org> changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |jb at gcc dot gnu.org
>          Depends on|                            |91413
> 
> --- Comment #4 from Janne Blomqvist <jb at gcc dot gnu.org> ---
> In PR91413 we discussed the issue of stack overflows if recursive is made the
> default. Some decision and solution on that issue is needed.
> 
> Referenced Bugs:
> 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91413
> [Bug 91413] [F2018]: Procedures are recursive by default; switching from stack
> to static allocation is not safe

Hi Janne, It's been awhile!

I compiled an older version of the polyhedron testsuite.
I did not see any impact while running the tests.
Perhaps, Polyhedron does not contain a usage pattern
that would cause a stack issue.  I did run the test
with my normal user privilege

% limits | grep stack
  stacksize              524288 kB

Perhaps, I should have limited the stack.

Note, the patch does allow gfortran to compile 
standard conforming Fortran in that it will
now allow a NON_RECURSIVE prefix.  We could disable
the actual setting of the recursive attribute
until someone comes up with a deeper analysis of
the handling of the stack.  I suspect most current
code does not use recursion unless RECURSIVE is 
explicitly used

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

* [Bug fortran/101632] NON_RECURSIVE procedure prefix is unsupported.  F2018 defaults to recursive procedures.
  2021-07-26 19:11 [Bug fortran/101632] New: NON_RECURSIVE procedure prefix is unsupported. F2018 defaults to recursive procedures kargl at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2021-08-03 15:14 ` sgk at troutmask dot apl.washington.edu
@ 2021-11-06 21:09 ` anlauf at gcc dot gnu.org
  2021-12-06 20:47 ` anlauf at gcc dot gnu.org
  2022-04-19 15:53 ` everythingfunctional at protonmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-11-06 21:09 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

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

--- Comment #6 from anlauf at gcc dot gnu.org ---
As a first step we could just parse and accept the attribute.

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

* [Bug fortran/101632] NON_RECURSIVE procedure prefix is unsupported.  F2018 defaults to recursive procedures.
  2021-07-26 19:11 [Bug fortran/101632] New: NON_RECURSIVE procedure prefix is unsupported. F2018 defaults to recursive procedures kargl at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2021-11-06 21:09 ` anlauf at gcc dot gnu.org
@ 2021-12-06 20:47 ` anlauf at gcc dot gnu.org
  2022-04-19 15:53 ` everythingfunctional at protonmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-12-06 20:47 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-12-06
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #7 from anlauf at gcc dot gnu.org ---
(In reply to Steve Kargl from comment #3)
> Better patch.

That patch produces many regressions in the test suite.  Seems we're not ready
yet for RECURSIVE as the default.

Removing or commenting out the hunk

+  /* If neither NON_RECURSIVE nor RECURSIVE has been seen and the F2018
+     standard is in play, then mark the  the procedure as recursive.  */
+  if ((gfc_option.allow_std & GFC_STD_F2018)
+      && !current_attr.non_recursive && !current_attr.recursive)
+    {
+      if (!gfc_add_recursive (&current_attr, NULL))
+       goto error;
+    }
+

allows at least parsing of NON_RECURSIVE, while having no effect otherwise.

Still lacking: handling of NON_RECURSIVE in module.c .

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

* [Bug fortran/101632] NON_RECURSIVE procedure prefix is unsupported.  F2018 defaults to recursive procedures.
  2021-07-26 19:11 [Bug fortran/101632] New: NON_RECURSIVE procedure prefix is unsupported. F2018 defaults to recursive procedures kargl at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2021-12-06 20:47 ` anlauf at gcc dot gnu.org
@ 2022-04-19 15:53 ` everythingfunctional at protonmail dot com
  7 siblings, 0 replies; 9+ messages in thread
From: everythingfunctional at protonmail dot com @ 2022-04-19 15:53 UTC (permalink / raw)
  To: gcc-bugs

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

Brad Richardson <everythingfunctional at protonmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |everythingfunctional@proton
                   |                            |mail.com

--- Comment #8 from Brad Richardson <everythingfunctional at protonmail dot com> ---
*** Bug 105309 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2022-04-19 15:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-26 19:11 [Bug fortran/101632] New: NON_RECURSIVE procedure prefix is unsupported. F2018 defaults to recursive procedures kargl at gcc dot gnu.org
2021-07-26 19:14 ` [Bug fortran/101632] " kargl at gcc dot gnu.org
2021-07-26 19:15 ` kargl at gcc dot gnu.org
2021-07-28  5:08 ` sgk at troutmask dot apl.washington.edu
2021-08-03 14:37 ` jb at gcc dot gnu.org
2021-08-03 15:14 ` sgk at troutmask dot apl.washington.edu
2021-11-06 21:09 ` anlauf at gcc dot gnu.org
2021-12-06 20:47 ` anlauf at gcc dot gnu.org
2022-04-19 15:53 ` everythingfunctional at protonmail dot com

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