Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(revision 227310)
+++ gcc/fortran/ChangeLog	(working copy)
@@ -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
Index: gcc/fortran/intrinsic.c
===================================================================
--- gcc/fortran/intrinsic.c	(revision 227296)
+++ gcc/fortran/intrinsic.c	(working copy)
@@ -2298,7 +2298,7 @@
   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 @@
 	      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,
Index: gcc/fortran/intrinsic.h
===================================================================
--- gcc/fortran/intrinsic.h	(revision 227296)
+++ gcc/fortran/intrinsic.h	(working copy)
@@ -522,7 +522,6 @@
 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_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 *);
Index: gcc/fortran/iresolve.c
===================================================================
--- gcc/fortran/iresolve.c	(revision 227296)
+++ gcc/fortran/iresolve.c	(working copy)
@@ -1505,25 +1505,6 @@
 
 
 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 @@
 
 
 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;
Index: gcc/fortran/trans-intrinsic.c
===================================================================
--- gcc/fortran/trans-intrinsic.c	(revision 227296)
+++ gcc/fortran/trans-intrinsic.c	(working copy)
@@ -2657,6 +2657,27 @@
 }
 
 
+/* 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 @@
 }
 
 
+/* 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_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 @@
     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 @@
       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;
Index: libgfortran/ChangeLog
===================================================================
--- libgfortran/ChangeLog	(revision 227310)
+++ libgfortran/ChangeLog	(working copy)
@@ -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
Index: libgfortran/intrinsics/malloc.c
===================================================================
--- libgfortran/intrinsics/malloc.c	(revision 227296)
+++ libgfortran/intrinsics/malloc.c	(working copy)
@@ -27,6 +27,10 @@
 #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));
 
