diff options
author | Thomas Koenig <tkoenig@gcc.gnu.org> | 2020-10-25 13:16:16 +0100 |
---|---|---|
committer | Thomas Koenig <tkoenig@gcc.gnu.org> | 2020-10-25 13:17:06 +0100 |
commit | 47d13acbda9a5d8eb57ff169ba74857cd54108e4 (patch) | |
tree | 9f8172cd70724fd0abd232cfc3679e8448a8db7b /gcc/fortran/intrinsic.c | |
parent | d7ddd287ca76e87f431f43687de6d8cc48e52543 (diff) | |
download | gcc-47d13acbda9a5d8eb57ff169ba74857cd54108e4.zip gcc-47d13acbda9a5d8eb57ff169ba74857cd54108e4.tar.gz gcc-47d13acbda9a5d8eb57ff169ba74857cd54108e4.tar.bz2 |
Correct decls for functions which do not pass actual arguments.
A wrong decl for findloc caused segfaults at runtime on
Darwin for ARM; however, this is only a symptom of a larger
disease: The declarations for our library functions are often
inconsistent. This patch solves that problem for the functions
specifically for the functions for which we do not pass optional
arguments, i.e. findloc and (min|max)loc.
It works by saving the symbols of the specific functions in
gfc_intrinsic_namespace and by generating the formal argument
lists from the actual argument lists. Because symbols are
re-used, so are the backend decls.
gcc/fortran/ChangeLog:
PR fortran/97454
* gfortran.h (gfc_symbol): Add pass_as_value flag.
(gfc_copy_formal_args_intr): Add optional argument
copy_type.
(gfc_get_intrinsic_function_symbol): Add prototype.
(gfc_find_intrinsic_symbol): Add prototype.
* intrinsic.c (gfc_get_intrinsic_function_symbol): New function.
(gfc_find_intrinsic_symbol): New function.
* symbol.c (gfc_copy_formal_args_intr): Add argument. Handle case
where the type needs to be copied from the actual argument.
* trans-intrinsic.c (remove_empty_actual_arguments): New function.
(specific_intrinsic_symbol): New function.
(gfc_conv_intrinsic_funcall): Use it.
(strip_kind_from_actual): Adjust so that the expression pointer
is set to NULL.
(gfc_conv_intrinsic_minmaxloc): Likewise.
(gfc_conv_intrinsic_minmaxval): Adjust removal of dim.
* trans-types.c (gfc_sym_type): If sym->pass_as_value is set, do
not pass by reference.
Diffstat (limited to 'gcc/fortran/intrinsic.c')
-rw-r--r-- | gcc/fortran/intrinsic.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c index f4dfcf7..07b953a 100644 --- a/gcc/fortran/intrinsic.c +++ b/gcc/fortran/intrinsic.c @@ -122,6 +122,43 @@ gfc_get_intrinsic_sub_symbol (const char *name) return sym; } +/* Get a symbol for a resolved function, with its special name. The + actual argument list needs to be set by the caller. */ + +gfc_symbol * +gfc_get_intrinsic_function_symbol (gfc_expr *expr) +{ + gfc_symbol *sym; + + gfc_get_symbol (expr->value.function.name, gfc_intrinsic_namespace, &sym); + sym->attr.external = 1; + sym->attr.function = 1; + sym->attr.always_explicit = 1; + sym->attr.proc = PROC_INTRINSIC; + sym->attr.flavor = FL_PROCEDURE; + sym->result = sym; + if (expr->rank > 0) + { + sym->attr.dimension = 1; + sym->as = gfc_get_array_spec (); + sym->as->type = AS_ASSUMED_SHAPE; + sym->as->rank = expr->rank; + } + return sym; +} + +/* Find a symbol for a resolved intrinsic procedure, return NULL if + not found. */ + +gfc_symbol * +gfc_find_intrinsic_symbol (gfc_expr *expr) +{ + gfc_symbol *sym; + gfc_find_symbol (expr->value.function.name, gfc_intrinsic_namespace, + 0, &sym); + return sym; +} + /* Return a pointer to the name of a conversion function given two typespecs. */ |