fortran: Fix up TYPE_ARG_TYPES of procs with scalar VALUE optional args [PR92305]
authorJakub Jelinek <jakub@redhat.com>
Sat, 1 Feb 2020 09:02:20 +0000 (10:02 +0100)
committerJakub Jelinek <jakub@redhat.com>
Sat, 1 Feb 2020 09:02:20 +0000 (10:02 +0100)
The following patch fixes
-FAIL: libgomp.fortran/use_device_addr-1.f90   -O0  execution test
-FAIL: libgomp.fortran/use_device_addr-2.f90   -O0  execution test
that has been FAILing for several months on powerpc64le-linux.
The problem is in the Fortran FE, which adds the artificial arguments
for scalar VALUE OPTIONAL dummy args only to DECL_ARGUMENTS where the
current function can see them, but not to TYPE_ARG_TYPES; if those functions
aren't varargs, this confuses calls.c to pass the remaining arguments
(which aren't named (== not covered by TYPE_ARG_TYPES) and aren't varargs
either) in a different spot from what the callee (which has proper
DECL_ARGUMENTS for all args) expects.  For the artificial length arguments
for character dummy args we already put them in both DECL_ARGUMENTS and
TYPE_ARG_TYPES.

2020-02-01  Jakub Jelinek  <jakub@redhat.com>

PR fortran/92305
* trans-types.c (gfc_get_function_type): Also push boolean_type_node
types for non-character scalar VALUE optional dummy arguments.
* trans-decl.c (create_function_arglist): Skip those in
hidden_typelist.  Formatting fix.

gcc/fortran/ChangeLog
gcc/fortran/trans-decl.c
gcc/fortran/trans-types.c

index 9b17daf15f9ab409f68ad019340a46bd7c7229b1..2b188e513b77c9f990ff5f77c96a715c214d7952 100644 (file)
@@ -1,3 +1,11 @@
+2020-02-01  Jakub Jelinek  <jakub@redhat.com>
+
+       PR fortran/92305
+       * trans-types.c (gfc_get_function_type): Also push boolean_type_node
+       types for non-character scalar VALUE optional dummy arguments.
+       * trans-decl.c (create_function_arglist): Skip those in
+       hidden_typelist.  Formatting fix.
+
 2020-01-31  Tobias Burnus  <tobias@codesourcery.com>
 
        PR fortran/93462
index 1147c246281b1d1ec5d25c040cba8a83d8236add..e91a2795762e324d509ccc9b0050f84247276d3e 100644 (file)
@@ -2645,8 +2645,8 @@ create_function_arglist (gfc_symbol * sym)
              || f->sym->ts.u.cl->backend_decl == length)
            {
              if (POINTER_TYPE_P (len_type))
-               f->sym->ts.u.cl->backend_decl =
-                       build_fold_indirect_ref_loc (input_location, length);
+               f->sym->ts.u.cl->backend_decl
+                 = build_fold_indirect_ref_loc (input_location, length);
              else if (f->sym->ts.u.cl->backend_decl == NULL)
                gfc_create_string_length (f->sym);
 
@@ -2677,6 +2677,8 @@ create_function_arglist (gfc_symbol * sym)
           DECL_ARG_TYPE (tmp) = boolean_type_node;
           TREE_READONLY (tmp) = 1;
           gfc_finish_decl (tmp);
+
+         hidden_typelist = TREE_CHAIN (hidden_typelist);
        }
 
       /* For non-constant length array arguments, make sure they use
index 0a749d6e0a07cda1d42b22e1173e0f46492a80fe..8a4c8eef4a11f5f4d0b4a136963d069eb8e56505 100644 (file)
@@ -3098,6 +3098,16 @@ gfc_get_function_type (gfc_symbol * sym, gfc_actual_arglist *actual_args)
 
          vec_safe_push (typelist, type);
        }
+      /* For noncharacter scalar intrinsic types, VALUE passes the value,
+        hence, the optional status cannot be transferred via a NULL pointer.
+        Thus, we will use a hidden argument in that case.  */
+      else if (arg
+              && arg->attr.optional
+              && arg->attr.value
+              && !arg->attr.dimension
+              && arg->ts.type != BT_CLASS
+              && !gfc_bt_struct (arg->ts.type))
+       vec_safe_push (typelist, boolean_type_node);
     }
 
   if (!vec_safe_is_empty (typelist)