]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/fortran/intrinsic.c
Wrap option names in gcc internal messages with %< and %>.
[thirdparty/gcc.git] / gcc / fortran / intrinsic.c
index 852ae92d211d15c9e36df97373615f6cff8f6bd1..4797b3d95cfec181f01c250621bea5504ee0b963 100644 (file)
@@ -1,6 +1,6 @@
 /* Build up a list of intrinsic subroutines and functions for the
    name-resolution stage.
-   Copyright (C) 2000-2014 Free Software Foundation, Inc.
+   Copyright (C) 2000-2019 Free Software Foundation, Inc.
    Contributed by Andy Vaught & Katherine Holcomb
 
 This file is part of GCC.
@@ -22,7 +22,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "flags.h"
+#include "options.h"
 #include "gfortran.h"
 #include "intrinsic.h"
 
@@ -60,17 +60,22 @@ enum klass
 
 
 /* Return a letter based on the passed type.  Used to construct the
-   name of a type-dependent subroutine.  */
+   name of a type-dependent subroutine.  If logical_equals_int is
+   true, we can treat a logical like an int.  */
 
 char
-gfc_type_letter (bt type)
+gfc_type_letter (bt type, bool logical_equals_int)
 {
   char c;
 
   switch (type)
     {
     case BT_LOGICAL:
-      c = 'l';
+      if (logical_equals_int)
+       c = 'i';
+      else
+       c = 'l';
+
       break;
     case BT_CHARACTER:
       c = 's';
@@ -204,7 +209,9 @@ do_ts29113_check (gfc_intrinsic_sym *specific, gfc_actual_arglist *arg)
               && specific->id != GFC_ISYM_RANK
               && specific->id != GFC_ISYM_SHAPE
               && specific->id != GFC_ISYM_SIZE
+              && specific->id != GFC_ISYM_SIZEOF
               && specific->id != GFC_ISYM_UBOUND
+              && specific->id != GFC_ISYM_IS_CONTIGUOUS
               && specific->id != GFC_ISYM_C_LOC)
        {
          gfc_error ("Assumed-type argument at %L is not permitted as actual"
@@ -332,11 +339,11 @@ add_sym (const char *name, gfc_isym_id id, enum klass cl, int actual_ok, bt type
       break;
 
     case SZ_NOTHING:
-      next_sym->name = gfc_get_string (name);
+      next_sym->name = gfc_get_string ("%s", name);
 
       strcpy (buf, "_gfortran_");
       strcat (buf, name);
-      next_sym->lib_name = gfc_get_string (buf);
+      next_sym->lib_name = gfc_get_string ("%s", buf);
 
       next_sym->pure = (cl != CLASS_IMPURE);
       next_sym->elemental = (cl == CLASS_ELEMENTAL);
@@ -519,6 +526,29 @@ add_sym_1s (const char *name, gfc_isym_id id, enum klass cl, bt type, int kind,
           (void *) 0);
 }
 
+/* Add a symbol to the subroutine ilst where the subroutine takes one
+   printf-style character argument and a variable number of arguments
+   to follow.  */
+
+static void
+add_sym_1p (const char *name, gfc_isym_id id, enum klass cl, bt type, int kind,
+           int standard, bool (*check) (gfc_actual_arglist *),
+           gfc_expr *(*simplify) (gfc_expr*), void (*resolve) (gfc_code *),
+           const char *a1, bt type1, int kind1, int optional1, sym_intent intent1)
+{
+  gfc_check_f cf;
+  gfc_simplify_f sf;
+  gfc_resolve_f rf;
+
+  cf.f1m = check;
+  sf.f1 = simplify;
+  rf.s1 = resolve;
+
+  add_sym (name, id, cl, ACTUAL_NO, type, kind, standard, cf, sf, rf,
+          a1, type1, kind1, optional1, intent1,
+          (void *) 0);
+}
+
 
 /* Add a symbol from the MAX/MIN family of intrinsic functions to the
    function.  MAX et al take 2 or more arguments.  */
@@ -659,31 +689,73 @@ add_sym_3 (const char *name, gfc_isym_id id, enum klass cl, int actual_ok, bt ty
 }
 
 
-/* MINLOC and MAXLOC get special treatment because their argument
-   might have to be reordered.  */
+/* MINLOC and MAXLOC get special treatment because their
+   argument might have to be reordered.  */
 
 static void
-add_sym_3ml (const char *name, gfc_isym_id id, enum klass cl, int actual_ok, bt type,
+add_sym_5ml (const char *name, gfc_isym_id id, enum klass cl, int actual_ok, bt type,
             int kind, int standard,
             bool (*check) (gfc_actual_arglist *),
-            gfc_expr *(*simplify) (gfc_expr *, gfc_expr *, gfc_expr *),
-            void (*resolve) (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *),
+            gfc_expr *(*simplify) (gfc_expr *, gfc_expr *, gfc_expr *,
+                                   gfc_expr *, gfc_expr *),
+            void (*resolve) (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *,
+                             gfc_expr *, gfc_expr *),
             const char *a1, bt type1, int kind1, int optional1,
             const char *a2, bt type2, int kind2, int optional2,
-            const char *a3, bt type3, int kind3, int optional3)
+            const char *a3, bt type3, int kind3, int optional3,
+            const char *a4, bt type4, int kind4, int optional4,
+            const char *a5, bt type5, int kind5, int optional5)
 {
   gfc_check_f cf;
   gfc_simplify_f sf;
   gfc_resolve_f rf;
 
-  cf.f3ml = check;
-  sf.f3 = simplify;
-  rf.f3 = resolve;
+  cf.f5ml = check;
+  sf.f5 = simplify;
+  rf.f5 = resolve;
 
   add_sym (name, id, cl, actual_ok, type, kind, standard, cf, sf, rf,
           a1, type1, kind1, optional1, INTENT_IN,
           a2, type2, kind2, optional2, INTENT_IN,
           a3, type3, kind3, optional3, INTENT_IN,
+          a4, type4, kind4, optional4, INTENT_IN,
+          a5, type5, kind5, optional5, INTENT_IN,
+          (void *) 0);
+}
+
+/* Similar for FINDLOC.  */
+
+static void
+add_sym_6fl (const char *name, gfc_isym_id id, enum klass cl, int actual_ok,
+            bt type, int kind, int standard,
+            bool (*check) (gfc_actual_arglist *),
+            gfc_expr *(*simplify) (gfc_expr *, gfc_expr *, gfc_expr *,
+                                   gfc_expr *, gfc_expr *, gfc_expr *),
+            void (*resolve) (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *,
+                             gfc_expr *, gfc_expr *, gfc_expr *),
+            const char *a1, bt type1, int kind1, int optional1,
+            const char *a2, bt type2, int kind2, int optional2,
+            const char *a3, bt type3, int kind3, int optional3,
+            const char *a4, bt type4, int kind4, int optional4,
+            const char *a5, bt type5, int kind5, int optional5,
+            const char *a6, bt type6, int kind6, int optional6)
+
+{
+  gfc_check_f cf;
+  gfc_simplify_f sf;
+  gfc_resolve_f rf;
+
+  cf.f6fl = check;
+  sf.f6 = simplify;
+  rf.f6 = resolve;
+
+  add_sym (name, id, cl, actual_ok, type, kind, standard, cf, sf, rf,
+          a1, type1, kind1, optional1, INTENT_IN,
+          a2, type2, kind2, optional2, INTENT_IN,
+          a3, type3, kind3, optional3, INTENT_IN,
+          a4, type4, kind4, optional4, INTENT_IN,
+          a5, type5, kind5, optional5, INTENT_IN,
+          a6, type6, kind6, optional6, INTENT_IN,
           (void *) 0);
 }
 
@@ -830,7 +902,7 @@ add_sym_5s (const char *name, gfc_isym_id id, enum klass cl, bt type, int kind,
            int kind3, int optional3, sym_intent intent3, const char *a4,
            bt type4, int kind4, int optional4, sym_intent intent4,
            const char *a5, bt type5, int kind5, int optional5,
-           sym_intent intent5) 
+           sym_intent intent5)
 {
   gfc_check_f cf;
   gfc_simplify_f sf;
@@ -860,7 +932,7 @@ find_sym (gfc_intrinsic_sym *start, int n, const char *name)
   /* name may be a user-supplied string, so we must first make sure
      that we're comparing against a pointer into the global string
      table.  */
-  const char *p = gfc_get_string (name);
+  const char *p = gfc_get_string ("%s", name);
 
   while (n > 0)
     {
@@ -1049,13 +1121,12 @@ gfc_is_intrinsic (gfc_symbol* sym, int subroutine_flag, locus loc)
   if (!gfc_check_intrinsic_standard (isym, &symstd, false, loc)
       && !sym->attr.artificial)
     {
-      if (sym->attr.proc == PROC_UNKNOWN
-         && gfc_option.warn_intrinsics_std)
-       gfc_warning_now ("The intrinsic '%s' at %L is not included in the"
-                        " selected standard but %s and '%s' will be"
-                        " treated as if declared EXTERNAL.  Use an"
-                        " appropriate -std=* option or define"
-                        " -fall-intrinsics to allow this intrinsic.",
+      if (sym->attr.proc == PROC_UNKNOWN && warn_intrinsics_std)
+       gfc_warning_now (OPT_Wintrinsics_std, "The intrinsic %qs at %L is not "
+                        "included in the selected standard but %s and %qs will"
+                        " be treated as if declared EXTERNAL.  Use an"
+                        " appropriate %<-std=%>* option or define"
+                        " %<-fall-intrinsics%> to allow this intrinsic.",
                         sym->name, &loc, symstd, sym->name);
 
       return false;
@@ -1086,7 +1157,7 @@ make_generic (const char *name, gfc_isym_id id, int standard ATTRIBUTE_UNUSED)
 
   g = gfc_find_function (name);
   if (g == NULL)
-    gfc_internal_error ("make_generic(): Can't find generic symbol '%s'",
+    gfc_internal_error ("make_generic(): Can't find generic symbol %qs",
                        name);
 
   gcc_assert (g->id == id);
@@ -1130,7 +1201,7 @@ make_alias (const char *name, int standard)
 
     case SZ_NOTHING:
       next_sym[0] = next_sym[-1];
-      next_sym->name = gfc_get_string (name);
+      next_sym->name = gfc_get_string ("%s", name);
       next_sym->standard = standard;
       next_sym++;
       break;
@@ -1159,6 +1230,17 @@ make_from_module (void)
     next_sym[-1].from_module = 1;
 }
 
+
+/* Mark the current subroutine as having a variable number of
+   arguments.  */
+
+static void
+make_vararg (void)
+{
+  if (sizing == SZ_NOTHING)
+    next_sym[-1].vararg = 1;
+}
+
 /* Set the attr.value of the current procedure.  */
 
 static void
@@ -1189,23 +1271,27 @@ set_attr_value (int n, ...)
 static void
 add_functions (void)
 {
-  /* Argument names as in the standard (to be used as argument keywords).  */
+  /* Argument names.  These are used as argument keywords and so need to
+    match the documentation.  Please keep this list in sorted order.  */
   const char
-    *a = "a", *f = "field", *pt = "pointer", *tg = "target",
-    *b = "b", *m = "matrix", *ma = "matrix_a", *mb = "matrix_b",
-    *c = "c", *n = "n", *ncopies= "ncopies", *pos = "pos", *bck = "back",
-    *i = "i", *v = "vector", *va = "vector_a", *vb = "vector_b",
-    *j = "j", *a1 = "a1", *fs = "fsource", *ts = "tsource",
-    *l = "l", *a2 = "a2", *mo = "mold", *ord = "order",
-    *p = "p", *ar = "array", *shp = "shape", *src = "source",
-    *r = "r", *bd = "boundary", *pad = "pad", *set = "set",
-    *s = "s", *dm = "dim", *kind = "kind", *msk = "mask",
-    *x = "x", *sh = "shift", *stg = "string", *ssg = "substring",
-    *y = "y", *sz = "size", *sta = "string_a", *stb = "string_b",
-    *z = "z", *ln = "len", *ut = "unit", *han = "handler",
-    *num = "number", *tm = "time", *nm = "name", *md = "mode",
-    *vl = "values", *p1 = "path1", *p2 = "path2", *com = "command",
-    *ca = "coarray", *sub = "sub";
+    *a = "a", *a1 = "a1", *a2 = "a2", *ar = "array", *b = "b",
+    *bck = "back", *bd = "boundary", *c = "c", *c_ptr_1 = "c_ptr_1",
+    *c_ptr_2 = "c_ptr_2", *ca = "coarray", *com = "command",
+    *dist = "distance", *dm = "dim", *f = "field", *failed="failed",
+    *fs = "fsource", *han = "handler", *i = "i",
+    *image = "image", *j = "j", *kind = "kind",
+    *l = "l", *ln = "len", *level = "level", *m = "matrix", *ma = "matrix_a",
+    *mb = "matrix_b", *md = "mode", *mo = "mold", *msk = "mask",
+    *n = "n", *ncopies= "ncopies", *nm = "name", *num = "number",
+    *ord = "order", *p = "p", *p1 = "path1", *p2 = "path2",
+    *pad = "pad", *pid = "pid", *pos = "pos", *pt = "pointer",
+    *r = "r", *s = "s", *set = "set", *sh = "shift", *shp = "shape",
+    *sig = "sig", *src = "source", *ssg = "substring",
+    *sta = "string_a", *stb = "string_b", *stg = "string",
+    *sub = "sub", *sz = "size", *tg = "target", *team = "team", *tm = "time",
+    *ts = "tsource", *ut = "unit", *v = "vector", *va = "vector_a",
+    *vb = "vector_b", *vl = "values", *val = "value", *x = "x", *y = "y",
+    *z = "z";
 
   int di, dr, dd, dl, dc, dz, ii;
 
@@ -1221,6 +1307,14 @@ add_functions (void)
             gfc_check_abs, gfc_simplify_abs, gfc_resolve_abs,
             a, BT_REAL, dr, REQUIRED);
 
+  if (flag_dec_intrinsic_ints)
+    {
+      make_alias ("babs", GFC_STD_GNU);
+      make_alias ("iiabs", GFC_STD_GNU);
+      make_alias ("jiabs", GFC_STD_GNU);
+      make_alias ("kiabs", GFC_STD_GNU);
+    }
+
   add_sym_1 ("iabs", GFC_ISYM_ABS, CLASS_ELEMENTAL, ACTUAL_YES, BT_INTEGER, di, GFC_STD_F77,
             NULL, gfc_simplify_abs, gfc_resolve_abs,
             a, BT_INTEGER, di, REQUIRED);
@@ -1233,8 +1327,8 @@ add_functions (void)
             NULL, gfc_simplify_abs, gfc_resolve_abs,
             a, BT_COMPLEX, dz, REQUIRED);
 
-  add_sym_1 ("zabs", GFC_ISYM_ABS, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL, dd, GFC_STD_GNU, 
-            NULL, gfc_simplify_abs, gfc_resolve_abs, 
+  add_sym_1 ("zabs", GFC_ISYM_ABS, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL, dd, GFC_STD_GNU,
+            NULL, gfc_simplify_abs, gfc_resolve_abs,
             a, BT_COMPLEX, dd, REQUIRED);
 
   make_alias ("cdabs", GFC_STD_GNU);
@@ -1295,8 +1389,8 @@ add_functions (void)
   make_alias ("imag", GFC_STD_GNU);
   make_alias ("imagpart", GFC_STD_GNU);
 
-  add_sym_1 ("dimag", GFC_ISYM_AIMAG, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL, dd, GFC_STD_GNU, 
-            NULL, gfc_simplify_aimag, gfc_resolve_aimag, 
+  add_sym_1 ("dimag", GFC_ISYM_AIMAG, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL, dd, GFC_STD_GNU,
+            NULL, gfc_simplify_aimag, gfc_resolve_aimag,
             z, BT_COMPLEX, dd, REQUIRED);
 
   make_generic ("aimag", GFC_ISYM_AIMAG, GFC_STD_F77);
@@ -1348,7 +1442,7 @@ add_functions (void)
             x, BT_REAL, dd, REQUIRED);
 
   make_generic ("asin", GFC_ISYM_ASIN, GFC_STD_F77);
-  
+
   add_sym_1 ("asinh", GFC_ISYM_ASINH, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL, dr,
             GFC_STD_F2008, gfc_check_fn_rc2008, gfc_simplify_asinh,
             gfc_resolve_asinh, x, BT_REAL, dr, REQUIRED);
@@ -1379,7 +1473,7 @@ add_functions (void)
             y, BT_REAL, dr, REQUIRED, x, BT_REAL, dr, REQUIRED);
 
   make_generic ("atan", GFC_ISYM_ATAN, GFC_STD_F77);
-  
+
   add_sym_1 ("atanh", GFC_ISYM_ATANH, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL, dr,
             GFC_STD_F2008, gfc_check_fn_rc2008, gfc_simplify_atanh,
             gfc_resolve_atanh, x, BT_REAL, dr, REQUIRED);
@@ -1399,7 +1493,7 @@ add_functions (void)
             y, BT_REAL, dd, REQUIRED, x, BT_REAL, dd, REQUIRED);
 
   make_generic ("atan2", GFC_ISYM_ATAN2, GFC_STD_F77);
-  
+
   /* Bessel and Neumann functions for G77 compatibility.  */
   add_sym_1 ("besj0", GFC_ISYM_J0, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_GNU,
             gfc_check_fn_r, gfc_simplify_bessel_j0, gfc_resolve_g77_math1,
@@ -1523,6 +1617,14 @@ add_functions (void)
             gfc_check_bitfcn, gfc_simplify_btest, gfc_resolve_btest,
             i, BT_INTEGER, di, REQUIRED, pos, BT_INTEGER, di, REQUIRED);
 
+  if (flag_dec_intrinsic_ints)
+    {
+      make_alias ("bbtest", GFC_STD_GNU);
+      make_alias ("bitest", GFC_STD_GNU);
+      make_alias ("bjtest", GFC_STD_GNU);
+      make_alias ("bktest", GFC_STD_GNU);
+    }
+
   make_generic ("btest", GFC_ISYM_BTEST, GFC_STD_F95);
 
   add_sym_2 ("ceiling", GFC_ISYM_CEILING, CLASS_ELEMENTAL, ACTUAL_NO, BT_INTEGER, di, GFC_STD_F95,
@@ -1556,7 +1658,7 @@ add_functions (void)
 
   make_generic ("cmplx", GFC_ISYM_CMPLX, GFC_STD_F77);
 
-  add_sym_0 ("command_argument_count", GFC_ISYM_COMMAND_ARGUMENT_COUNT, CLASS_INQUIRY, 
+  add_sym_0 ("command_argument_count", GFC_ISYM_COMMAND_ARGUMENT_COUNT, CLASS_INQUIRY,
             ACTUAL_NO, BT_INTEGER, di, GFC_STD_F2003, NULL, NULL, NULL);
 
   make_generic ("command_argument_count", GFC_ISYM_COMMAND_ARGUMENT_COUNT,
@@ -1582,7 +1684,7 @@ add_functions (void)
             z, BT_COMPLEX, dz, REQUIRED);
 
   add_sym_1 ("dconjg", GFC_ISYM_CONJG, CLASS_ELEMENTAL, ACTUAL_YES, BT_COMPLEX, dd, GFC_STD_GNU,
-            NULL, gfc_simplify_conjg, gfc_resolve_conjg, 
+            NULL, gfc_simplify_conjg, gfc_resolve_conjg,
             z, BT_COMPLEX, dd, REQUIRED);
 
   make_generic ("conjg", GFC_ISYM_CONJG, GFC_STD_F77);
@@ -1600,7 +1702,7 @@ add_functions (void)
             x, BT_COMPLEX, dz, REQUIRED);
 
   add_sym_1 ("zcos", GFC_ISYM_COS, CLASS_ELEMENTAL, ACTUAL_YES, BT_COMPLEX, dd, GFC_STD_GNU,
-            NULL, gfc_simplify_cos, gfc_resolve_cos, 
+            NULL, gfc_simplify_cos, gfc_resolve_cos,
             x, BT_COMPLEX, dd, REQUIRED);
 
   make_alias ("cdcos", GFC_STD_GNU);
@@ -1625,9 +1727,11 @@ add_functions (void)
 
   make_generic ("count", GFC_ISYM_COUNT, GFC_STD_F95);
 
-  add_sym_3 ("cshift", GFC_ISYM_CSHIFT, CLASS_TRANSFORMATIONAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_F95,
-            gfc_check_cshift, NULL, gfc_resolve_cshift,
-            ar, BT_REAL, dr, REQUIRED, sh, BT_INTEGER, di, REQUIRED,
+  add_sym_3 ("cshift", GFC_ISYM_CSHIFT, CLASS_TRANSFORMATIONAL, ACTUAL_NO,
+            BT_REAL, dr, GFC_STD_F95,
+            gfc_check_cshift, gfc_simplify_cshift, gfc_resolve_cshift,
+            ar, BT_REAL, dr, REQUIRED,
+            sh, BT_INTEGER, di, REQUIRED,
             dm, BT_INTEGER, ii, OPTIONAL);
 
   make_generic ("cshift", GFC_ISYM_CSHIFT, GFC_STD_F95);
@@ -1701,14 +1805,14 @@ add_functions (void)
   make_generic ("dshiftr", GFC_ISYM_DSHIFTR, GFC_STD_F2008);
 
   add_sym_4 ("eoshift", GFC_ISYM_EOSHIFT, CLASS_TRANSFORMATIONAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_F95,
-            gfc_check_eoshift, NULL, gfc_resolve_eoshift,
+            gfc_check_eoshift, gfc_simplify_eoshift, gfc_resolve_eoshift,
             ar, BT_REAL, dr, REQUIRED, sh, BT_INTEGER, ii, REQUIRED,
             bd, BT_REAL, dr, OPTIONAL, dm, BT_INTEGER, ii, OPTIONAL);
 
   make_generic ("eoshift", GFC_ISYM_EOSHIFT, GFC_STD_F95);
 
-  add_sym_1 ("epsilon", GFC_ISYM_EPSILON, CLASS_INQUIRY, ACTUAL_NO, BT_REAL, dr, GFC_STD_F95,
-            gfc_check_x, gfc_simplify_epsilon, NULL,
+  add_sym_1 ("epsilon", GFC_ISYM_EPSILON, CLASS_INQUIRY, ACTUAL_NO, BT_REAL, dr,
+            GFC_STD_F95, gfc_check_fn_r, gfc_simplify_epsilon, NULL,
             x, BT_REAL, dr, REQUIRED);
 
   make_generic ("epsilon", GFC_ISYM_EPSILON, GFC_STD_F95);
@@ -1767,15 +1871,15 @@ add_functions (void)
             x, BT_COMPLEX, dz, REQUIRED);
 
   add_sym_1 ("zexp", GFC_ISYM_EXP, CLASS_ELEMENTAL, ACTUAL_YES, BT_COMPLEX, dd,  GFC_STD_GNU,
-            NULL, gfc_simplify_exp, gfc_resolve_exp, 
+            NULL, gfc_simplify_exp, gfc_resolve_exp,
             x, BT_COMPLEX, dd, REQUIRED);
 
   make_alias ("cdexp", GFC_STD_GNU);
 
   make_generic ("exp", GFC_ISYM_EXP, GFC_STD_F77);
 
-  add_sym_1 ("exponent", GFC_ISYM_EXPONENT, CLASS_ELEMENTAL, ACTUAL_NO, BT_INTEGER, di, GFC_STD_F95,
-            gfc_check_x, gfc_simplify_exponent, gfc_resolve_exponent,
+  add_sym_1 ("exponent", GFC_ISYM_EXPONENT, CLASS_ELEMENTAL, ACTUAL_NO, BT_INTEGER, di,
+            GFC_STD_F95, gfc_check_fn_r, gfc_simplify_exponent, gfc_resolve_exponent,
             x, BT_REAL, dr, REQUIRED);
 
   make_generic ("exponent", GFC_ISYM_EXPONENT, GFC_STD_F95);
@@ -1787,6 +1891,13 @@ add_functions (void)
             a, BT_UNKNOWN, 0, REQUIRED,
             mo, BT_UNKNOWN, 0, REQUIRED);
 
+  add_sym_2 ("failed_images", GFC_ISYM_FAILED_IMAGES, CLASS_TRANSFORMATIONAL,
+            ACTUAL_NO, BT_INTEGER, dd, GFC_STD_F2018,
+            gfc_check_failed_or_stopped_images,
+            gfc_simplify_failed_or_stopped_images,
+            gfc_resolve_failed_images, team, BT_VOID, di, OPTIONAL,
+            kind, BT_INTEGER, di, OPTIONAL);
+
   add_sym_0 ("fdate",  GFC_ISYM_FDATE, CLASS_IMPURE, ACTUAL_NO, BT_CHARACTER,
             dc, GFC_STD_GNU, NULL, NULL, gfc_resolve_fdate);
 
@@ -1805,8 +1916,8 @@ add_functions (void)
 
   make_generic ("fnum", GFC_ISYM_FNUM, GFC_STD_GNU);
 
-  add_sym_1 ("fraction", GFC_ISYM_FRACTION, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_F95,
-            gfc_check_x, gfc_simplify_fraction, gfc_resolve_fraction,
+  add_sym_1 ("fraction", GFC_ISYM_FRACTION, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr,
+            GFC_STD_F95, gfc_check_fn_r, gfc_simplify_fraction, gfc_resolve_fraction,
             x, BT_REAL, dr, REQUIRED);
 
   make_generic ("fraction", GFC_ISYM_FRACTION, GFC_STD_F95);
@@ -1878,6 +1989,11 @@ add_functions (void)
 
   make_generic ("getpid", GFC_ISYM_GETPID, GFC_STD_GNU);
 
+  add_sym_1 ("get_team", GFC_ISYM_GET_TEAM, CLASS_TRANSFORMATIONAL,
+            ACTUAL_NO, BT_INTEGER, di, GFC_STD_F2018,
+            gfc_check_get_team, NULL, gfc_resolve_get_team,
+            level, BT_INTEGER, di, OPTIONAL);
+
   add_sym_0 ("getuid", GFC_ISYM_GETUID, CLASS_IMPURE, ACTUAL_NO, BT_INTEGER,
             di, GFC_STD_GNU, NULL, NULL, gfc_resolve_getuid);
 
@@ -1910,10 +2026,19 @@ add_functions (void)
 
   make_generic ("iachar", GFC_ISYM_IACHAR, GFC_STD_F95);
 
-  add_sym_2 ("iand", GFC_ISYM_IAND, CLASS_ELEMENTAL, ACTUAL_NO, BT_INTEGER, di, GFC_STD_F95,
-            gfc_check_iand, gfc_simplify_iand, gfc_resolve_iand,
+  add_sym_2 ("iand", GFC_ISYM_IAND, CLASS_ELEMENTAL, ACTUAL_NO, BT_INTEGER, di,
+            GFC_STD_F95,
+            gfc_check_iand_ieor_ior, gfc_simplify_iand, gfc_resolve_iand,
             i, BT_INTEGER, di, REQUIRED, j, BT_INTEGER, di, REQUIRED);
 
+  if (flag_dec_intrinsic_ints)
+    {
+      make_alias ("biand", GFC_STD_GNU);
+      make_alias ("iiand", GFC_STD_GNU);
+      make_alias ("jiand", GFC_STD_GNU);
+      make_alias ("kiand", GFC_STD_GNU);
+    }
+
   make_generic ("iand", GFC_ISYM_IAND, GFC_STD_F95);
 
   add_sym_2 ("and", GFC_ISYM_AND, CLASS_IMPURE, ACTUAL_NO, BT_LOGICAL,
@@ -1945,6 +2070,14 @@ add_functions (void)
             gfc_check_bitfcn, gfc_simplify_ibclr, gfc_resolve_ibclr,
             i, BT_INTEGER, di, REQUIRED, pos, BT_INTEGER, di, REQUIRED);
 
+  if (flag_dec_intrinsic_ints)
+    {
+      make_alias ("bbclr", GFC_STD_GNU);
+      make_alias ("iibclr", GFC_STD_GNU);
+      make_alias ("jibclr", GFC_STD_GNU);
+      make_alias ("kibclr", GFC_STD_GNU);
+    }
+
   make_generic ("ibclr", GFC_ISYM_IBCLR, GFC_STD_F95);
 
   add_sym_3 ("ibits", GFC_ISYM_IBITS, CLASS_ELEMENTAL, ACTUAL_NO, BT_INTEGER, di, GFC_STD_F95,
@@ -1952,12 +2085,28 @@ add_functions (void)
             i, BT_INTEGER, di, REQUIRED, pos, BT_INTEGER, di, REQUIRED,
             ln, BT_INTEGER, di, REQUIRED);
 
+  if (flag_dec_intrinsic_ints)
+    {
+      make_alias ("bbits", GFC_STD_GNU);
+      make_alias ("iibits", GFC_STD_GNU);
+      make_alias ("jibits", GFC_STD_GNU);
+      make_alias ("kibits", GFC_STD_GNU);
+    }
+
   make_generic ("ibits", GFC_ISYM_IBITS, GFC_STD_F95);
 
   add_sym_2 ("ibset", GFC_ISYM_IBSET, CLASS_ELEMENTAL, ACTUAL_NO, BT_INTEGER, di, GFC_STD_F95,
             gfc_check_bitfcn, gfc_simplify_ibset, gfc_resolve_ibset,
             i, BT_INTEGER, di, REQUIRED, pos, BT_INTEGER, di, REQUIRED);
 
+  if (flag_dec_intrinsic_ints)
+    {
+      make_alias ("bbset", GFC_STD_GNU);
+      make_alias ("iibset", GFC_STD_GNU);
+      make_alias ("jibset", GFC_STD_GNU);
+      make_alias ("kibset", GFC_STD_GNU);
+    }
+
   make_generic ("ibset", GFC_ISYM_IBSET, GFC_STD_F95);
 
   add_sym_2 ("ichar", GFC_ISYM_ICHAR, CLASS_ELEMENTAL, ACTUAL_NO,
@@ -1967,10 +2116,19 @@ add_functions (void)
 
   make_generic ("ichar", GFC_ISYM_ICHAR, GFC_STD_F77);
 
-  add_sym_2 ("ieor", GFC_ISYM_IEOR, CLASS_ELEMENTAL, ACTUAL_NO, BT_INTEGER, di, GFC_STD_F95,
-            gfc_check_ieor, gfc_simplify_ieor, gfc_resolve_ieor,
+  add_sym_2 ("ieor", GFC_ISYM_IEOR, CLASS_ELEMENTAL, ACTUAL_NO, BT_INTEGER, di,
+            GFC_STD_F95,
+            gfc_check_iand_ieor_ior, gfc_simplify_ieor, gfc_resolve_ieor,
             i, BT_INTEGER, di, REQUIRED, j, BT_INTEGER, di, REQUIRED);
 
+  if (flag_dec_intrinsic_ints)
+    {
+      make_alias ("bieor", GFC_STD_GNU);
+      make_alias ("iieor", GFC_STD_GNU);
+      make_alias ("jieor", GFC_STD_GNU);
+      make_alias ("kieor", GFC_STD_GNU);
+    }
+
   make_generic ("ieor", GFC_ISYM_IEOR, GFC_STD_F95);
 
   add_sym_2 ("xor", GFC_ISYM_XOR, CLASS_IMPURE, ACTUAL_NO, BT_LOGICAL,
@@ -1988,6 +2146,11 @@ add_functions (void)
             gfc_check_image_index, gfc_simplify_image_index, gfc_resolve_image_index,
             ca, BT_REAL, dr, REQUIRED, sub, BT_INTEGER, ii, REQUIRED);
 
+  add_sym_2 ("image_status", GFC_ISYM_IMAGE_STATUS, CLASS_ELEMENTAL, ACTUAL_NO,
+            BT_INTEGER, di, GFC_STD_F2018, gfc_check_image_status,
+            gfc_simplify_image_status, gfc_resolve_image_status, image,
+            BT_INTEGER, di, REQUIRED, team, BT_VOID, di, OPTIONAL);
+
   /* The resolution function for INDEX is called gfc_resolve_index_func
      because the name gfc_resolve_index is already used in resolve.c.  */
   add_sym_4 ("index", GFC_ISYM_INDEX, CLASS_ELEMENTAL, ACTUAL_YES,
@@ -2032,10 +2195,19 @@ add_functions (void)
 
   make_generic ("long", GFC_ISYM_LONG, GFC_STD_GNU);
 
-  add_sym_2 ("ior", GFC_ISYM_IOR, CLASS_ELEMENTAL, ACTUAL_NO, BT_INTEGER, di, GFC_STD_F95,
-            gfc_check_ior, gfc_simplify_ior, gfc_resolve_ior,
+  add_sym_2 ("ior", GFC_ISYM_IOR, CLASS_ELEMENTAL, ACTUAL_NO, BT_INTEGER, di,
+            GFC_STD_F95,
+            gfc_check_iand_ieor_ior, gfc_simplify_ior, gfc_resolve_ior,
             i, BT_INTEGER, di, REQUIRED, j, BT_INTEGER, di, REQUIRED);
 
+  if (flag_dec_intrinsic_ints)
+    {
+      make_alias ("bior", GFC_STD_GNU);
+      make_alias ("iior", GFC_STD_GNU);
+      make_alias ("jior", GFC_STD_GNU);
+      make_alias ("kior", GFC_STD_GNU);
+    }
+
   make_generic ("ior", GFC_ISYM_IOR, GFC_STD_F95);
 
   add_sym_2 ("or", GFC_ISYM_OR, CLASS_IMPURE, ACTUAL_NO, BT_LOGICAL,
@@ -2064,6 +2236,14 @@ add_functions (void)
 
   make_generic ("isatty", GFC_ISYM_ISATTY, GFC_STD_GNU);
 
+  add_sym_1 ("is_contiguous", GFC_ISYM_IS_CONTIGUOUS, CLASS_INQUIRY, ACTUAL_NO,
+            BT_LOGICAL, dl, GFC_STD_F2008,
+            gfc_check_is_contiguous, gfc_simplify_is_contiguous,
+            gfc_resolve_is_contiguous,
+            ar, BT_REAL, dr, REQUIRED);
+
+  make_generic ("is_contiguous", GFC_ISYM_IS_CONTIGUOUS, GFC_STD_F2008);
+
   add_sym_1 ("is_iostat_end", GFC_ISYM_IS_IOSTAT_END,
             CLASS_ELEMENTAL, ACTUAL_NO, BT_LOGICAL, dl, GFC_STD_F2003,
             gfc_check_i, gfc_simplify_is_iostat_end, NULL,
@@ -2103,6 +2283,14 @@ add_functions (void)
             gfc_check_ishft, gfc_simplify_ishft, gfc_resolve_ishft,
             i, BT_INTEGER, di, REQUIRED, sh, BT_INTEGER, di, REQUIRED);
 
+  if (flag_dec_intrinsic_ints)
+    {
+      make_alias ("bshft", GFC_STD_GNU);
+      make_alias ("iishft", GFC_STD_GNU);
+      make_alias ("jishft", GFC_STD_GNU);
+      make_alias ("kishft", GFC_STD_GNU);
+    }
+
   make_generic ("ishft", GFC_ISYM_ISHFT, GFC_STD_F95);
 
   add_sym_3 ("ishftc", GFC_ISYM_ISHFTC, CLASS_ELEMENTAL, ACTUAL_NO, BT_INTEGER, di, GFC_STD_F95,
@@ -2110,11 +2298,19 @@ add_functions (void)
             i, BT_INTEGER, di, REQUIRED, sh, BT_INTEGER, di, REQUIRED,
             sz, BT_INTEGER, di, OPTIONAL);
 
+  if (flag_dec_intrinsic_ints)
+    {
+      make_alias ("bshftc", GFC_STD_GNU);
+      make_alias ("iishftc", GFC_STD_GNU);
+      make_alias ("jishftc", GFC_STD_GNU);
+      make_alias ("kishftc", GFC_STD_GNU);
+    }
+
   make_generic ("ishftc", GFC_ISYM_ISHFTC, GFC_STD_F95);
 
   add_sym_2 ("kill", GFC_ISYM_KILL, CLASS_IMPURE, ACTUAL_NO, BT_INTEGER,
-            di, GFC_STD_GNU, gfc_check_kill, NULL, gfc_resolve_kill,
-            a, BT_INTEGER, di, REQUIRED, b, BT_INTEGER, di, REQUIRED);
+            di, GFC_STD_GNU, gfc_check_kill, NULL, NULL,
+            pid, BT_INTEGER, di, REQUIRED, sig, BT_INTEGER, di, REQUIRED);
 
   make_generic ("kill", GFC_ISYM_KILL, GFC_STD_GNU);
 
@@ -2210,7 +2406,7 @@ add_functions (void)
             p1, BT_CHARACTER, dc, REQUIRED, p2, BT_CHARACTER, dc, REQUIRED);
 
   make_generic ("link", GFC_ISYM_LINK, GFC_STD_GNU);
-  
+
   add_sym_1 ("log", GFC_ISYM_LOG, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_F77,
             gfc_check_fn_rc, gfc_simplify_log, gfc_resolve_log,
             x, BT_REAL, dr, REQUIRED);
@@ -2264,7 +2460,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);
@@ -2320,19 +2516,29 @@ add_functions (void)
 
   make_generic ("max", GFC_ISYM_MAX, GFC_STD_F77);
 
-  add_sym_1 ("maxexponent", GFC_ISYM_MAXEXPONENT, CLASS_INQUIRY, ACTUAL_NO, BT_INTEGER, di,
-            GFC_STD_F95, gfc_check_x, gfc_simplify_maxexponent, NULL,
+  add_sym_1 ("maxexponent", GFC_ISYM_MAXEXPONENT, CLASS_INQUIRY, ACTUAL_NO, BT_INTEGER,
+            di, GFC_STD_F95, gfc_check_fn_r, gfc_simplify_maxexponent, NULL,
             x, BT_UNKNOWN, dr, REQUIRED);
 
   make_generic ("maxexponent", GFC_ISYM_MAXEXPONENT, GFC_STD_F95);
 
-  add_sym_3ml ("maxloc", GFC_ISYM_MAXLOC, CLASS_TRANSFORMATIONAL, ACTUAL_NO, BT_INTEGER, di, GFC_STD_F95,
-              gfc_check_minloc_maxloc, NULL, gfc_resolve_maxloc,
+  add_sym_5ml ("maxloc", GFC_ISYM_MAXLOC, CLASS_TRANSFORMATIONAL, ACTUAL_NO, BT_INTEGER, di, GFC_STD_F95,
+              gfc_check_minloc_maxloc, gfc_simplify_maxloc, gfc_resolve_maxloc,
               ar, BT_REAL, dr, REQUIRED, dm, BT_INTEGER, ii, OPTIONAL,
-              msk, BT_LOGICAL, dl, OPTIONAL);
+              msk, BT_LOGICAL, dl, OPTIONAL, kind, BT_INTEGER, di, OPTIONAL,
+              bck, BT_LOGICAL, dl, OPTIONAL);
 
   make_generic ("maxloc", GFC_ISYM_MAXLOC, GFC_STD_F95);
 
+  add_sym_6fl ("findloc", GFC_ISYM_FINDLOC, CLASS_TRANSFORMATIONAL, ACTUAL_NO,
+              BT_INTEGER, di, GFC_STD_F2008,
+              gfc_check_findloc, gfc_simplify_findloc, gfc_resolve_findloc,
+              ar, BT_REAL, dr, REQUIRED, val, BT_REAL, dr, REQUIRED,
+              dm, BT_INTEGER, ii, OPTIONAL, msk, BT_LOGICAL, dl, OPTIONAL,
+              kind, BT_INTEGER, di, OPTIONAL, bck, BT_LOGICAL, dl, OPTIONAL);
+
+  make_generic ("findloc", GFC_ISYM_FINDLOC, GFC_STD_F2008);
+
   add_sym_3red ("maxval", GFC_ISYM_MAXVAL, CLASS_TRANSFORMATIONAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_F95,
                gfc_check_minval_maxval, gfc_simplify_maxval, gfc_resolve_maxval,
                ar, BT_REAL, dr, REQUIRED, dm, BT_INTEGER, ii, OPTIONAL,
@@ -2396,16 +2602,17 @@ add_functions (void)
 
   make_generic ("min", GFC_ISYM_MIN, GFC_STD_F77);
 
-  add_sym_1 ("minexponent", GFC_ISYM_MINEXPONENT, CLASS_INQUIRY, ACTUAL_NO, BT_INTEGER, di,
-            GFC_STD_F95, gfc_check_x, gfc_simplify_minexponent, NULL,
+  add_sym_1 ("minexponent", GFC_ISYM_MINEXPONENT, CLASS_INQUIRY, ACTUAL_NO, BT_INTEGER,
+            di, GFC_STD_F95, gfc_check_fn_r, gfc_simplify_minexponent, NULL,
             x, BT_UNKNOWN, dr, REQUIRED);
 
   make_generic ("minexponent", GFC_ISYM_MINEXPONENT, GFC_STD_F95);
 
-  add_sym_3ml ("minloc", GFC_ISYM_MINLOC, CLASS_TRANSFORMATIONAL, ACTUAL_NO, BT_INTEGER, di, GFC_STD_F95,
-              gfc_check_minloc_maxloc, NULL, gfc_resolve_minloc,
+  add_sym_5ml ("minloc", GFC_ISYM_MINLOC, CLASS_TRANSFORMATIONAL, ACTUAL_NO, BT_INTEGER, di, GFC_STD_F95,
+              gfc_check_minloc_maxloc, gfc_simplify_minloc, gfc_resolve_minloc,
               ar, BT_REAL, dr, REQUIRED, dm, BT_INTEGER, ii, OPTIONAL,
-              msk, BT_LOGICAL, dl, OPTIONAL);
+              msk, BT_LOGICAL, dl, OPTIONAL, kind, BT_INTEGER, di, OPTIONAL,
+              bck, BT_LOGICAL, dl, OPTIONAL);
 
   make_generic ("minloc", GFC_ISYM_MINLOC, GFC_STD_F95);
 
@@ -2420,6 +2627,14 @@ add_functions (void)
             gfc_check_a_p, gfc_simplify_mod, gfc_resolve_mod,
             a, BT_INTEGER, di, REQUIRED, p, BT_INTEGER, di, REQUIRED);
 
+  if (flag_dec_intrinsic_ints)
+    {
+      make_alias ("bmod", GFC_STD_GNU);
+      make_alias ("imod", GFC_STD_GNU);
+      make_alias ("jmod", GFC_STD_GNU);
+      make_alias ("kmod", GFC_STD_GNU);
+    }
+
   add_sym_2 ("amod", GFC_ISYM_MOD, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL, dr, GFC_STD_F77,
             NULL, gfc_simplify_mod, gfc_resolve_mod,
             a, BT_REAL, dr, REQUIRED, p, BT_REAL, dr, REQUIRED);
@@ -2462,6 +2677,14 @@ add_functions (void)
             gfc_check_i, gfc_simplify_not, gfc_resolve_not,
             i, BT_INTEGER, di, REQUIRED);
 
+  if (flag_dec_intrinsic_ints)
+    {
+      make_alias ("bnot", GFC_STD_GNU);
+      make_alias ("inot", GFC_STD_GNU);
+      make_alias ("jnot", GFC_STD_GNU);
+      make_alias ("knot", GFC_STD_GNU);
+    }
+
   make_generic ("not", GFC_ISYM_NOT, GFC_STD_F95);
 
   add_sym_2 ("norm2", GFC_ISYM_NORM2, CLASS_TRANSFORMATIONAL, ACTUAL_NO, BT_REAL, dr,
@@ -2477,9 +2700,11 @@ add_functions (void)
 
   make_generic ("null", GFC_ISYM_NULL, GFC_STD_F95);
 
-  add_sym_0 ("num_images", GFC_ISYM_NUM_IMAGES, CLASS_INQUIRY, ACTUAL_NO,
+  add_sym_2 ("num_images", GFC_ISYM_NUM_IMAGES, CLASS_INQUIRY, ACTUAL_NO,
             BT_INTEGER, di, GFC_STD_F2008,
-            NULL, gfc_simplify_num_images, NULL);
+            gfc_check_num_images, gfc_simplify_num_images, NULL,
+            dist, BT_INTEGER, di, OPTIONAL,
+            failed, BT_LOGICAL, dl, OPTIONAL);
 
   add_sym_3 ("pack", GFC_ISYM_PACK, CLASS_TRANSFORMATIONAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_F95,
             gfc_check_pack, gfc_simplify_pack, gfc_resolve_pack,
@@ -2553,9 +2778,9 @@ add_functions (void)
   make_generic ("range", GFC_ISYM_RANGE, GFC_STD_F95);
 
   add_sym_1 ("rank", GFC_ISYM_RANK, CLASS_INQUIRY, ACTUAL_NO, BT_INTEGER, di,
-            GFC_STD_F2008_TS, gfc_check_rank, gfc_simplify_rank, gfc_resolve_rank,
+            GFC_STD_F2018, gfc_check_rank, gfc_simplify_rank, gfc_resolve_rank,
             a, BT_REAL, dr, REQUIRED);
-  make_generic ("rank", GFC_ISYM_RANK, GFC_STD_F2008_TS);
+  make_generic ("rank", GFC_ISYM_RANK, GFC_STD_F2018);
 
   add_sym_2 ("real", GFC_ISYM_REAL, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_F77,
             gfc_check_real, gfc_simplify_real, gfc_resolve_real,
@@ -2570,6 +2795,13 @@ add_functions (void)
             gfc_check_float, gfc_simplify_float, NULL,
             a, BT_INTEGER, di, REQUIRED);
 
+  if (flag_dec_intrinsic_ints)
+    {
+      make_alias ("floati", GFC_STD_GNU);
+      make_alias ("floatj", GFC_STD_GNU);
+      make_alias ("floatk", GFC_STD_GNU);
+    }
+
   add_sym_1 ("dfloat", GFC_ISYM_REAL, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dd, GFC_STD_GNU,
             gfc_check_float, gfc_simplify_dble, gfc_resolve_dble,
             a, BT_REAL, dr, REQUIRED);
@@ -2585,7 +2817,7 @@ add_functions (void)
             p1, BT_CHARACTER, dc, REQUIRED, p2, BT_CHARACTER, dc, REQUIRED);
 
   make_generic ("rename", GFC_ISYM_RENAME, GFC_STD_GNU);
-  
+
   add_sym_2 ("repeat", GFC_ISYM_REPEAT, CLASS_TRANSFORMATIONAL, ACTUAL_NO, BT_CHARACTER, dc, GFC_STD_F95,
             gfc_check_repeat, gfc_simplify_repeat, gfc_resolve_repeat,
             stg, BT_CHARACTER, dc, REQUIRED, ncopies, BT_INTEGER, di, REQUIRED);
@@ -2599,8 +2831,8 @@ add_functions (void)
 
   make_generic ("reshape", GFC_ISYM_RESHAPE, GFC_STD_F95);
 
-  add_sym_1 ("rrspacing", GFC_ISYM_RRSPACING, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_F95,
-            gfc_check_x, gfc_simplify_rrspacing, gfc_resolve_rrspacing,
+  add_sym_1 ("rrspacing", GFC_ISYM_RRSPACING, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr,
+            GFC_STD_F95, gfc_check_fn_r, gfc_simplify_rrspacing, gfc_resolve_rrspacing,
             x, BT_REAL, dr, REQUIRED);
 
   make_generic ("rrspacing", GFC_ISYM_RRSPACING, GFC_STD_F95);
@@ -2756,15 +2988,16 @@ add_functions (void)
   make_generic ("size", GFC_ISYM_SIZE, GFC_STD_F95);
 
   /* Obtain the stride for a given dimensions; to be used only internally.
-     "make_from_module" makes inaccessible for external users.  */
+     "make_from_module" makes it inaccessible for external users.  */
   add_sym_2 (GFC_PREFIX ("stride"), GFC_ISYM_STRIDE, CLASS_INQUIRY, ACTUAL_NO,
             BT_INTEGER, gfc_index_integer_kind, GFC_STD_GNU,
             NULL, NULL, gfc_resolve_stride,
             ar, BT_REAL, dr, REQUIRED, dm, BT_INTEGER, ii, OPTIONAL);
   make_from_module();
 
-  add_sym_1 ("sizeof", GFC_ISYM_SIZEOF, CLASS_IMPURE, ACTUAL_NO, BT_INTEGER, ii,
-            GFC_STD_GNU, gfc_check_sizeof, gfc_simplify_sizeof, NULL,
+  add_sym_1 ("sizeof", GFC_ISYM_SIZEOF, CLASS_INQUIRY, ACTUAL_NO,
+            BT_INTEGER, ii, GFC_STD_GNU,
+            gfc_check_sizeof, gfc_simplify_sizeof, NULL,
             x, BT_UNKNOWN, 0, REQUIRED);
 
   make_generic ("sizeof", GFC_ISYM_SIZEOF, GFC_STD_GNU);
@@ -2772,8 +3005,8 @@ add_functions (void)
   /* The following functions are part of ISO_C_BINDING.  */
   add_sym_2 ("c_associated", GFC_ISYM_C_ASSOCIATED, CLASS_INQUIRY, ACTUAL_NO,
             BT_LOGICAL, dl, GFC_STD_F2003, gfc_check_c_associated, NULL, NULL,
-            "C_PTR_1", BT_VOID, 0, REQUIRED,
-            "C_PTR_2", BT_VOID, 0, OPTIONAL);
+            c_ptr_1, BT_VOID, 0, REQUIRED,
+            c_ptr_2, BT_VOID, 0, OPTIONAL);
   make_from_module();
 
   add_sym_1 ("c_loc", GFC_ISYM_C_LOC, CLASS_INQUIRY, ACTUAL_NO,
@@ -2794,7 +3027,7 @@ add_functions (void)
             x, BT_UNKNOWN, 0, REQUIRED);
   make_from_module();
 
-  /* COMPILER_OPTIONS and COMPILER_VERSION are part of ISO_FORTRAN_ENV.  */  
+  /* COMPILER_OPTIONS and COMPILER_VERSION are part of ISO_FORTRAN_ENV.  */
   add_sym_0 ("compiler_options", GFC_ISYM_COMPILER_OPTIONS, CLASS_INQUIRY,
             ACTUAL_NO, BT_CHARACTER, dc, GFC_STD_F2008,
             NULL, gfc_simplify_compiler_options, NULL);
@@ -2805,8 +3038,8 @@ add_functions (void)
             NULL, gfc_simplify_compiler_version, NULL);
   make_from_module();
 
-  add_sym_1 ("spacing", GFC_ISYM_SPACING, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_F95,
-            gfc_check_x, gfc_simplify_spacing, gfc_resolve_spacing,
+  add_sym_1 ("spacing", GFC_ISYM_SPACING, CLASS_ELEMENTAL, ACTUAL_NO, BT_REAL, dr,
+            GFC_STD_F95, gfc_check_fn_r, gfc_simplify_spacing, gfc_resolve_spacing,
             x, BT_REAL, dr, REQUIRED);
 
   make_generic ("spacing", GFC_ISYM_SPACING, GFC_STD_F95);
@@ -2846,13 +3079,20 @@ add_functions (void)
 
   make_generic ("stat", GFC_ISYM_STAT, GFC_STD_GNU);
 
+  add_sym_2 ("stopped_images", GFC_ISYM_STOPPED_IMAGES, CLASS_TRANSFORMATIONAL,
+            ACTUAL_NO, BT_INTEGER, dd, GFC_STD_F2018,
+            gfc_check_failed_or_stopped_images,
+            gfc_simplify_failed_or_stopped_images,
+            gfc_resolve_stopped_images, team, BT_VOID, di, OPTIONAL,
+            kind, BT_INTEGER, di, OPTIONAL);
+
   add_sym_2 ("storage_size", GFC_ISYM_STORAGE_SIZE, CLASS_INQUIRY, ACTUAL_NO,
             BT_INTEGER, di, GFC_STD_F2008,
             gfc_check_storage_size, gfc_simplify_storage_size,
             gfc_resolve_storage_size,
             a, BT_UNKNOWN, 0, REQUIRED,
             kind, BT_INTEGER, di, OPTIONAL);
-  
+
   add_sym_3red ("sum", GFC_ISYM_SUM, CLASS_TRANSFORMATIONAL, ACTUAL_NO, BT_REAL, dr, GFC_STD_F95,
                gfc_check_product_sum, gfc_simplify_sum, gfc_resolve_sum,
                ar, BT_REAL, dr, REQUIRED, dm, BT_INTEGER, ii, OPTIONAL,
@@ -2892,9 +3132,15 @@ add_functions (void)
 
   make_generic ("tanh", GFC_ISYM_TANH, GFC_STD_F77);
 
-  add_sym_2 ("this_image", GFC_ISYM_THIS_IMAGE, CLASS_INQUIRY, ACTUAL_NO, BT_INTEGER, di, GFC_STD_F2008,
+  add_sym_1 ("team_number", GFC_ISYM_TEAM_NUMBER, CLASS_TRANSFORMATIONAL,
+            ACTUAL_YES, BT_INTEGER, di, GFC_STD_F2018,
+            gfc_check_team_number, NULL, gfc_resolve_team_number,
+            team, BT_DERIVED, di, OPTIONAL);
+
+  add_sym_3 ("this_image", GFC_ISYM_THIS_IMAGE, CLASS_INQUIRY, ACTUAL_NO, BT_INTEGER, di, GFC_STD_F2008,
             gfc_check_this_image, gfc_simplify_this_image, gfc_resolve_this_image,
-            ca, BT_REAL, dr, OPTIONAL, dm, BT_INTEGER, ii, OPTIONAL);
+            ca, BT_REAL, dr, OPTIONAL, dm, BT_INTEGER, ii, OPTIONAL,
+            dist, BT_INTEGER, di, OPTIONAL);
 
   add_sym_0 ("time", GFC_ISYM_TIME, CLASS_IMPURE, ACTUAL_NO, BT_INTEGER,
             di, GFC_STD_GNU, NULL, NULL, gfc_resolve_time);
@@ -2907,8 +3153,7 @@ add_functions (void)
   make_generic ("time8", GFC_ISYM_TIME8, GFC_STD_GNU);
 
   add_sym_1 ("tiny", GFC_ISYM_TINY, CLASS_INQUIRY, ACTUAL_NO, BT_REAL, dr, GFC_STD_F95,
-            gfc_check_x, gfc_simplify_tiny, NULL,
-            x, BT_REAL, dr, REQUIRED);
+            gfc_check_fn_r, gfc_simplify_tiny, NULL, x, BT_REAL, dr, REQUIRED);
 
   make_generic ("tiny", GFC_ISYM_TINY, GFC_STD_F95);
 
@@ -2988,12 +3233,130 @@ add_functions (void)
             bck, BT_LOGICAL, dl, OPTIONAL, kind, BT_INTEGER, di, OPTIONAL);
 
   make_generic ("verify", GFC_ISYM_VERIFY, GFC_STD_F95);
-    
+
   add_sym_1 ("loc", GFC_ISYM_LOC, CLASS_IMPURE, ACTUAL_NO, BT_INTEGER, ii,
             GFC_STD_GNU, gfc_check_loc, NULL, gfc_resolve_loc,
             x, BT_UNKNOWN, 0, REQUIRED);
-               
+
   make_generic ("loc", GFC_ISYM_LOC, GFC_STD_GNU);
+
+  if (flag_dec_math)
+    {
+      add_sym_1 ("acosd", GFC_ISYM_ACOS, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dr, GFC_STD_GNU,
+                gfc_check_fn_r, gfc_simplify_atrigd, gfc_resolve_atrigd,
+                x, BT_REAL, dr, REQUIRED);
+
+      add_sym_1 ("dacosd", GFC_ISYM_ACOS, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dd, GFC_STD_GNU,
+                gfc_check_fn_d, gfc_simplify_atrigd, gfc_resolve_atrigd,
+                x, BT_REAL, dd, REQUIRED);
+
+      make_generic ("acosd", GFC_ISYM_ACOS, GFC_STD_GNU);
+
+      add_sym_1 ("asind", GFC_ISYM_ASIN, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dr, GFC_STD_GNU,
+                gfc_check_fn_r, gfc_simplify_atrigd, gfc_resolve_atrigd,
+                x, BT_REAL, dr, REQUIRED);
+
+      add_sym_1 ("dasind", GFC_ISYM_ASIN, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dd, GFC_STD_GNU,
+                gfc_check_fn_d, gfc_simplify_atrigd, gfc_resolve_atrigd,
+                x, BT_REAL, dd, REQUIRED);
+
+      make_generic ("asind", GFC_ISYM_ASIN, GFC_STD_GNU);
+
+      add_sym_1 ("atand", GFC_ISYM_ATAN, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dr, GFC_STD_GNU,
+                gfc_check_fn_r, gfc_simplify_atrigd, gfc_resolve_atrigd,
+                x, BT_REAL, dr, REQUIRED);
+
+      add_sym_1 ("datand", GFC_ISYM_ATAN, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dd, GFC_STD_GNU,
+                gfc_check_fn_d, gfc_simplify_atrigd, gfc_resolve_atrigd,
+                x, BT_REAL, dd, REQUIRED);
+
+      make_generic ("atand", GFC_ISYM_ATAN, GFC_STD_GNU);
+
+      add_sym_2 ("atan2d",GFC_ISYM_ATAN2,CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dr, GFC_STD_GNU,
+                gfc_check_atan2, gfc_simplify_atan2d, gfc_resolve_atan2d,
+                y, BT_REAL, dr, REQUIRED, x, BT_REAL, dr, REQUIRED);
+
+      add_sym_2 ("datan2d",GFC_ISYM_ATAN2,CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dd, GFC_STD_GNU,
+                gfc_check_datan2, gfc_simplify_atan2d, gfc_resolve_atan2d,
+                y, BT_REAL, dd, REQUIRED, x, BT_REAL, dd, REQUIRED);
+
+      make_generic ("atan2d", GFC_ISYM_ATAN2, GFC_STD_GNU);
+
+      add_sym_1 ("cosd", GFC_ISYM_COS, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dr, GFC_STD_GNU,
+                gfc_check_fn_r, gfc_simplify_trigd, gfc_resolve_trigd,
+                x, BT_REAL, dr, REQUIRED);
+
+      add_sym_1 ("dcosd", GFC_ISYM_COS, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dd, GFC_STD_GNU,
+                gfc_check_fn_d, gfc_simplify_trigd, gfc_resolve_trigd,
+                x, BT_REAL, dd, REQUIRED);
+
+      make_generic ("cosd", GFC_ISYM_COS, GFC_STD_GNU);
+
+      add_sym_1 ("cotan", GFC_ISYM_COTAN, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dr, GFC_STD_GNU,
+                gfc_check_fn_rc2008, gfc_simplify_cotan, gfc_resolve_cotan,
+                x, BT_REAL, dr, REQUIRED);
+
+      add_sym_1 ("dcotan", GFC_ISYM_COTAN, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dd, GFC_STD_GNU,
+                gfc_check_fn_d, gfc_simplify_cotan, gfc_resolve_cotan,
+                x, BT_REAL, dd, REQUIRED);
+
+      make_generic ("cotan", GFC_ISYM_COTAN, GFC_STD_GNU);
+
+      add_sym_1 ("cotand", GFC_ISYM_COTAN, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dr, GFC_STD_GNU,
+                gfc_check_fn_r, gfc_simplify_trigd, gfc_resolve_trigd,
+                x, BT_REAL, dr, REQUIRED);
+
+      add_sym_1 ("dcotand",GFC_ISYM_COTAN, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dd, GFC_STD_GNU,
+                gfc_check_fn_d, gfc_simplify_trigd, gfc_resolve_trigd,
+                x, BT_REAL, dd, REQUIRED);
+
+      make_generic ("cotand", GFC_ISYM_COTAN, GFC_STD_GNU);
+
+      add_sym_1 ("sind", GFC_ISYM_SIN, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dr, GFC_STD_GNU,
+                gfc_check_fn_r, gfc_simplify_trigd, gfc_resolve_trigd,
+                x, BT_REAL, dr, REQUIRED);
+
+      add_sym_1 ("dsind", GFC_ISYM_SIN, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dd, GFC_STD_GNU,
+                gfc_check_fn_d, gfc_simplify_trigd, gfc_resolve_trigd,
+                x, BT_REAL, dd, REQUIRED);
+
+      make_generic ("sind", GFC_ISYM_SIN, GFC_STD_GNU);
+
+      add_sym_1 ("tand", GFC_ISYM_TAN, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dr, GFC_STD_GNU,
+                gfc_check_fn_r, gfc_simplify_trigd, gfc_resolve_trigd,
+                x, BT_REAL, dr, REQUIRED);
+
+      add_sym_1 ("dtand", GFC_ISYM_TAN, CLASS_ELEMENTAL, ACTUAL_YES, BT_REAL,
+                dd, GFC_STD_GNU,
+                gfc_check_fn_d, gfc_simplify_trigd, gfc_resolve_trigd,
+                x, BT_REAL, dd, REQUIRED);
+
+      make_generic ("tand", GFC_ISYM_TAN, GFC_STD_GNU);
+    }
+
+  /* The following function is internally used for coarray libray functions.
+     "make_from_module" makes it inaccessible for external users.  */
+  add_sym_1 (GFC_PREFIX ("caf_get"), GFC_ISYM_CAF_GET, CLASS_IMPURE, ACTUAL_NO,
+            BT_REAL, dr, GFC_STD_GNU, NULL, NULL, NULL,
+            x, BT_REAL, dr, REQUIRED);
+  make_from_module();
 }
 
 
@@ -3002,19 +3365,20 @@ add_functions (void)
 static void
 add_subroutines (void)
 {
-  /* Argument names as in the standard (to be used as argument keywords).  */
-  const char
-    *a = "a", *h = "harvest", *dt = "date", *vl = "values", *pt = "put",
-    *c = "count", *tm = "time", *tp = "topos", *gt = "get",
-    *t = "to", *zn = "zone", *fp = "frompos", *cm = "count_max",
-    *f = "from", *sz = "size", *ln = "len", *cr = "count_rate",
-    *com = "command", *length = "length", *st = "status",
-    *val = "value", *num = "number", *name = "name",
-    *trim_name = "trim_name", *ut = "unit", *han = "handler",
-    *sec = "seconds", *res = "result", *of = "offset", *md = "mode",
-    *whence = "whence", *pos = "pos", *ptr = "ptr", *p1 = "path1",
-    *p2 = "path2", *msk = "mask", *old = "old", *result_image = "result_image",
-    *stat = "stat", *errmsg = "errmsg";
+  /* Argument names.  These are used as argument keywords and so need to
+     match the documentation.  Please keep this list in sorted order.  */
+  static const char
+    *a = "a", *c = "count", *cm = "count_max", *com = "command",
+    *cr = "count_rate", *dt = "date", *errmsg = "errmsg", *f = "from",
+    *fp = "frompos", *gt = "get", *h = "harvest", *han = "handler",
+    *length = "length", *ln = "len", *md = "mode", *msk = "mask",
+    *name = "name", *num = "number", *of = "offset", *old = "old",
+    *p1 = "path1", *p2 = "path2", *pid = "pid", *pos = "pos",
+    *pt = "put", *ptr = "ptr", *res = "result",
+    *result_image = "result_image", *sec = "seconds", *sig = "sig",
+    *st = "status", *stat = "stat", *sz = "size", *t = "to",
+    *tm = "time", *tp = "topos", *trim_name = "trim_name", *ut = "unit",
+    *val = "value", *vl = "values", *whence = "whence", *zn = "zone";
 
   int di, dr, dc, dl, ii;
 
@@ -3028,17 +3392,88 @@ add_subroutines (void)
 
   make_noreturn();
 
-  add_sym_2s ("atomic_define", GFC_ISYM_ATOMIC_DEF, CLASS_ATOMIC,
+  add_sym_3s ("atomic_define", GFC_ISYM_ATOMIC_DEF, CLASS_ATOMIC,
              BT_UNKNOWN, 0, GFC_STD_F2008,
              gfc_check_atomic_def, NULL, gfc_resolve_atomic_def,
              "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT,
-             "value", BT_INTEGER, di, REQUIRED, INTENT_IN);
+             "value", BT_INTEGER, di, REQUIRED, INTENT_IN,
+             stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT);
 
-  add_sym_2s ("atomic_ref", GFC_ISYM_ATOMIC_REF, CLASS_ATOMIC,
+  add_sym_3s ("atomic_ref", GFC_ISYM_ATOMIC_REF, CLASS_ATOMIC,
              BT_UNKNOWN, 0, GFC_STD_F2008,
              gfc_check_atomic_ref, NULL, gfc_resolve_atomic_ref,
              "value", BT_INTEGER, di, REQUIRED, INTENT_OUT,
-             "atom", BT_INTEGER, di, REQUIRED, INTENT_IN);
+             "atom", BT_INTEGER, di, REQUIRED, INTENT_IN,
+             stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT);
+
+  add_sym_5s ("atomic_cas", GFC_ISYM_ATOMIC_CAS, CLASS_ATOMIC,
+             BT_UNKNOWN, 0, GFC_STD_F2018,
+             gfc_check_atomic_cas, NULL, NULL,
+             "atom", BT_INTEGER, di, REQUIRED, INTENT_INOUT,
+             "old", BT_INTEGER, di, REQUIRED, INTENT_OUT,
+             "compare", BT_INTEGER, di, REQUIRED, INTENT_IN,
+             "new", BT_INTEGER, di, REQUIRED, INTENT_IN,
+             stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT);
+
+  add_sym_3s ("atomic_add", GFC_ISYM_ATOMIC_ADD, CLASS_ATOMIC,
+             BT_UNKNOWN, 0, GFC_STD_F2018,
+             gfc_check_atomic_op, NULL, NULL,
+             "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT,
+             "value", BT_INTEGER, di, REQUIRED, INTENT_IN,
+             stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT);
+
+  add_sym_3s ("atomic_and", GFC_ISYM_ATOMIC_AND, CLASS_ATOMIC,
+             BT_UNKNOWN, 0, GFC_STD_F2018,
+             gfc_check_atomic_op, NULL, NULL,
+             "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT,
+             "value", BT_INTEGER, di, REQUIRED, INTENT_IN,
+             stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT);
+
+  add_sym_3s ("atomic_or", GFC_ISYM_ATOMIC_OR, CLASS_ATOMIC,
+             BT_UNKNOWN, 0, GFC_STD_F2018,
+             gfc_check_atomic_op, NULL, NULL,
+             "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT,
+             "value", BT_INTEGER, di, REQUIRED, INTENT_IN,
+             stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT);
+
+  add_sym_3s ("atomic_xor", GFC_ISYM_ATOMIC_XOR, CLASS_ATOMIC,
+             BT_UNKNOWN, 0, GFC_STD_F2018,
+             gfc_check_atomic_op, NULL, NULL,
+             "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT,
+             "value", BT_INTEGER, di, REQUIRED, INTENT_IN,
+             stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT);
+
+  add_sym_4s ("atomic_fetch_add", GFC_ISYM_ATOMIC_FETCH_ADD, CLASS_ATOMIC,
+             BT_UNKNOWN, 0, GFC_STD_F2018,
+             gfc_check_atomic_fetch_op, NULL, NULL,
+             "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT,
+             "value", BT_INTEGER, di, REQUIRED, INTENT_IN,
+             "old", BT_INTEGER, di, REQUIRED, INTENT_OUT,
+             stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT);
+
+  add_sym_4s ("atomic_fetch_and", GFC_ISYM_ATOMIC_FETCH_AND, CLASS_ATOMIC,
+             BT_UNKNOWN, 0, GFC_STD_F2018,
+             gfc_check_atomic_fetch_op, NULL, NULL,
+             "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT,
+             "value", BT_INTEGER, di, REQUIRED, INTENT_IN,
+             "old", BT_INTEGER, di, REQUIRED, INTENT_OUT,
+             stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT);
+
+  add_sym_4s ("atomic_fetch_or", GFC_ISYM_ATOMIC_FETCH_OR, CLASS_ATOMIC,
+             BT_UNKNOWN, 0, GFC_STD_F2018,
+             gfc_check_atomic_fetch_op, NULL, NULL,
+             "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT,
+             "value", BT_INTEGER, di, REQUIRED, INTENT_IN,
+             "old", BT_INTEGER, di, REQUIRED, INTENT_OUT,
+             stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT);
+
+  add_sym_4s ("atomic_fetch_xor", GFC_ISYM_ATOMIC_FETCH_XOR, CLASS_ATOMIC,
+             BT_UNKNOWN, 0, GFC_STD_F2018,
+             gfc_check_atomic_fetch_op, NULL, NULL,
+             "atom", BT_INTEGER, di, REQUIRED, INTENT_OUT,
+             "value", BT_INTEGER, di, REQUIRED, INTENT_IN,
+             "old", BT_INTEGER, di, REQUIRED, INTENT_OUT,
+             stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT);
 
   add_sym_0s ("backtrace", GFC_ISYM_BACKTRACE, GFC_STD_GNU, NULL);
 
@@ -3046,6 +3481,13 @@ add_subroutines (void)
              GFC_STD_F95, gfc_check_cpu_time, NULL, gfc_resolve_cpu_time,
              tm, BT_REAL, dr, REQUIRED, INTENT_OUT);
 
+  add_sym_3s ("event_query", GFC_ISYM_EVENT_QUERY, CLASS_ATOMIC,
+             BT_UNKNOWN, 0, GFC_STD_F2018,
+             gfc_check_event_query, NULL, gfc_resolve_event_query,
+             "event", BT_INTEGER, di, REQUIRED, INTENT_IN,
+             c, BT_INTEGER, di, OPTIONAL, INTENT_IN,
+             stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT);
+
   /* More G77 compatibility garbage.  */
   add_sym_2s ("ctime", GFC_ISYM_CTIME, CLASS_IMPURE, BT_UNKNOWN, 0, GFC_STD_GNU,
              gfc_check_ctime_sub, NULL, gfc_resolve_ctime_sub,
@@ -3174,14 +3616,27 @@ add_subroutines (void)
              t, BT_UNKNOWN, 0, REQUIRED, INTENT_OUT);
 
   add_sym_5s ("mvbits", GFC_ISYM_MVBITS, CLASS_ELEMENTAL, BT_UNKNOWN, 0,
-             GFC_STD_F95, gfc_check_mvbits, gfc_simplify_mvbits,
-             gfc_resolve_mvbits,
+             GFC_STD_F95, gfc_check_mvbits, NULL, gfc_resolve_mvbits,
              f, BT_INTEGER, di, REQUIRED, INTENT_IN,
              fp, BT_INTEGER, di, REQUIRED, INTENT_IN,
              ln, BT_INTEGER, di, REQUIRED, INTENT_IN,
              t, BT_INTEGER, di, REQUIRED, INTENT_INOUT,
              tp, BT_INTEGER, di, REQUIRED, INTENT_IN);
 
+  if (flag_dec_intrinsic_ints)
+    {
+      make_alias ("bmvbits", GFC_STD_GNU);
+      make_alias ("imvbits", GFC_STD_GNU);
+      make_alias ("jmvbits", GFC_STD_GNU);
+      make_alias ("kmvbits", GFC_STD_GNU);
+    }
+
+  add_sym_2s ("random_init", GFC_ISYM_RANDOM_INIT, CLASS_IMPURE,
+             BT_UNKNOWN, 0, GFC_STD_F2018,
+             gfc_check_random_init, NULL, gfc_resolve_random_init,
+             "repeatable",     BT_LOGICAL, dl, REQUIRED, INTENT_IN,
+             "image_distinct", BT_LOGICAL, dl, REQUIRED, INTENT_IN);
+
   add_sym_1s ("random_number", GFC_ISYM_RANDOM_NUMBER, CLASS_IMPURE,
              BT_UNKNOWN, 0, GFC_STD_F95,
              gfc_check_random_number, NULL, gfc_resolve_random_number,
@@ -3210,9 +3665,28 @@ add_subroutines (void)
              "fptr", BT_UNKNOWN, 0, REQUIRED, INTENT_OUT);
   make_from_module();
 
+  /* Internal subroutine for emitting a runtime error.  */
+
+  add_sym_1p ("fe_runtime_error", GFC_ISYM_FE_RUNTIME_ERROR, CLASS_IMPURE,
+             BT_UNKNOWN, 0, GFC_STD_GNU,
+             gfc_check_fe_runtime_error, NULL, gfc_resolve_fe_runtime_error,
+             "msg", BT_CHARACTER, dc, REQUIRED, INTENT_IN);
+
+  make_noreturn ();
+  make_vararg ();
+  make_from_module ();
+
   /* Coarray collectives.  */
+  add_sym_4s ("co_broadcast", GFC_ISYM_CO_BROADCAST, CLASS_IMPURE,
+             BT_UNKNOWN, 0, GFC_STD_F2018,
+             gfc_check_co_broadcast, NULL, NULL,
+             a, BT_REAL, dr, REQUIRED, INTENT_INOUT,
+             "source_image", BT_INTEGER, di, REQUIRED, INTENT_IN,
+             stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT,
+             errmsg, BT_CHARACTER, dc, OPTIONAL, INTENT_OUT);
+
   add_sym_4s ("co_max", GFC_ISYM_CO_MAX, CLASS_IMPURE,
-             BT_UNKNOWN, 0, GFC_STD_F2008_TS,
+             BT_UNKNOWN, 0, GFC_STD_F2018,
              gfc_check_co_minmax, NULL, NULL,
              a, BT_REAL, dr, REQUIRED, INTENT_INOUT,
              result_image, BT_INTEGER, di, OPTIONAL, INTENT_IN,
@@ -3220,7 +3694,7 @@ add_subroutines (void)
              errmsg, BT_CHARACTER, dc, OPTIONAL, INTENT_OUT);
 
   add_sym_4s ("co_min", GFC_ISYM_CO_MIN, CLASS_IMPURE,
-             BT_UNKNOWN, 0, GFC_STD_F2008_TS,
+             BT_UNKNOWN, 0, GFC_STD_F2018,
              gfc_check_co_minmax, NULL, NULL,
              a, BT_REAL, dr, REQUIRED, INTENT_INOUT,
              result_image, BT_INTEGER, di, OPTIONAL, INTENT_IN,
@@ -3228,13 +3702,32 @@ add_subroutines (void)
              errmsg, BT_CHARACTER, dc, OPTIONAL, INTENT_OUT);
 
   add_sym_4s ("co_sum", GFC_ISYM_CO_SUM, CLASS_IMPURE,
-             BT_UNKNOWN, 0, GFC_STD_F2008_TS,
+             BT_UNKNOWN, 0, GFC_STD_F2018,
              gfc_check_co_sum, NULL, NULL,
              a, BT_REAL, dr, REQUIRED, INTENT_INOUT,
              result_image, BT_INTEGER, di, OPTIONAL, INTENT_IN,
              stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT,
              errmsg, BT_CHARACTER, dc, OPTIONAL, INTENT_OUT);
 
+  add_sym_5s ("co_reduce", GFC_ISYM_CO_REDUCE, CLASS_IMPURE,
+             BT_UNKNOWN, 0, GFC_STD_F2018,
+             gfc_check_co_reduce, NULL, NULL,
+             a, BT_REAL, dr, REQUIRED, INTENT_INOUT,
+             "operator", BT_INTEGER, di, REQUIRED, INTENT_IN,
+             result_image, BT_INTEGER, di, OPTIONAL, INTENT_IN,
+             stat, BT_INTEGER, di, OPTIONAL, INTENT_OUT,
+             errmsg, BT_CHARACTER, dc, OPTIONAL, INTENT_OUT);
+
+
+  /* The following subroutine is internally used for coarray libray functions.
+     "make_from_module" makes it inaccessible for external users.  */
+  add_sym_2s (GFC_PREFIX ("caf_send"), GFC_ISYM_CAF_SEND, CLASS_IMPURE,
+             BT_UNKNOWN, 0, GFC_STD_GNU, NULL, NULL, NULL,
+             "x", BT_REAL, dr, REQUIRED, INTENT_OUT,
+             "y", BT_REAL, dr, REQUIRED, INTENT_IN);
+  make_from_module();
+
+
   /* More G77 compatibility garbage.  */
   add_sym_3s ("alarm", GFC_ISYM_ALARM, CLASS_IMPURE, BT_UNKNOWN, 0, GFC_STD_GNU,
              gfc_check_alarm_sub, NULL, gfc_resolve_alarm_sub,
@@ -3279,7 +3772,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,
@@ -3300,9 +3793,9 @@ add_subroutines (void)
              st, BT_INTEGER, di, OPTIONAL, INTENT_OUT);
 
   add_sym_3s ("kill", GFC_ISYM_KILL, CLASS_IMPURE, BT_UNKNOWN, 0, GFC_STD_GNU,
-             gfc_check_kill_sub, NULL, gfc_resolve_kill_sub,
-             c, BT_INTEGER, di, REQUIRED, INTENT_IN,
-             val, BT_INTEGER, di, REQUIRED, INTENT_IN,
+             gfc_check_kill_sub, NULL, NULL,
+             pid, BT_INTEGER, di, REQUIRED, INTENT_IN,
+             sig, BT_INTEGER, di, REQUIRED, INTENT_IN,
              st, BT_INTEGER, di, OPTIONAL, INTENT_OUT);
 
   add_sym_3s ("link", GFC_ISYM_LINK, CLASS_IMPURE, BT_UNKNOWN, 0, GFC_STD_GNU,
@@ -3706,7 +4199,7 @@ sort_actual (const char *name, gfc_actual_arglist **ap,
   if (a == NULL)
     goto do_sort;
 
-  gfc_error ("Too many arguments in call to '%s' at %L", name, where);
+  gfc_error ("Too many arguments in call to %qs at %L", name, where);
   return false;
 
 keywords:
@@ -3724,14 +4217,14 @@ keywords:
            gfc_error ("The argument list functions %%VAL, %%LOC or %%REF "
                       "are not allowed in this context at %L", where);
          else
-           gfc_error ("Can't find keyword named '%s' in call to '%s' at %L",
+           gfc_error ("Can't find keyword named %qs in call to %qs at %L",
                       a->name, name, where);
          return false;
        }
 
       if (f->actual != NULL)
        {
-         gfc_error ("Argument '%s' appears twice in call to '%s' at %L",
+         gfc_error ("Argument %qs appears twice in call to %qs at %L",
                     f->name, name, where);
          return false;
        }
@@ -3745,7 +4238,7 @@ optional:
     {
       if (f->actual == NULL && f->optional == 0)
        {
-         gfc_error ("Missing actual argument '%s' in call to '%s' at %L",
+         gfc_error ("Missing actual argument %qs in call to %qs at %L",
                     f->name, name, where);
          return false;
        }
@@ -3817,7 +4310,7 @@ check_arglist (gfc_actual_arglist **ap, gfc_intrinsic_sym *sym,
       if (!gfc_compare_types (&ts, &actual->expr->ts))
        {
          if (error_flag)
-           gfc_error ("Type of argument '%s' in call to '%s' at %L should "
+           gfc_error ("Type of argument %qs in call to %qs at %L should "
                       "be %s, not %s", gfc_current_intrinsic_arg[i]->name,
                       gfc_current_intrinsic, &actual->expr->where,
                       gfc_typename (&formal->ts),
@@ -3849,7 +4342,7 @@ check_arglist (gfc_actual_arglist **ap, gfc_intrinsic_sym *sym,
 static void
 resolve_intrinsic (gfc_intrinsic_sym *specific, gfc_expr *e)
 {
-  gfc_expr *a1, *a2, *a3, *a4, *a5;
+  gfc_expr *a1, *a2, *a3, *a4, *a5, *a6;
   gfc_actual_arglist *arg;
 
   if (specific->resolve.f1 == NULL)
@@ -3923,6 +4416,15 @@ resolve_intrinsic (gfc_intrinsic_sym *specific, gfc_expr *e)
       return;
     }
 
+  a6 = arg->expr;
+  arg = arg->next;
+
+  if (arg == NULL)
+    {
+      (*specific->resolve.f6) (e, a1, a2, a3, a4, a5, a6);
+      return;
+    }
+
   gfc_internal_error ("resolve_intrinsic(): Too many args for intrinsic");
 }
 
@@ -3936,7 +4438,7 @@ resolve_intrinsic (gfc_intrinsic_sym *specific, gfc_expr *e)
 static bool
 do_simplify (gfc_intrinsic_sym *specific, gfc_expr *e)
 {
-  gfc_expr *result, *a1, *a2, *a3, *a4, *a5;
+  gfc_expr *result, *a1, *a2, *a3, *a4, *a5, *a6;
   gfc_actual_arglist *arg;
 
   /* Max and min require special handling due to the variable number
@@ -3953,6 +4455,15 @@ do_simplify (gfc_intrinsic_sym *specific, gfc_expr *e)
       goto finish;
     }
 
+  /* Some math intrinsics need to wrap the original expression.  */
+  if (specific->simplify.f1 == gfc_simplify_trigd
+      || specific->simplify.f1 == gfc_simplify_atrigd
+      || specific->simplify.f1 == gfc_simplify_cotan)
+    {
+      result = (*specific->simplify.f1) (e);
+      goto finish;
+    }
+
   if (specific->simplify.f1 == NULL)
     {
       result = NULL;
@@ -4008,8 +4519,17 @@ do_simplify (gfc_intrinsic_sym *specific, gfc_expr *e)
                  if (arg == NULL)
                    result = (*specific->simplify.f5) (a1, a2, a3, a4, a5);
                  else
-                   gfc_internal_error
-                     ("do_simplify(): Too many args for intrinsic");
+                   {
+                     a6 = arg->expr;
+                     arg = arg->next;
+
+                     if (arg == NULL)
+                       result = (*specific->simplify.f6)
+                                       (a1, a2, a3, a4, a5, a6);
+                     else
+                       gfc_internal_error
+                         ("do_simplify(): Too many args for intrinsic");
+                   }
                }
            }
        }
@@ -4086,9 +4606,11 @@ check_specific (gfc_intrinsic_sym *specific, gfc_expr *expr, int error_flag)
   if (!do_ts29113_check (specific, *ap))
     return false;
 
-  if (specific->check.f3ml == gfc_check_minloc_maxloc)
+  if (specific->check.f5ml == gfc_check_minloc_maxloc)
     /* This is special because we might have to reorder the argument list.  */
     t = gfc_check_minloc_maxloc (*ap);
+  else if (specific->check.f6fl == gfc_check_findloc)
+    t = gfc_check_findloc (*ap);
   else if (specific->check.f3red == gfc_check_minval_maxval)
     /* This is also special because we also might have to reorder the
        argument list.  */
@@ -4124,11 +4646,11 @@ check_specific (gfc_intrinsic_sym *specific, gfc_expr *expr, int error_flag)
       first_expr = arg->expr;
 
       for ( ; arg && arg->expr; arg = arg->next, n++)
-       if (!gfc_check_conformance (first_expr, arg->expr, 
+       if (!gfc_check_conformance (first_expr, arg->expr,
                                    "arguments '%s' and '%s' for "
-                                   "intrinsic '%s'", 
-                                   gfc_current_intrinsic_arg[0]->name, 
-                                   gfc_current_intrinsic_arg[n]->name, 
+                                   "intrinsic '%s'",
+                                   gfc_current_intrinsic_arg[0]->name,
+                                   gfc_current_intrinsic_arg[n]->name,
                                    gfc_current_intrinsic))
          return false;
     }
@@ -4155,7 +4677,7 @@ gfc_check_intrinsic_standard (const gfc_intrinsic_sym* isym,
   const char* symstd_msg;
 
   /* For -fall-intrinsics, just succeed.  */
-  if (gfc_option.flag_all_intrinsics)
+  if (flag_all_intrinsics)
     return true;
 
   /* Find the symbol's standard message for later usage.  */
@@ -4185,8 +4707,8 @@ gfc_check_intrinsic_standard (const gfc_intrinsic_sym* isym,
       symstd_msg = "new in Fortran 2008";
       break;
 
-    case GFC_STD_F2008_TS:
-      symstd_msg = "new in TS 29113/TS 18508";
+    case GFC_STD_F2018:
+      symstd_msg = "new in Fortran 2018";
       break;
 
     case GFC_STD_GNU:
@@ -4198,7 +4720,7 @@ gfc_check_intrinsic_standard (const gfc_intrinsic_sym* isym,
       break;
 
     default:
-      gfc_internal_error ("Invalid standard code on intrinsic '%s' (%d)",
+      gfc_internal_error ("Invalid standard code on intrinsic %qs (%d)",
                          isym->name, isym->standard);
     }
 
@@ -4207,7 +4729,7 @@ gfc_check_intrinsic_standard (const gfc_intrinsic_sym* isym,
     {
       /* Do only print a warning if not a GNU extension.  */
       if (!silent && isym->standard != GFC_STD_GNU)
-       gfc_warning ("Intrinsic '%s' (is %s) is used at %L",
+       gfc_warning (0, "Intrinsic %qs (is %s) is used at %L",
                     isym->name, _(symstd_msg), &where);
 
       return true;
@@ -4278,7 +4800,7 @@ gfc_intrinsic_func_interface (gfc_expr *expr, int error_flag)
   if ((isym->id == GFC_ISYM_REAL || isym->id == GFC_ISYM_DBLE
        || isym->id == GFC_ISYM_CMPLX)
       && gfc_init_expr_flag
-      && !gfc_notify_std (GFC_STD_F2003, "Function '%s' as initialization "
+      && !gfc_notify_std (GFC_STD_F2003, "Function %qs as initialization "
                          "expression at %L", name, &expr->where))
     {
       if (!error_flag)
@@ -4286,6 +4808,27 @@ gfc_intrinsic_func_interface (gfc_expr *expr, int error_flag)
       return MATCH_ERROR;
     }
 
+  /* F95, 7.1.6.1: Only transformational functions REPEAT, RESHAPE,
+     SELECTED_INT_KIND, SELECTED_REAL_KIND, TRANSFER, and TRIM are allowed in
+     initialization expressions.  */
+
+  if (gfc_init_expr_flag && isym->transformational)
+    {
+      gfc_isym_id id = isym->id;
+      if (id != GFC_ISYM_REPEAT && id != GFC_ISYM_RESHAPE
+         && id != GFC_ISYM_SI_KIND && id != GFC_ISYM_SR_KIND
+         && id != GFC_ISYM_TRANSFER && id != GFC_ISYM_TRIM
+         && !gfc_notify_std (GFC_STD_F2003, "Transformational function %qs "
+                             "at %L is invalid in an initialization "
+                             "expression", name, &expr->where))
+       {
+         if (!error_flag)
+           gfc_pop_suppress_errors ();
+
+         return MATCH_ERROR;
+       }
+    }
+
   gfc_current_intrinsic_where = &expr->where;
 
   /* Bypass the generic list for min, max and ISO_C_Binding's c_loc.  */
@@ -4392,7 +4935,7 @@ gfc_intrinsic_sub_interface (gfc_code *c, int error_flag)
 
   init_arglist (isym);
 
-  if (!sort_actual (name, &c->ext.actual, isym->formal, &c->loc))
+  if (!isym->vararg && !sort_actual (name, &c->ext.actual, isym->formal, &c->loc))
     goto fail;
 
   if (!do_ts29113_check (isym, c->ext.actual))
@@ -4425,14 +4968,14 @@ gfc_intrinsic_sub_interface (gfc_code *c, int error_flag)
 
   if (gfc_do_concurrent_flag && !isym->pure)
     {
-      gfc_error ("Subroutine call to intrinsic '%s' in DO CONCURRENT "
+      gfc_error ("Subroutine call to intrinsic %qs in DO CONCURRENT "
                 "block at %L is not PURE", name, &c->loc);
       return MATCH_ERROR;
     }
 
   if (!isym->pure && gfc_pure (NULL))
     {
-      gfc_error ("Subroutine call to intrinsic '%s' at %L is not PURE", name,
+      gfc_error ("Subroutine call to intrinsic %qs at %L is not PURE", name,
                 &c->loc);
       return MATCH_ERROR;
     }
@@ -4485,9 +5028,13 @@ gfc_convert_type_warn (gfc_expr *expr, gfc_typespec *ts, int eflag, int wflag)
   if (ts->type == BT_UNKNOWN)
     goto bad;
 
-  /* NULL and zero size arrays get their type here.  */
-  if (expr->expr_type == EXPR_NULL
-      || (expr->expr_type == EXPR_ARRAY && expr->value.constructor == NULL))
+  expr->do_not_warn = ! wflag;
+
+  /* NULL and zero size arrays get their type here, unless they already have a
+     typespec.  */
+  if ((expr->expr_type == EXPR_NULL
+       || (expr->expr_type == EXPR_ARRAY && expr->value.constructor == NULL))
+      && expr->ts.type == BT_UNKNOWN)
     {
       /* Sometimes the RHS acquire the type.  */
       expr->ts = *ts;
@@ -4497,6 +5044,13 @@ gfc_convert_type_warn (gfc_expr *expr, gfc_typespec *ts, int eflag, int wflag)
   if (expr->ts.type == BT_UNKNOWN)
     goto bad;
 
+  /* In building an array constructor, gfortran can end up here when no
+     conversion is required for an intrinsic type.  We need to let derived
+     types drop through.  */
+  if (from_ts.type != BT_DERIVED
+      && (from_ts.type == ts->type && from_ts.kind == ts->kind))
+    return true;
+
   if (expr->ts.type == BT_DERIVED && ts->type == BT_DERIVED
       && gfc_compare_types (&expr->ts, ts))
     return true;
@@ -4508,14 +5062,13 @@ gfc_convert_type_warn (gfc_expr *expr, gfc_typespec *ts, int eflag, int wflag)
   /* At this point, a conversion is necessary. A warning may be needed.  */
   if ((gfc_option.warn_std & sym->standard) != 0)
     {
-      gfc_warning_now ("Extension: Conversion from %s to %s at %L",
+      gfc_warning_now (0, "Extension: Conversion from %s to %s at %L",
                       gfc_typename (&from_ts), gfc_typename (ts),
                       &expr->where);
     }
   else if (wflag)
     {
-      if (gfc_option.flag_range_check
-         && expr->expr_type == EXPR_CONSTANT
+      if (flag_range_check && expr->expr_type == EXPR_CONSTANT
          && from_ts.type == ts->type)
        {
          /* Do nothing. Constants of the same type are range-checked
@@ -4542,15 +5095,18 @@ gfc_convert_type_warn (gfc_expr *expr, gfc_typespec *ts, int eflag, int wflag)
          /* Larger kinds can hold values of smaller kinds without problems.
             Hence, only warn if target kind is smaller than the source
             kind - or if -Wconversion-extra is specified.  */
-         if (gfc_option.warn_conversion_extra)
-           gfc_warning_now ("Conversion from %s to %s at %L",
-                            gfc_typename (&from_ts), gfc_typename (ts),
-                            &expr->where);
-         else if (gfc_option.gfc_warn_conversion
-                  && from_ts.kind > ts->kind)
-           gfc_warning_now ("Possible change of value in conversion "
-                            "from %s to %s at %L", gfc_typename (&from_ts),
-                            gfc_typename (ts), &expr->where);
+         if (expr->expr_type != EXPR_CONSTANT)
+           {
+             if (warn_conversion && from_ts.kind > ts->kind)
+               gfc_warning_now (OPT_Wconversion, "Possible change of value in "
+                                "conversion from %s to %s at %L",
+                                gfc_typename (&from_ts), gfc_typename (ts),
+                                &expr->where);
+             else if (warn_conversion_extra)
+               gfc_warning_now (OPT_Wconversion_extra, "Conversion from %s to %s "
+                                "at %L", gfc_typename (&from_ts),
+                                gfc_typename (ts), &expr->where);
+           }
        }
       else if ((from_ts.type == BT_REAL && ts->type == BT_INTEGER)
               || (from_ts.type == BT_COMPLEX && ts->type == BT_INTEGER)
@@ -4558,18 +5114,17 @@ gfc_convert_type_warn (gfc_expr *expr, gfc_typespec *ts, int eflag, int wflag)
        {
          /* Conversion from REAL/COMPLEX to INTEGER or COMPLEX to REAL
             usually comes with a loss of information, regardless of kinds.  */
-         if (gfc_option.warn_conversion_extra
-             || gfc_option.gfc_warn_conversion)
-           gfc_warning_now ("Possible change of value in conversion "
-                            "from %s to %s at %L", gfc_typename (&from_ts),
-                            gfc_typename (ts), &expr->where);
+         if (warn_conversion && expr->expr_type != EXPR_CONSTANT)
+           gfc_warning_now (OPT_Wconversion, "Possible change of value in "
+                            "conversion from %s to %s at %L",
+                            gfc_typename (&from_ts), gfc_typename (ts),
+                            &expr->where);
        }
       else if (from_ts.type == BT_HOLLERITH || ts->type == BT_HOLLERITH)
        {
          /* If HOLLERITH is involved, all bets are off.  */
-         if (gfc_option.warn_conversion_extra
-             || gfc_option.gfc_warn_conversion)
-           gfc_warning_now ("Conversion from %s to %s at %L",
+         if (warn_conversion)
+           gfc_warning_now (OPT_Wconversion, "Conversion from %s to %s at %L",
                             gfc_typename (&from_ts), gfc_typename (ts),
                             &expr->where);
        }
@@ -4589,12 +5144,14 @@ gfc_convert_type_warn (gfc_expr *expr, gfc_typespec *ts, int eflag, int wflag)
   new_expr->value.function.name = sym->lib_name;
   new_expr->value.function.isym = sym;
   new_expr->where = old_where;
+  new_expr->ts = *ts;
   new_expr->rank = rank;
   new_expr->shape = gfc_copy_shape (shape, rank);
 
   gfc_get_ha_sym_tree (sym->name, &new_expr->symtree);
   new_expr->symtree->n.sym->result = new_expr->symtree->n.sym;
-  new_expr->symtree->n.sym->ts = *ts;
+  new_expr->symtree->n.sym->ts.type = ts->type;
+  new_expr->symtree->n.sym->ts.kind = ts->kind;
   new_expr->symtree->n.sym->attr.flavor = FL_PROCEDURE;
   new_expr->symtree->n.sym->attr.function = 1;
   new_expr->symtree->n.sym->attr.elemental = 1;
@@ -4627,7 +5184,7 @@ bad:
       return false;
     }
 
-  gfc_internal_error ("Can't convert %s to %s at %L",
+  gfc_internal_error ("Can't convert %qs to %qs at %L",
                      gfc_typename (&from_ts), gfc_typename (ts),
                      &expr->where);
   /* Not reached */
@@ -4660,11 +5217,13 @@ gfc_convert_chartype (gfc_expr *expr, gfc_typespec *ts)
   new_expr->value.function.name = sym->lib_name;
   new_expr->value.function.isym = sym;
   new_expr->where = old_where;
+  new_expr->ts = *ts;
   new_expr->rank = rank;
   new_expr->shape = gfc_copy_shape (shape, rank);
 
   gfc_get_ha_sym_tree (sym->name, &new_expr->symtree);
-  new_expr->symtree->n.sym->ts = *ts;
+  new_expr->symtree->n.sym->ts.type = ts->type;
+  new_expr->symtree->n.sym->ts.kind = ts->kind;
   new_expr->symtree->n.sym->attr.flavor = FL_PROCEDURE;
   new_expr->symtree->n.sym->attr.function = 1;
   new_expr->symtree->n.sym->attr.elemental = 1;
@@ -4699,29 +5258,31 @@ gfc_warn_intrinsic_shadow (const gfc_symbol* sym, bool in_module, bool func)
   gfc_intrinsic_sym* isym;
 
   /* If the warning is disabled, do nothing at all.  */
-  if (!gfc_option.warn_intrinsic_shadow)
+  if (!warn_intrinsic_shadow)
     return;
 
   /* Try to find an intrinsic of the same name.  */
   if (func)
     isym = gfc_find_function (sym->name);
-  else  
+  else
     isym = gfc_find_subroutine (sym->name);
 
   /* If no intrinsic was found with this name or it's not included in the
      selected standard, everything's fine.  */
-  if (!isym || !gfc_check_intrinsic_standard (isym, NULL, true, 
+  if (!isym || !gfc_check_intrinsic_standard (isym, NULL, true,
                                              sym->declared_at))
     return;
 
   /* Emit the warning.  */
   if (in_module || sym->ns->proc_name)
-    gfc_warning ("'%s' declared at %L may shadow the intrinsic of the same"
+    gfc_warning (OPT_Wintrinsic_shadow,
+                "%qs declared at %L may shadow the intrinsic of the same"
                 " name.  In order to call the intrinsic, explicit INTRINSIC"
                 " declarations may be required.",
                 sym->name, &sym->declared_at);
   else
-    gfc_warning ("'%s' declared at %L is also the name of an intrinsic.  It can"
+    gfc_warning (OPT_Wintrinsic_shadow,
+                "%qs declared at %L is also the name of an intrinsic.  It can"
                 " only be called via an explicit interface or if declared"
                 " EXTERNAL.", sym->name, &sym->declared_at);
 }