From 8b40ca6a38070686f7aea3cd661197ca879eab50 Mon Sep 17 00:00:00 2001 From: Francois-Xavier Coudert Date: Fri, 28 Aug 2015 20:46:43 +0000 Subject: re PR fortran/53668 (Cray-pointer diagnostic enhancement) PR fortran/53668 * intrinsic.c (add_functions, add_subroutines): Remove resolution functions for FREE and MALLOC. * intrinsic.h (gfc_resolve_malloc, gfc_resolve_free): Remove. * iresolve.c (gfc_resolve_malloc, gfc_resolve_free): Remove. * trans-intrinsic.c (conv_intrinsic_free, gfc_conv_intrinsic_malloc): New functions. * intrinsics/malloc.c: Adapt comments. From-SVN: r227311 --- gcc/fortran/trans-intrinsic.c | 46 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'gcc/fortran/trans-intrinsic.c') diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c index f5b270f..554469e 100644 --- a/gcc/fortran/trans-intrinsic.c +++ b/gcc/fortran/trans-intrinsic.c @@ -2657,6 +2657,27 @@ gfc_conv_intrinsic_fdate (gfc_se * se, gfc_expr * expr) } +/* Generate a direct call to free() for the FREE subroutine. */ + +static tree +conv_intrinsic_free (gfc_code *code) +{ + stmtblock_t block; + gfc_se argse; + tree arg, call; + + gfc_init_se (&argse, NULL); + gfc_conv_expr (&argse, code->ext.actual->expr); + arg = fold_convert (ptr_type_node, argse.expr); + + gfc_init_block (&block); + call = build_call_expr_loc (input_location, + builtin_decl_explicit (BUILT_IN_FREE), 1, arg); + gfc_add_expr_to_block (&block, call); + return gfc_finish_block (&block); +} + + /* Call the SYSTEM_CLOCK library functions, handling the type and kind conversions. */ @@ -7648,6 +7669,22 @@ gfc_conv_ieee_arithmetic_function (gfc_se * se, gfc_expr * expr) } +/* Generate a direct call to malloc() for the MALLOC intrinsic. */ + +static void +gfc_conv_intrinsic_malloc (gfc_se * se, gfc_expr * expr) +{ + tree arg, res, restype; + + gfc_conv_intrinsic_function_args (se, expr, &arg, 1); + arg = fold_convert (size_type_node, arg); + res = build_call_expr_loc (input_location, + builtin_decl_explicit (BUILT_IN_MALLOC), 1, arg); + restype = gfc_typenode_for_spec (&expr->ts); + se->expr = fold_convert (restype, res); +} + + /* Generate code for an intrinsic function. Some map directly to library calls, others get special handling. In some cases the name of the function used depends on the type specifiers. */ @@ -8078,6 +8115,10 @@ gfc_conv_intrinsic_function (gfc_se * se, gfc_expr * expr) gfc_conv_intrinsic_strcmp (se, expr, LT_EXPR); break; + case GFC_ISYM_MALLOC: + gfc_conv_intrinsic_malloc (se, expr); + break; + case GFC_ISYM_MASKL: gfc_conv_intrinsic_mask (se, expr, 1); break; @@ -8267,7 +8308,6 @@ gfc_conv_intrinsic_function (gfc_se * se, gfc_expr * expr) case GFC_ISYM_JN2: case GFC_ISYM_LINK: case GFC_ISYM_LSTAT: - case GFC_ISYM_MALLOC: case GFC_ISYM_MATMUL: case GFC_ISYM_MCLOCK: case GFC_ISYM_MCLOCK8: @@ -9536,6 +9576,10 @@ gfc_conv_intrinsic_subroutine (gfc_code *code) res = conv_co_collective (code); break; + case GFC_ISYM_FREE: + res = conv_intrinsic_free (code); + break; + case GFC_ISYM_SYSTEM_CLOCK: res = conv_intrinsic_system_clock (code); break; -- cgit v1.1