aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/fortran/ChangeLog10
-rw-r--r--gcc/fortran/intrinsic.c4
-rw-r--r--gcc/fortran/intrinsic.h2
-rw-r--r--gcc/fortran/iresolve.c36
-rw-r--r--gcc/fortran/trans-intrinsic.c46
-rw-r--r--libgfortran/ChangeLog5
-rw-r--r--libgfortran/intrinsics/malloc.c4
7 files changed, 66 insertions, 41 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 9ca5f8d9922..24def1b4862 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,13 @@
+2015-08-28 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
+
+ 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.
+
2015-08-24 Louis Krupp <louis.krupp@zoho.com>
PR fortran/62536
diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c
index a80b16e68b4..b46a5b21b79 100644
--- a/gcc/fortran/intrinsic.c
+++ b/gcc/fortran/intrinsic.c
@@ -2298,7 +2298,7 @@ add_functions (void)
make_generic ("lstat", GFC_ISYM_LSTAT, GFC_STD_GNU);
add_sym_1 ("malloc", GFC_ISYM_MALLOC, CLASS_IMPURE, ACTUAL_NO, BT_INTEGER, ii,
- GFC_STD_GNU, gfc_check_malloc, NULL, gfc_resolve_malloc,
+ GFC_STD_GNU, gfc_check_malloc, NULL, NULL,
sz, BT_INTEGER, di, REQUIRED);
make_generic ("malloc", GFC_ISYM_MALLOC, GFC_STD_GNU);
@@ -3433,7 +3433,7 @@ add_subroutines (void)
st, BT_INTEGER, di, OPTIONAL, INTENT_OUT);
add_sym_1s ("free", GFC_ISYM_FREE, CLASS_IMPURE, BT_UNKNOWN, 0, GFC_STD_GNU,
- gfc_check_free, NULL, gfc_resolve_free,
+ gfc_check_free, NULL, NULL,
ptr, BT_INTEGER, ii, REQUIRED, INTENT_INOUT);
add_sym_4s ("fseek", GFC_ISYM_FSEEK, CLASS_IMPURE, BT_UNKNOWN, 0, GFC_STD_GNU,
diff --git a/gcc/fortran/intrinsic.h b/gcc/fortran/intrinsic.h
index a9f16f52743..4e91b822b22 100644
--- a/gcc/fortran/intrinsic.h
+++ b/gcc/fortran/intrinsic.h
@@ -522,7 +522,6 @@ void gfc_resolve_log (gfc_expr *, gfc_expr *);
void gfc_resolve_log10 (gfc_expr *, gfc_expr *);
void gfc_resolve_logical (gfc_expr *, gfc_expr *, gfc_expr *);
void gfc_resolve_lstat (gfc_expr *, gfc_expr *, gfc_expr *);
-void gfc_resolve_malloc (gfc_expr *, gfc_expr *);
void gfc_resolve_matmul (gfc_expr *, gfc_expr *, gfc_expr *);
void gfc_resolve_max (gfc_expr *, gfc_actual_arglist *);
void gfc_resolve_maxloc (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *);
@@ -605,7 +604,6 @@ void gfc_resolve_exit (gfc_code *);
void gfc_resolve_fdate_sub (gfc_code *);
void gfc_resolve_fe_runtime_error (gfc_code *);
void gfc_resolve_flush (gfc_code *);
-void gfc_resolve_free (gfc_code *);
void gfc_resolve_fseek_sub (gfc_code *);
void gfc_resolve_fstat_sub (gfc_code *);
void gfc_resolve_ftell_sub (gfc_code *);
diff --git a/gcc/fortran/iresolve.c b/gcc/fortran/iresolve.c
index cf79256b14e..7503f183749 100644
--- a/gcc/fortran/iresolve.c
+++ b/gcc/fortran/iresolve.c
@@ -1505,25 +1505,6 @@ gfc_resolve_logical (gfc_expr *f, gfc_expr *a, gfc_expr *kind)
void
-gfc_resolve_malloc (gfc_expr *f, gfc_expr *size)
-{
- if (size->ts.kind < gfc_index_integer_kind)
- {
- gfc_typespec ts;
- gfc_clear_ts (&ts);
-
- ts.type = BT_INTEGER;
- ts.kind = gfc_index_integer_kind;
- gfc_convert_type_warn (size, &ts, 2, 0);
- }
-
- f->ts.type = BT_INTEGER;
- f->ts.kind = gfc_index_integer_kind;
- f->value.function.name = gfc_get_string (PREFIX ("malloc"));
-}
-
-
-void
gfc_resolve_matmul (gfc_expr *f, gfc_expr *a, gfc_expr *b)
{
gfc_expr temp;
@@ -3386,23 +3367,6 @@ gfc_resolve_flush (gfc_code *c)
void
-gfc_resolve_free (gfc_code *c)
-{
- gfc_typespec ts;
- gfc_expr *n;
- gfc_clear_ts (&ts);
-
- ts.type = BT_INTEGER;
- ts.kind = gfc_index_integer_kind;
- n = c->ext.actual->expr;
- if (n->ts.kind != ts.kind)
- gfc_convert_type (n, &ts, 2);
-
- c->resolved_sym = gfc_get_intrinsic_sub_symbol (PREFIX ("free"));
-}
-
-
-void
gfc_resolve_ctime_sub (gfc_code *c)
{
gfc_typespec ts;
diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c
index f5b270f4bf7..554469efff0 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;
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index 75be9ad3be2..a0b70ed4c35 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,8 @@
+2015-08-28 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
+
+ PR fortran/53668
+ * intrinsics/malloc.c: Adapt comments.
+
2015-08-28 James Greenhalgh <james.greenhalgh@arm.com>
* configure.ac: Auto-detect newlib function support unless we
diff --git a/libgfortran/intrinsics/malloc.c b/libgfortran/intrinsics/malloc.c
index b3fdad74946..9ffd18fd9f0 100644
--- a/libgfortran/intrinsics/malloc.c
+++ b/libgfortran/intrinsics/malloc.c
@@ -27,6 +27,10 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
#include <stdlib.h>
+/* The runtime MALLOC and FREE are kept here until the libgfortran ABI
+ is broken. The front-end now emits direct calls to the GCC's malloc()
+ and free() built-ins. */
+
extern void PREFIX(free) (void **);
export_proto_np(PREFIX(free));