------
WITH PATCH:

diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc
index 6bba58e7d1c..f8488f55a91 100644
--- a/gcc/fortran/check.cc
+++ b/gcc/fortran/check.cc
@@ -1865,7 +1865,7 @@ gfc_check_image_status (gfc_expr *image, gfc_expr *team)
       || !positive_check (0, image))
     return false;
 
-  return !team || (scalar_check (team, 0) && team_type_check (team, 0));
+  return !team || (scalar_check (team, 1) && team_type_check (team, 1));
 }
 
 
@@ -1908,13 +1908,8 @@ gfc_check_f_c_string (gfc_expr *string, gfc_expr *asis)
 bool
 gfc_check_failed_or_stopped_images (gfc_expr *team, gfc_expr *kind)
 {
-  if (team)
-    {
-      gfc_error ("%qs argument of %qs intrinsic at %L not yet supported",
-                gfc_current_intrinsic_arg[0]->name, gfc_current_intrinsic,
-                &team->where);
-      return false;
-    }
+  if (team && (!scalar_check (team, 0) || !team_type_check (team, 0)))
+    return false;
 
   if (kind)
     {
diff --git a/gcc/fortran/coarray.cc b/gcc/fortran/coarray.cc
index ea56ab7de78..18f4c29c105 100644
--- a/gcc/fortran/coarray.cc
+++ b/gcc/fortran/coarray.cc
@@ -696,21 +696,11 @@ check_add_new_component (gfc_symbol *type, gfc_expr *e, 
gfc_symbol *add_data)
            check_add_new_component (type, actual->expr, add_data);
          break;
        case EXPR_FUNCTION:
-         if (!e->symtree->n.sym->attr.pure
-             && !e->symtree->n.sym->attr.elemental
-             && !(e->value.function.isym
-                  && (e->value.function.isym->pure
-                      || e->value.function.isym->elemental)))
-           /* Treat non-pure/non-elemental functions.  */
-           check_add_new_comp_handle_array (e, type, add_data);
-         else
-           for (gfc_actual_arglist *actual = e->value.function.actual; actual;
-                actual = actual->next)
-             check_add_new_component (type, actual->expr, add_data);
+         check_add_new_comp_handle_array (e, type, add_data);
          break;
        case EXPR_VARIABLE:
-           check_add_new_comp_handle_array (e, type, add_data);
-           break;
+         check_add_new_comp_handle_array (e, type, add_data);
+         break;
        case EXPR_ARRAY:
        case EXPR_PPC:
        case EXPR_STRUCTURE:
diff --git a/gcc/fortran/invoke.texi b/gcc/fortran/invoke.texi
index 549c45032fd..c544037033a 100644
--- a/gcc/fortran/invoke.texi
+++ b/gcc/fortran/invoke.texi
@@ -104,6 +104,7 @@ one is not the default.
 * Interoperability Options::  Options for interoperability with other
                               languages.
 * Environment Variables:: Environment variables that affect @command{gfortran}.
+* Shared Memory Coarrays:: Multi process shared memory coarray support.
 @end menu
 
 @node Option Summary
@@ -2305,3 +2306,65 @@ variables.
 @xref{Runtime}, for environment variables that affect the
 run-time behavior of programs compiled with GNU Fortran.
 @c man end
+
+@node Shared Memory Coarrays
+@section Shared Memory Coarrays
+
+@c man begin SHARED MEMORY COARRAYS
+
+@command{gfortran} supplies a runtime library for running coarray enabled
+programs using a shared memory multi process approach.  The library is supplied
+as a static link library with the @command{libgfortran} library and is fully
+compatible with the ABI enabled when @command{gfortran} is called with
+@code{-fcoarray=lib}.  The shared memory coarray library then just needs to be
+linked to the executable produced by @command{gfortran} using
+@code{-lcaf_shmem}.
+
+The library @code{caf_shmem} can only be used on architectures that allow
+multiple processes to use the same memory at the same virtual memory address in
+each process' memory space.  This is the case on most Unix and Windows based
+systems.
+
+The resulting executable can be started without any driver and does not provide
+any additional command line options.  Limited control is possible by
+environment variables:
+
+@env{GFORTRAN_NUM_IMAGES}: The number of images to spawn when running the
+executable.  Note, there will always be one additional supervisor process, 
which
+does not participate in the computation, but is only responsible for starting
+the images and catching any (ab-)normal termination.  When the environment
+variable is not set, then the number of hardware threads reported by the OS 
will
+be taken. Over-provisioning is possible.  The number of images is limited only
+by the OS and the size of an integer variable on the architecture the program 
is
+to be run on.
+
+@env{GFORTRAN_SHARED_MEMORY_SIZE}: The size of the shared memory segment made
+available to all images is fixed and needs to be set at program start.  It can
+not grow or shrink.  The size can be given in bytes (no suffix), kilobytes
+(@code{k} or @code{K} suffix), megabytes (@code{m} or @code{M}) or gigabytes
+(@code{g} or @code{G}).  If the variable is not set, or not parseable, then on
+32-bit architectures 2^28 bytes and on 64-bit 2^34 bytes are choosen.  Note,
+although the size is set, most modern systems do not allocate the memory at
+program start.  This allows to choose a shared memory size larger than 
available
+memory.
+
+Warning: Choosing a large shared memory size may produce large coredumps!
+
+@env{GFORTRAN_IMAGE_RESTARTS_LIMIT}: On certain platforms, esp. MacOS, the
+shared memory segment needs to be placed on the same (virtual) address in every
+image or synchronisation primitives do not work as expected.  Unfortunately are
+some OSes somewhat arbitrary on when they can do this.  When the OS is not able
+to fullfill the request, then the image aborts itsself and is restarted by the
+supervisor untill the OS complies.  This environment variable limits the total
+number of restarts of all images having an issue with shared memory segment
+placement.  The default value is 4000.
+
+The shared memory coarray library internally uses some additional environment
+variables, which will be overwritten without notice or may result in failure to
+start.  These are: @code{GFORTRAN_IMAGE_NUM}, @code{GFORTRAN_SHMEM_PID} and
+@code{GFORTRAN_SHMEM_BASE}.  It is strongly discouraged to use these variables.
+Special care needs to be taken, when one coarray program starts another coarray
+program as a child process.  In this case it is the spawning process'
+responsibility to remove above variables from the environment.
+
+@c man end
diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index e5b36234d7e..a7b31e14c56 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -14247,10 +14247,33 @@ start:
              code->ext.actual = gfc_get_actual_arglist ();
              code->ext.actual->expr = code->expr1;
              code->ext.actual->next = gfc_get_actual_arglist ();
-             code->ext.actual->next->expr = code->expr2;
+             if (code->expr2->expr_type != EXPR_VARIABLE
+                 && code->expr2->expr_type != EXPR_CONSTANT)
+               {
+                 /* Convert assignments of expr1[...] = expr2 into
+                       tvar = expr2
+                       expr1[...] = tvar
+                    when expr2 is not trivial.  */
+                 gfc_expr *tvar = get_temp_from_expr (code->expr2, ns);
+                 gfc_code next_code = *code;
+                 gfc_code *rhs_code
+                   = build_assignment (EXEC_ASSIGN, tvar, code->expr2, NULL,
+                                       NULL, code->expr2->where);
+                 *code = *rhs_code;
+                 code->next = rhs_code;
+                 *rhs_code = next_code;
+
+                 rhs_code->ext.actual->next->expr = tvar;
+                 rhs_code->expr1 = NULL;
+                 rhs_code->expr2 = NULL;
+               }
+             else
+               {
+                 code->ext.actual->next->expr = code->expr2;
 
-             code->expr1 = NULL;
-             code->expr2 = NULL;
+                 code->expr1 = NULL;
+                 code->expr2 = NULL;
+               }
              break;
            }
 
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index b3262729c98..26a1886b538 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -4322,10 +4322,9 @@ gfc_build_builtin_function_decls (void)
        get_identifier (PREFIX ("caf_sync_team")), ". r w w w ", void_type_node,
        4, pvoid_type_node, pint_type, pchar_type_node, size_type_node);
 
-      gfor_fndecl_caf_team_number
-       = gfc_build_library_function_decl_with_spec (
-           get_identifier (PREFIX("caf_team_number")), ". r ",
-           integer_type_node, 1, integer_type_node);
+      gfor_fndecl_caf_team_number = gfc_build_library_function_decl_with_spec (
+       get_identifier (PREFIX ("caf_team_number")), ". r ", integer_type_node,
+       1, pvoid_type_node);
 
       gfor_fndecl_caf_image_status = gfc_build_library_function_decl_with_spec 
(
        get_identifier (PREFIX ("caf_image_status")), ". r r ",
diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index cc32d5dbb64..a2a32018edb 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -90,6 +90,8 @@ static tree
 get_scalar_to_descriptor_type (tree scalar, symbol_attribute attr)
 {
   enum gfc_array_kind akind;
+  tree *lbound = NULL, *ubound = NULL;
+  int codim = 0;
 
   if (attr.pointer)
     akind = GFC_ARRAY_POINTER_CONT;
@@ -100,8 +102,16 @@ get_scalar_to_descriptor_type (tree scalar, 
symbol_attribute attr)
 
   if (POINTER_TYPE_P (TREE_TYPE (scalar)))
     scalar = TREE_TYPE (scalar);
-  return gfc_get_array_type_bounds (TREE_TYPE (scalar), 0, 0, NULL, NULL, 1,
-                                   akind, !(attr.pointer || attr.target));
+  if (TYPE_LANG_SPECIFIC (TREE_TYPE (scalar)))
+    {
+      struct lang_type *lang_specific = TYPE_LANG_SPECIFIC (TREE_TYPE 
(scalar));
+      codim = lang_specific->corank;
+      lbound = lang_specific->lbound;
+      ubound = lang_specific->ubound;
+    }
+  return gfc_get_array_type_bounds (TREE_TYPE (scalar), 0, codim, lbound,
+                                   ubound, 1, akind,
+                                   !(attr.pointer || attr.target));
 }
 
 tree
@@ -781,11 +791,43 @@ gfc_get_vptr_from_expr (tree expr)
   return NULL_TREE;
 }
 
+static void
+copy_coarray_desc_part (stmtblock_t *block, tree dest, tree src)
+{
+  tree src_type = TREE_TYPE (src);
+  if (TYPE_LANG_SPECIFIC (src_type) && TYPE_LANG_SPECIFIC (src_type)->corank)
+    {
+      struct lang_type *lang_specific = TYPE_LANG_SPECIFIC (src_type);
+      for (int c = 0; c < lang_specific->corank; ++c)
+       {
+         int dim = lang_specific->rank + c;
+         tree codim = gfc_rank_cst[dim];
+
+         if (lang_specific->lbound[dim])
+           gfc_conv_descriptor_lbound_set (block, dest, codim,
+                                           lang_specific->lbound[dim]);
+         else
+           gfc_conv_descriptor_lbound_set (
+             block, dest, codim, gfc_conv_descriptor_lbound_get (src, codim));
+         if (dim + 1 < lang_specific->corank)
+           {
+             if (lang_specific->ubound[dim])
+               gfc_conv_descriptor_ubound_set (block, dest, codim,
+                                               lang_specific->ubound[dim]);
+             else
+               gfc_conv_descriptor_ubound_set (
+                 block, dest, codim,
+                 gfc_conv_descriptor_ubound_get (src, codim));
+           }
+       }
+    }
+}
+
 void
 gfc_class_array_data_assign (stmtblock_t *block, tree lhs_desc, tree rhs_desc,
                             bool lhs_type)
 {
-  tree tmp, tmp2, type;
+  tree lhs_dim, rhs_dim, type;
 
   gfc_conv_descriptor_data_set (block, lhs_desc,
                                gfc_conv_descriptor_data_get (rhs_desc));
@@ -796,15 +838,18 @@ gfc_class_array_data_assign (stmtblock_t *block, tree 
lhs_desc, tree rhs_desc,
                  gfc_conv_descriptor_dtype (rhs_desc));
 
   /* Assign the dimension as range-ref.  */
-  tmp = gfc_get_descriptor_dimension (lhs_desc);
-  tmp2 = gfc_get_descriptor_dimension (rhs_desc);
+  lhs_dim = gfc_get_descriptor_dimension (lhs_desc);
+  rhs_dim = gfc_get_descriptor_dimension (rhs_desc);
+
+  type = lhs_type ? TREE_TYPE (lhs_dim) : TREE_TYPE (rhs_dim);
+  lhs_dim = build4_loc (input_location, ARRAY_RANGE_REF, type, lhs_dim,
+                       gfc_index_zero_node, NULL_TREE, NULL_TREE);
+  rhs_dim = build4_loc (input_location, ARRAY_RANGE_REF, type, rhs_dim,
+                       gfc_index_zero_node, NULL_TREE, NULL_TREE);
+  gfc_add_modify (block, lhs_dim, rhs_dim);
 
-  type = lhs_type ? TREE_TYPE (tmp) : TREE_TYPE (tmp2);
-  tmp = build4_loc (input_location, ARRAY_RANGE_REF, type, tmp,
-                   gfc_index_zero_node, NULL_TREE, NULL_TREE);
-  tmp2 = build4_loc (input_location, ARRAY_RANGE_REF, type, tmp2,
-                    gfc_index_zero_node, NULL_TREE, NULL_TREE);
-  gfc_add_modify (block, tmp, tmp2);
+  /* The corank dimensions are not copied by the ARRAY_RANGE_REF.  */
+  copy_coarray_desc_part (block, lhs_desc, rhs_desc);
 }
 
 /* Takes a derived type expression and returns the address of a temporary
@@ -920,6 +965,7 @@ gfc_conv_derived_to_class (gfc_se *parmse, gfc_expr *e, 
gfc_symbol *fsym,
                                                    gfc_expr_attr (e));
              gfc_add_modify (&parmse->pre, gfc_conv_descriptor_dtype (ctree),
                              gfc_get_dtype (type));
+             copy_coarray_desc_part (&parmse->pre, ctree, parmse->expr);
              if (optional)
                parmse->expr = build3_loc (input_location, COND_EXPR,
                                           TREE_TYPE (parmse->expr),
diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index ec98f967200..4c6199cbe4a 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -2073,9 +2073,13 @@ conv_intrinsic_image_status (gfc_se *se, gfc_expr *expr)
                                            GFC_STAT_STOPPED_IMAGE));
     }
   else if (flag_coarray == GFC_FCOARRAY_LIB)
+    /* The team is optional and therefore needs to be a pointer to the opaque
+       pointer.  */
     tmp = build_call_expr_loc (input_location, gfor_fndecl_caf_image_status, 2,
                               args[0],
-                              num_args < 2 ? null_pointer_node : args[1]);
+                              num_args < 2
+                                ? null_pointer_node
+                                : gfc_build_addr_expr (NULL_TREE, args[1]));
   else
     gcc_unreachable ();
 
diff --git a/gcc/fortran/trans-stmt.cc b/gcc/fortran/trans-stmt.cc
index 1e1179323c4..4d2ca182f80 100644
--- a/gcc/fortran/trans-stmt.cc
+++ b/gcc/fortran/trans-stmt.cc
@@ -1362,7 +1362,8 @@ gfc_trans_sync (gfc_code *code, gfc_exec_op type)
     {
       gfc_init_se (&argse, NULL);
       gfc_conv_expr_val (&argse, code->expr1);
-      images = argse.expr;
+      images = gfc_trans_force_lval (&argse.pre, argse.expr);
+      gfc_add_block_to_block (&se.pre, &argse.pre);
     }
 
   if (code->expr2)
@@ -1372,6 +1373,7 @@ gfc_trans_sync (gfc_code *code, gfc_exec_op type)
       gfc_init_se (&argse, NULL);
       gfc_conv_expr_val (&argse, code->expr2);
       stat = argse.expr;
+      gfc_add_block_to_block (&se.pre, &argse.pre);
     }
   else
     stat = null_pointer_node;
@@ -1384,8 +1386,9 @@ gfc_trans_sync (gfc_code *code, gfc_exec_op type)
       argse.want_pointer = 1;
       gfc_conv_expr (&argse, code->expr3);
       gfc_conv_string_parameter (&argse);
-      errmsg = gfc_build_addr_expr (NULL, argse.expr);
+      errmsg = argse.expr;
       errmsglen = fold_convert (size_type_node, argse.string_length);
+      gfc_add_block_to_block (&se.pre, &argse.pre);
     }
   else if (flag_coarray == GFC_FCOARRAY_LIB)
     {
diff --git a/gcc/testsuite/gfortran.dg/coarray/alloc_comp_4.f90 
b/gcc/testsuite/gfortran.dg/coarray/alloc_comp_4.f90
index 2ee8ff0253d..50b4bab1603 100644
--- a/gcc/testsuite/gfortran.dg/coarray/alloc_comp_4.f90
+++ b/gcc/testsuite/gfortran.dg/coarray/alloc_comp_4.f90
@@ -11,11 +11,19 @@ program main
   end type
 
   type(mytype), save :: object[*]
-  integer :: me
+  integer :: me, other
 
   me=this_image()
-  allocate(object%indices(me))
-  object%indices = 42
+  other = me + 1
+  if (other .GT. num_images()) other = 1
+  if (me == num_images()) then
+     allocate(object%indices(me/2))
+  else
+    allocate(object%indices(me))
+  end if
+  object%indices = 42 * me
 
-  if ( any( object[me]%indices(:) /= 42 ) ) STOP 1
+  sync all
+  if ( any( object[other]%indices(:) /= 42 * other ) ) STOP 1
+  sync all
 end program
diff --git a/gcc/testsuite/gfortran.dg/coarray/atomic_2.f90 
b/gcc/testsuite/gfortran.dg/coarray/atomic_2.f90
index 5e1c4967248..7eccd7b578c 100644
--- a/gcc/testsuite/gfortran.dg/coarray/atomic_2.f90
+++ b/gcc/testsuite/gfortran.dg/coarray/atomic_2.f90
@@ -61,7 +61,7 @@ end do
 sync all
 
 call atomic_ref(var, caf[num_images()], stat=stat)
-if (stat /= 0 .or. var /= num_images() + this_image()) STOP 12
+if (stat /= 0 .or. var /= num_images() * 2) STOP 12
 do i = 1, num_images()
   call atomic_ref(var, caf[i], stat=stat)
   if (stat /= 0 .or. var /= num_images() + i) STOP 13
@@ -328,7 +328,7 @@ end do
 sync all
 
 call atomic_ref(var, caf[num_images()], stat=stat)
-if (stat /= 0 .or. var /= num_images() + this_image()) STOP 45
+if (stat /= 0 .or. var /= num_images() * 2) STOP 45
 do i = 1, num_images()
   call atomic_ref(var, caf[i], stat=stat)
   if (stat /= 0 .or. var /= num_images() + i) STOP 46
@@ -403,7 +403,7 @@ if (this_image() < storage_size(caf)-2) then
   do i = this_image(), min(num_images(), storage_size(caf)-2)
     var = -99
     call atomic_fetch_and(caf[i], shiftl(1, this_image()), var, stat=stat)
-    if (stat /= 0 .or. var <= 0) STOP 53
+    if (stat /= 0) STOP 53
   end do
 end if
 sync all
@@ -544,7 +544,7 @@ if (this_image() < storage_size(caf)-2) then
   do i = this_image(), min(num_images(), storage_size(caf)-2)
     var = -99
     call atomic_fetch_xor(caf[i], shiftl(1, this_image()), var, stat=stat)
-    if (stat /= 0 .or. (var < 0 .and. var /= -1)) STOP 68
+    if (stat /= 0) STOP 68
   end do
 end if
 sync all
@@ -628,26 +628,27 @@ sync all
 
 if (this_image() == 1) then
   call atomic_cas(caf_log[num_images()], compare=.false., new=.false., 
old=var2, stat=stat)
-  if (stat /= 0 .or. var2 .neqv. .true.) STOP 82
+  if (stat /= 0 .or. (var2 .neqv. .true.)) STOP 82
   call atomic_ref(var2, caf_log[num_images()], stat=stat)
-  if (stat /= 0 .or. var2 .neqv. .true.) STOP 83
+  if (stat /= 0 .or. (var2 .neqv. .true.)) STOP 83
 end if
 sync all
 
-if (this_image() == num_images() .and. caf_log .neqv. .true.) STOP 84
+if (this_image() == num_images() .and. (caf_log .neqv. .true.)) STOP 84
 call atomic_ref(var2, caf_log[num_images()], stat=stat)
-if (stat /= 0 .or. var2 .neqv. .true.) STOP 85
+if (stat /= 0 .or. (var2 .neqv. .true.)) STOP 85
 sync all
 
 if (this_image() == 1) then
   call atomic_cas(caf_log[num_images()], compare=.true., new=.false., 
old=var2, stat=stat)
-  if (stat /= 0 .or. var2 .neqv. .true.) STOP 86
+  if (stat /= 0 .or. (var2 .neqv. .true.)) STOP 86
   call atomic_ref(var2, caf_log[num_images()], stat=stat)
-  if (stat /= 0 .or. var2 .neqv. .false.) STOP 87
+  if (stat /= 0 .or. (var2 .neqv. .false.)) STOP 87
 end if
 sync all
 
-if (this_image() == num_images() .and. caf_log .neqv. .false.) STOP 88
+if (this_image() == num_images() .and. (caf_log .neqv. .false.)) STOP 88
 call atomic_ref(var2, caf_log[num_images()], stat=stat)
-if (stat /= 0 .or. var2 .neqv. .false.) STOP 89
+if (stat /= 0 .or. (var2 .neqv. .false.)) STOP 89
+sync all
 end
diff --git a/gcc/testsuite/gfortran.dg/coarray/caf.exp 
b/gcc/testsuite/gfortran.dg/coarray/caf.exp
index c8ea08980e2..9cd99f8e0cb 100644
--- a/gcc/testsuite/gfortran.dg/coarray/caf.exp
+++ b/gcc/testsuite/gfortran.dg/coarray/caf.exp
@@ -70,6 +70,12 @@ proc dg-compile-aux-modules { args } {
     }
 }
 
+if { [getenv GFORTRAN_NUM_IMAGES] == "" } {
+  # Some caf_shmem tests need at least 8 images.  This is also to limit the
+  # number of images on big machines preventing overload w/o any benefit.
+  setenv GFORTRAN_NUM_IMAGES 8
+}
+
 # Main loop.
 foreach test [lsort [glob -nocomplain 
\$srcdir/\$subdir/*.\\[fF\\]{,90,95,03,08} ]] {
     # If we're only testing specific files and this isn't one of them, skip it.
@@ -103,6 +109,13 @@ foreach test [lsort [glob -nocomplain 
\$srcdir/\$subdir/*.\\[fF\\]{,90,95,03,08} ]]
        dg-test \$test "-fcoarray=lib \$flags -lcaf_single" {}
        cleanup-modules ""
     }
+
+    foreach flags \$option_list {
+        verbose "Testing \$nshort (libcaf_shmem), \$flags" 1
+        set gfortran_aux_module_flags "-fcoarray=lib \$flags -lcaf_shmem"
+        dg-test \$test "-fcoarray=lib \$flags -lcaf_shmem" {}
+        cleanup-modules ""
+    }
 }
 torture-finish
 dg-finish
diff --git a/gcc/testsuite/gfortran.dg/coarray/coarray_allocated.f90 
b/gcc/testsuite/gfortran.dg/coarray/coarray_allocated.f90
index 27db0e8d8ce..ce7c6288a61 100644
--- a/gcc/testsuite/gfortran.dg/coarray/coarray_allocated.f90
+++ b/gcc/testsuite/gfortran.dg/coarray/coarray_allocated.f90
@@ -19,7 +19,7 @@ program p
   ! For this reason, -fcoarray=single and -fcoarray=lib give the
   ! same result
   if (allocated (a[1])) stop 3
-  if (allocated (c%x[1,2,3])) stop 4
+  if (allocated (c%x[1,1,1])) stop 4
 
   ! Allocate collectively
   allocate(a[*])
@@ -28,16 +28,17 @@ program p
   if (.not. allocated (a)) stop 5
   if (.not. allocated (c%x)) stop 6
   if (.not. allocated (a[1])) stop 7
-  if (.not. allocated (c%x[1,2,3])) stop 8
+  if (.not. allocated (c%x[1,1,1])) stop 8
 
-  ! Deallocate collectively
+  sync all
+  ! Dellocate collectively
   deallocate(a)
   deallocate(c%x)
 
   if (allocated (a)) stop 9
   if (allocated (c%x)) stop 10
   if (allocated (a[1])) stop 11
-  if (allocated (c%x[1,2,3])) stop 12
+  if (allocated (c%x[1,1,1])) stop 12
 end
 
 ! Expected: always local access and never a call to _gfortran_caf_get
diff --git a/gcc/testsuite/gfortran.dg/coarray/coindexed_1.f90 
b/gcc/testsuite/gfortran.dg/coarray/coindexed_1.f90
index f90b65cb389..8f7a83a9c99 100644
--- a/gcc/testsuite/gfortran.dg/coarray/coindexed_1.f90
+++ b/gcc/testsuite/gfortran.dg/coarray/coindexed_1.f90
@@ -21,6 +21,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   str1a = 1_"abc"
   str2a = 1_"XXXXXXX"
+  sync all
   if (this_image() == num_images()) then
     str2a[1] = str1a
   end if
@@ -37,6 +38,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   ustr1a = 4_"abc"
   ustr2a = 4_"XXXXXXX"
+  sync all
   if (this_image() == num_images()) then
     ustr2a[1] = ustr1a
   end if
@@ -53,6 +55,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   str2a = 1_"abcde"
   str1a = 1_"XXX"
+  sync all
   if (this_image() == num_images()) then
     str1a[1] = str2a
   end if
@@ -69,6 +72,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   ustr2a = 4_"abcde"
   ustr1a = 4_"XXX"
+  sync all
   if (this_image() == num_images()) then
     ustr1a[1] = ustr2a
   end if
@@ -91,6 +95,7 @@ subroutine char_test()
   str2b(1) = 1_"XXXXXXX"
   str2b(2) = 1_"YYYYYYY"
   str2b(3) = 1_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     str2b(:)[1] = str1b
   end if
@@ -113,6 +118,7 @@ subroutine char_test()
   ustr2b(1) = 4_"XXXXXXX"
   ustr2b(2) = 4_"YYYYYYY"
   ustr2b(3) = 4_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr2b(:)[1] = ustr1b
   end if
@@ -135,6 +141,7 @@ subroutine char_test()
   str1b(1) = 1_"XXX"
   str1b(2) = 1_"YYY"
   str1b(3) = 1_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     str1b(:)[1] = str2b
   end if
@@ -157,6 +164,7 @@ subroutine char_test()
   ustr1b(1) = 4_"XXX"
   ustr1b(2) = 4_"YYY"
   ustr1b(3) = 4_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr1b(:)[1] = ustr2b
   end if
@@ -179,6 +187,7 @@ subroutine char_test()
   str2b(1) = 1_"XXXXXXX"
   str2b(2) = 1_"YYYYYYY"
   str2b(3) = 1_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     str2b(:)[1] = str1a
   end if
@@ -199,6 +208,7 @@ subroutine char_test()
   ustr2b(1) = 4_"XXXXXXX"
   ustr2b(2) = 4_"YYYYYYY"
   ustr2b(3) = 4_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr2b(:)[1] = ustr1a
   end if
@@ -219,6 +229,7 @@ subroutine char_test()
   str1b(1) = 1_"XXX"
   str1b(2) = 1_"YYY"
   str1b(3) = 1_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     str1b(:)[1] = str2a
   end if
@@ -239,6 +250,7 @@ subroutine char_test()
   ustr1b(1) = 4_"XXX"
   ustr1b(2) = 4_"YYY"
   ustr1b(3) = 4_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr1b(:)[1] = ustr2a
   end if
@@ -261,6 +273,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   str1a = 1_"abc"
   str2a = 1_"XXXXXXX"
+  sync all
   if (this_image() == num_images()) then
     str2a = str1a[1]
   end if
@@ -277,6 +290,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   ustr1a = 4_"abc"
   ustr2a = 4_"XXXXXXX"
+  sync all
   if (this_image() == num_images()) then
     ustr2a = ustr1a[1]
   end if
@@ -293,6 +307,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   str2a = 1_"abcde"
   str1a = 1_"XXX"
+  sync all
   if (this_image() == num_images()) then
     str1a = str2a[1]
   end if
@@ -309,6 +324,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   ustr2a = 4_"abcde"
   ustr1a = 4_"XXX"
+  sync all
   if (this_image() == num_images()) then
     ustr1a = ustr2a[1]
   end if
@@ -331,6 +347,7 @@ subroutine char_test()
   str2b(1) = 1_"XXXXXXX"
   str2b(2) = 1_"YYYYYYY"
   str2b(3) = 1_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     str2b = str1b(:)[1]
   end if
@@ -353,6 +370,7 @@ subroutine char_test()
   ustr2b(1) = 4_"XXXXXXX"
   ustr2b(2) = 4_"YYYYYYY"
   ustr2b(3) = 4_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr2b = ustr1b(:)[1]
   end if
@@ -375,6 +393,7 @@ subroutine char_test()
   str1b(1) = 1_"XXX"
   str1b(2) = 1_"YYY"
   str1b(3) = 1_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     str1b = str2b(:)[1]
   end if
@@ -397,6 +416,7 @@ subroutine char_test()
   ustr1b(1) = 4_"XXX"
   ustr1b(2) = 4_"YYY"
   ustr1b(3) = 4_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr1b = ustr2b(:)[1]
   end if
@@ -419,6 +439,7 @@ subroutine char_test()
   str2b(1) = 1_"XXXXXXX"
   str2b(2) = 1_"YYYYYYY"
   str2b(3) = 1_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     str2b = str1a[1]
   end if
@@ -439,6 +460,7 @@ subroutine char_test()
   ustr2b(1) = 4_"XXXXXXX"
   ustr2b(2) = 4_"YYYYYYY"
   ustr2b(3) = 4_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr2b = ustr1a[1]
   end if
@@ -459,6 +481,7 @@ subroutine char_test()
   str1b(1) = 1_"XXX"
   str1b(2) = 1_"YYY"
   str1b(3) = 1_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     str1b = str2a[1]
   end if
@@ -479,6 +502,7 @@ subroutine char_test()
   ustr1b(1) = 4_"XXX"
   ustr1b(2) = 4_"YYY"
   ustr1b(3) = 4_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr1b = ustr2a[1]
   end if
@@ -502,6 +526,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   str1a = 1_"abc"
   str2a = 1_"XXXXXXX"
+  sync all
   if (this_image() == num_images()) then
     str2a[1] = str1a[mod(1, num_images())+1]
   end if
@@ -518,6 +543,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   ustr1a = 4_"abc"
   ustr2a = 4_"XXXXXXX"
+  sync all
   if (this_image() == num_images()) then
     ustr2a[1] = ustr1a[mod(1, num_images())+1]
   end if
@@ -534,6 +560,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   str2a = 1_"abcde"
   str1a = 1_"XXX"
+  sync all
   if (this_image() == num_images()) then
     str1a[1] = str2a[mod(1, num_images())+1]
   end if
@@ -550,6 +577,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   ustr2a = 4_"abcde"
   ustr1a = 4_"XXX"
+  sync all
   if (this_image() == num_images()) then
     ustr1a[1] = ustr2a[mod(1, num_images())+1]
   end if
@@ -572,6 +600,7 @@ subroutine char_test()
   str2b(1) = 1_"XXXXXXX"
   str2b(2) = 1_"YYYYYYY"
   str2b(3) = 1_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     str2b(:)[1] = str1b(:)[mod(1, num_images())+1]
   end if
@@ -594,6 +623,7 @@ subroutine char_test()
   ustr2b(1) = 4_"XXXXXXX"
   ustr2b(2) = 4_"YYYYYYY"
   ustr2b(3) = 4_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr2b(:)[1] = ustr1b(:)[mod(1, num_images())+1]
   end if
@@ -616,6 +646,7 @@ subroutine char_test()
   str1b(1) = 1_"XXX"
   str1b(2) = 1_"YYY"
   str1b(3) = 1_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     str1b(:)[1] = str2b(:)[mod(1, num_images())+1]
   end if
@@ -638,6 +669,7 @@ subroutine char_test()
   ustr1b(1) = 4_"XXX"
   ustr1b(2) = 4_"YYY"
   ustr1b(3) = 4_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr1b(:)[1] = ustr2b(:)[mod(1, num_images())+1]
   end if
@@ -660,6 +692,7 @@ subroutine char_test()
   str2b(1) = 1_"XXXXXXX"
   str2b(2) = 1_"YYYYYYY"
   str2b(3) = 1_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     str2b(:)[1] = str1a[mod(1, num_images())+1]
   end if
@@ -680,6 +713,7 @@ subroutine char_test()
   ustr2b(1) = 4_"XXXXXXX"
   ustr2b(2) = 4_"YYYYYYY"
   ustr2b(3) = 4_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr2b(:)[1] = ustr1a[mod(1, num_images())+1]
   end if
@@ -700,6 +734,7 @@ subroutine char_test()
   str1b(1) = 1_"XXX"
   str1b(2) = 1_"YYY"
   str1b(3) = 1_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     str1b(:)[1] = str2a[mod(1, num_images())+1]
   end if
@@ -720,6 +755,7 @@ subroutine char_test()
   ustr1b(1) = 4_"XXX"
   ustr1b(2) = 4_"YYY"
   ustr1b(3) = 4_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr1b(:)[1] = ustr2a[mod(1, num_images())+1]
   end if
@@ -743,7 +779,8 @@ subroutine char_test()
   str2a = 1_"zzzzzzzz"; str2b = 1_"zzzzzzzz"
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   ustr1a = 4_"abc"
-  str1a = 1_"XXXXXXX"
+  str2a = 1_"XXXXXXX"
+  sync all
   if (this_image() == num_images()) then
     str2a[1] = ustr1a
   end if
@@ -760,6 +797,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   str1a = 4_"abc"
   ustr2a = 1_"XXXXXXX"
+  sync all
   if (this_image() == num_images()) then
     ustr2a[1] = str1a
   end if
@@ -776,6 +814,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   ustr2a = 4_"abcde"
   str1a = 1_"XXX"
+  sync all
   if (this_image() == num_images()) then
     str1a[1] = ustr2a
   end if
@@ -792,6 +831,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   str2a = 4_"abcde"
   ustr1a = 1_"XXX"
+  sync all
   if (this_image() == num_images()) then
     ustr1a[1] = str2a
   end if
@@ -814,6 +854,7 @@ subroutine char_test()
   str2b(1) = 1_"XXXXXXX"
   str2b(2) = 1_"YYYYYYY"
   str2b(3) = 1_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     str2b(:)[1] = ustr1b
   end if
@@ -836,6 +877,7 @@ subroutine char_test()
   ustr2b(1) = 4_"XXXXXXX"
   ustr2b(2) = 4_"YYYYYYY"
   ustr2b(3) = 4_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr2b(:)[1] = str1b
   end if
@@ -858,6 +900,7 @@ subroutine char_test()
   str1b(1) = 1_"XXX"
   str1b(2) = 1_"YYY"
   str1b(3) = 1_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     str1b(:)[1] = ustr2b
   end if
@@ -880,6 +923,7 @@ subroutine char_test()
   ustr1b(1) = 4_"XXX"
   ustr1b(2) = 4_"YYY"
   ustr1b(3) = 4_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr1b(:)[1] = str2b
   end if
@@ -902,6 +946,7 @@ subroutine char_test()
   str2b(1) = 1_"XXXXXXX"
   str2b(2) = 1_"YYYYYYY"
   str2b(3) = 1_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     str2b(:)[1] = ustr1a
   end if
@@ -922,6 +967,7 @@ subroutine char_test()
   ustr2b(1) = 4_"XXXXXXX"
   ustr2b(2) = 4_"YYYYYYY"
   ustr2b(3) = 4_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr2b(:)[1] = str1a
   end if
@@ -942,6 +988,7 @@ subroutine char_test()
   str1b(1) = 1_"XXX"
   str1b(2) = 1_"YYY"
   str1b(3) = 1_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     str1b(:)[1] = ustr2a
   end if
@@ -962,6 +1009,7 @@ subroutine char_test()
   ustr1b(1) = 4_"XXX"
   ustr1b(2) = 4_"YYY"
   ustr1b(3) = 4_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr1b(:)[1] = str2a
   end if
@@ -984,6 +1032,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   ustr1a = 4_"abc"
   str2a = 1_"XXXXXXX"
+  sync all
   if (this_image() == num_images()) then
     str2a = ustr1a[1]
   end if
@@ -1000,6 +1049,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   str1a = 1_"abc"
   ustr2a = 4_"XXXXXXX"
+  sync all
   if (this_image() == num_images()) then
     ustr2a = str1a[1]
   end if
@@ -1016,6 +1066,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   ustr2a = 4_"abcde"
   str1a = 1_"XXX"
+  sync all
   if (this_image() == num_images()) then
     str1a = ustr2a[1]
   end if
@@ -1032,6 +1083,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   str2a = 1_"abcde"
   ustr1a = 4_"XXX"
+  sync all
   if (this_image() == num_images()) then
     ustr1a = str2a[1]
   end if
@@ -1054,6 +1106,7 @@ subroutine char_test()
   str2b(1) = 1_"XXXXXXX"
   str2b(2) = 1_"YYYYYYY"
   str2b(3) = 1_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     str2b = ustr1b(:)[1]
   end if
@@ -1076,6 +1129,7 @@ subroutine char_test()
   ustr2b(1) = 4_"XXXXXXX"
   ustr2b(2) = 4_"YYYYYYY"
   ustr2b(3) = 4_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr2b = str1b(:)[1]
   end if
@@ -1098,6 +1152,7 @@ subroutine char_test()
   str1b(1) = 1_"XXX"
   str1b(2) = 1_"YYY"
   str1b(3) = 1_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     str1b = ustr2b(:)[1]
   end if
@@ -1120,6 +1175,7 @@ subroutine char_test()
   ustr1b(1) = 4_"XXX"
   ustr1b(2) = 4_"YYY"
   ustr1b(3) = 4_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr1b = str2b(:)[1]
   end if
@@ -1142,6 +1198,7 @@ subroutine char_test()
   str2b(1) = 1_"XXXXXXX"
   str2b(2) = 1_"YYYYYYY"
   str2b(3) = 1_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     str2b = ustr1a[1]
   end if
@@ -1162,6 +1219,7 @@ subroutine char_test()
   ustr2b(1) = 4_"XXXXXXX"
   ustr2b(2) = 4_"YYYYYYY"
   ustr2b(3) = 4_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr2b = str1a[1]
   end if
@@ -1182,6 +1240,7 @@ subroutine char_test()
   str1b(1) = 1_"XXX"
   str1b(2) = 1_"YYY"
   str1b(3) = 1_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     str1b = ustr2a[1]
   end if
@@ -1202,6 +1261,7 @@ subroutine char_test()
   ustr1b(1) = 4_"XXX"
   ustr1b(2) = 4_"YYY"
   ustr1b(3) = 4_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr1b = str2a[1]
   end if
@@ -1225,6 +1285,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   ustr1a = 4_"abc"
   str2a = 1_"XXXXXXX"
+  sync all
   if (this_image() == num_images()) then
     str2a[1] = ustr1a[mod(1, num_images())+1]
   end if
@@ -1241,6 +1302,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   str1a = 1_"abc"
   ustr2a = 4_"XXXXXXX"
+  sync all
   if (this_image() == num_images()) then
     ustr2a[1] = str1a[mod(1, num_images())+1]
   end if
@@ -1257,6 +1319,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   ustr2a = 4_"abcde"
   str1a = 1_"XXX"
+  sync all
   if (this_image() == num_images()) then
     str1a[1] = ustr2a[mod(1, num_images())+1]
   end if
@@ -1273,6 +1336,7 @@ subroutine char_test()
   ustr2a = 4_"zzzzzzzz"; ustr2b = 4_"zzzzzzzz"
   str2a = 1_"abcde"
   ustr1a = 4_"XXX"
+  sync all
   if (this_image() == num_images()) then
     ustr1a[1] = str2a[mod(1, num_images())+1]
   end if
@@ -1295,6 +1359,7 @@ subroutine char_test()
   str2b(1) = 1_"XXXXXXX"
   str2b(2) = 1_"YYYYYYY"
   str2b(3) = 1_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     str2b(:)[1] = ustr1b(:)[mod(1, num_images())+1]
   end if
@@ -1317,6 +1382,7 @@ subroutine char_test()
   ustr2b(1) = 4_"XXXXXXX"
   ustr2b(2) = 4_"YYYYYYY"
   ustr2b(3) = 4_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr2b(:)[1] = str1b(:)[mod(1, num_images())+1]
   end if
@@ -1339,6 +1405,7 @@ subroutine char_test()
   str1b(1) = 1_"XXX"
   str1b(2) = 1_"YYY"
   str1b(3) = 1_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     str1b(:)[1] = ustr2b(:)[mod(1, num_images())+1]
   end if
@@ -1361,6 +1428,7 @@ subroutine char_test()
   ustr1b(1) = 4_"XXX"
   ustr1b(2) = 4_"YYY"
   ustr1b(3) = 4_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr1b(:)[1] = str2b(:)[mod(1, num_images())+1]
   end if
@@ -1383,6 +1451,7 @@ subroutine char_test()
   str2b(1) = 1_"XXXXXXX"
   str2b(2) = 1_"YYYYYYY"
   str2b(3) = 1_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     str2b(:)[1] = ustr1a[mod(1, num_images())+1]
   end if
@@ -1403,6 +1472,7 @@ subroutine char_test()
   ustr2b(1) = 4_"XXXXXXX"
   ustr2b(2) = 4_"YYYYYYY"
   ustr2b(3) = 4_"ZZZZZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr2b(:)[1] = str1a[mod(1, num_images())+1]
   end if
@@ -1423,6 +1493,7 @@ subroutine char_test()
   str1b(1) = 1_"XXX"
   str1b(2) = 1_"YYY"
   str1b(3) = 1_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     str1b(:)[1] = ustr2a[mod(1, num_images())+1]
   end if
@@ -1443,6 +1514,7 @@ subroutine char_test()
   ustr1b(1) = 4_"XXX"
   ustr1b(2) = 4_"YYY"
   ustr1b(3) = 4_"ZZZ"
+  sync all
   if (this_image() == num_images()) then
     ustr1b(:)[1] = str2a[mod(1, num_images())+1]
   end if
diff --git a/gcc/testsuite/gfortran.dg/coarray/coindexed_3.f08 
b/gcc/testsuite/gfortran.dg/coarray/coindexed_3.f08
index 7fd20851e0a..145835d461b 100644
--- a/gcc/testsuite/gfortran.dg/coarray/coindexed_3.f08
+++ b/gcc/testsuite/gfortran.dg/coarray/coindexed_3.f08
@@ -15,8 +15,8 @@ program pr98903
   a = 42
   s = 42
 
-  ! Checking against single image only.  Therefore team statements are
-  ! not viable nor are they (yet) supported by GFortran.
+  sync all
+  
   if (a[1, team_number=-1, stat=s] /= 42) stop 1
   if (s /= 0) stop 2
 
diff --git a/gcc/testsuite/gfortran.dg/coarray/coindexed_5.f90 
b/gcc/testsuite/gfortran.dg/coarray/coindexed_5.f90
index c35ec1093c1..8eb64669628 100644
--- a/gcc/testsuite/gfortran.dg/coarray/coindexed_5.f90
+++ b/gcc/testsuite/gfortran.dg/coarray/coindexed_5.f90
@@ -13,68 +13,72 @@ program coindexed_5
   parentteam = get_team()
 
   caf = [23, 32]
-  form team(t_num, team, new_index=1)
+  form team(t_num, team) !, new_index=num_images() - this_image() + 1)
   form team(t_num, formed_team)
 
   change team(team, cell[*] => caf(2))
-    ! for get_from_remote
-    ! Checking against caf_single is very limitted.
-    if (cell[1, team_number=t_num] /= 32) stop 1
-    if (cell[1, team_number=st_num] /= 32) stop 2
-    if (cell[1, team=parentteam] /= 32) stop 3
+    associate(me => this_image())
+      ! for get_from_remote
+      ! Checking against caf_single is very limitted.
+      if (cell[me, team_number=t_num] /= 32) stop 1
+      if (cell[me, team_number=st_num] /= 32) stop 2
+      if (cell[me, team=parentteam] /= 32) stop 3
 
-    ! Check that team_number is validated
-    lhs = cell[1, team_number=5, stat=stat]
-    if (stat /= 1) stop 4
+      ! Check that team_number is validated
+      lhs = cell[me, team_number=5, stat=stat]
+      if (stat /= 1) stop 4
 
-    ! Check that only access to active teams is valid
-    stat = 42
-    lhs = cell[1, team=formed_team, stat=stat]
-    if (stat /= 1) stop 5
+      ! Check that only access to active teams is valid
+      stat = 42
+      lhs = cell[me, team=formed_team, stat=stat]
+      if (stat /= 1) stop 5
 
-    ! for send_to_remote
-    ! Checking against caf_single is very limitted.
-    cell[1, team_number=t_num] = 45
-    if (cell /= 45) stop 11
-    cell[1, team_number=st_num] = 46
-    if (cell /= 46) stop 12
-    cell[1, team=parentteam] = 47
-    if (cell /= 47) stop 13
+      ! for send_to_remote
+      ! Checking against caf_single is very limitted.
+      cell[me, team_number=t_num] = 45
+      if (cell /= 45) stop 11
+      cell[me, team_number=st_num] = 46
+      if (cell /= 46) stop 12
+      cell[me, team=parentteam] = 47
+      if (cell /= 47) stop 13
 
-    ! Check that team_number is validated
-    stat = -1
-    cell[1, team_number=5, stat=stat] = 0
-    if (stat /= 1) stop 14
+      ! Check that team_number is validated
+      stat = -1
+      cell[me, team_number=5, stat=stat] = 0
+      if (stat /= 1) stop 14
 
-    ! Check that only access to active teams is valid
-    stat = 42
-    cell[1, team=formed_team, stat=stat] = -1
-    if (stat /= 1) stop 15
+      ! Check that only access to active teams is valid
+      stat = 42
+      cell[me, team=formed_team, stat=stat] = -1
+      if (stat /= 1) stop 15
 
-    ! for transfer_between_remotes
-    ! Checking against caf_single is very limitted.
-    cell[1, team_number=t_num] = caf(1)[1, team_number=-1]
-    if (cell /= 23) stop 21
-    cell[1, team_number=st_num] = caf(2)[1, team_number=-1]
-    ! cell is an alias for caf(2) and has been overwritten by caf(1)!
-    if (cell /= 23) stop 22
-    cell[1, team=parentteam] = caf(1)[1, team= team]
-    if (cell /= 23) stop 23
+      ! for transfer_between_remotes
+      ! Checking against caf_single is very limitted.
+      cell[me, team_number=t_num] = caf(1)[me, team_number=-1]
+      if (cell /= 23) stop 21
+      cell[me, team_number=st_num] = caf(2)[me, team_number=-1]
+      ! cell is an alias for caf(2) and has been overwritten by caf(1)!
+      if (cell /= 23) stop 22
+      cell[me, team=parentteam] = caf(1)[me, team= team]
+      if (cell /= 23) stop 23
 
-    ! Check that team_number is validated
-    stat = -1
-    cell[1, team_number=5, stat=stat] = caf(1)[1, team_number= -1]
-    if (stat /= 1) stop 24
-    stat = -1
-    cell[1, team_number=t_num] = caf(1)[1, team_number= -2, stat=stat]
-    if (stat /= 1) stop 25
+      ! Check that team_number is validated
+      stat = -1
+      cell[me, team_number=5, stat=stat] = caf(1)[me, team_number= -1]
+      if (stat /= 1) stop 24
+      stat = -1
+      cell[me, team_number=t_num] = caf(1)[me, team_number= -2, stat=stat]
+      if (stat /= 1) stop 25
 
-    ! Check that only access to active teams is valid
-    stat = 42
-    cell[1, team=formed_team, stat=stat] = caf(1)[1]
-    if (stat /= 1) stop 26
-    stat = 42
-    cell[1] = caf(1)[1, team=formed_team, stat=stat]
-    if (stat /= 1) stop 27
+      ! Check that only access to active teams is valid
+      stat = 42
+      cell[me, team=formed_team, stat=stat] = caf(1)[me]
+      if (stat /= 1) stop 26
+      stat = 42
+      cell[me] = caf(1)[me, team=formed_team, stat=stat]
+      if (stat /= 1) stop 27
+
+      sync all
+    end associate
   end team
 end program coindexed_5
diff --git a/gcc/testsuite/gfortran.dg/coarray/dummy_3.f90 
b/gcc/testsuite/gfortran.dg/coarray/dummy_3.f90
index 4b45daab649..c569390e7c6 100644
--- a/gcc/testsuite/gfortran.dg/coarray/dummy_3.f90
+++ b/gcc/testsuite/gfortran.dg/coarray/dummy_3.f90
@@ -15,6 +15,7 @@ program pr77871
    p%i = 42
    allocate (p2(5)[*])
    p2(:)%i = (/(i, i=0, 4)/)
+   sync all
    call s(p, 1)
    call s2(p2, 1)
 contains
diff --git a/gcc/testsuite/gfortran.dg/coarray/event_1.f90 
b/gcc/testsuite/gfortran.dg/coarray/event_1.f90
index 81dc90b7197..a9fecf93984 100644
--- a/gcc/testsuite/gfortran.dg/coarray/event_1.f90
+++ b/gcc/testsuite/gfortran.dg/coarray/event_1.f90
@@ -5,47 +5,54 @@
 use iso_fortran_env, only: event_type
 implicit none
 
-type(event_type), save :: var[*]
+type(event_type), save, allocatable, dimension(:) :: events[:]
 integer :: count, stat
 
-count = -42
-call event_query (var, count)
-if (count /= 0) STOP 1
-
-stat = 99
-event post (var, stat=stat)
-if (stat /= 0) STOP 2
-call event_query(var, count, stat=stat)
-if (count /= 1 .or. stat /= 0) STOP 3
-
-stat = 99
-event post (var[this_image()])
-call event_query(var, count)
-if (count /= 2) STOP 4
-
-stat = 99
-event wait (var)
-call event_query(var, count)
-if (count /= 1) STOP 5
-
-stat = 99
-event post (var)
-call event_query(var, count)
-if (count /= 2) STOP 6
-
-stat = 99
-event post (var)
-call event_query(var, count)
-if (count /= 3) STOP 7
-
-stat = 99
-event wait (var, until_count=2)
-call event_query(var, count)
-if (count /= 1) STOP 8
-
-stat = 99
-event wait (var, stat=stat, until_count=1)
-if (stat /= 0) STOP 9
-call event_query(event=var, stat=stat, count=count)
-if (count /= 0 .or. stat /= 0) STOP 10
+associate (me => this_image(), np => num_images())
+  allocate(events(np)[*])
+
+  associate(var => events(me))
+    count = -42
+    call event_query (var, count)
+    if (count /= 0) STOP 1
+
+    stat = 99
+    event post (var, stat=stat)
+    if (stat /= 0) STOP 2
+    call event_query(var, count, stat=stat)
+    if (count /= 1 .or. stat /= 0) STOP 3
+
+    count = 99
+    event post (var[this_image()])
+    call event_query(var, count)
+    if (count /= 2) STOP 4
+
+    count = 99
+    event wait (var)
+    call event_query(var, count)
+    if (count /= 1) STOP 5
+
+    count = 99
+    event post (var)
+    call event_query(var, count)
+    if (count /= 2) STOP 6
+
+    count = 99
+    event post (var)
+    call event_query(var, count)
+    if (count /= 3) STOP 7
+
+    count = 99
+    event wait (var, until_count=2)
+    call event_query(var, count)
+    if (count /= 1) STOP 8
+   
+    stat = 99
+    event wait (var, stat=stat, until_count=1)
+    if (stat /= 0) STOP 9
+    count = 99
+    call event_query(event=var, stat=stat, count=count)
+    if (count /= 0 .or. stat /= 0) STOP 10
+  end associate
+end associate
 end
diff --git a/gcc/testsuite/gfortran.dg/coarray/event_3.f08 
b/gcc/testsuite/gfortran.dg/coarray/event_3.f08
index 60d3193f776..cedf636b79b 100644
--- a/gcc/testsuite/gfortran.dg/coarray/event_3.f08
+++ b/gcc/testsuite/gfortran.dg/coarray/event_3.f08
@@ -11,8 +11,8 @@ program global_event
   contains
     subroutine exchange
       integer :: cnt
-      event post(x[1])
-      event post(x[1])
+      event post(x[this_image()])
+      event post(x[this_image()])
       call event_query(x, cnt)
       if (cnt /= 2) error stop 1
       event wait(x, until_count=2)
diff --git a/gcc/testsuite/gfortran.dg/coarray/event_4.f08 
b/gcc/testsuite/gfortran.dg/coarray/event_4.f08
index de901c01aa4..26a1f59df03 100644
--- a/gcc/testsuite/gfortran.dg/coarray/event_4.f08
+++ b/gcc/testsuite/gfortran.dg/coarray/event_4.f08
@@ -8,5 +8,6 @@ program event_4
   type(event_type) done[*]
   nc(1) = 1
   event post(done[1])
-  event wait(done,until_count=nc(1))
+  if (this_image() == 1) event wait(done,until_count=nc(1))
+  sync all
 end
diff --git a/gcc/testsuite/gfortran.dg/coarray/failed_images_1.f08 
b/gcc/testsuite/gfortran.dg/coarray/failed_images_1.f08
index 4898dd8a7a2..34ae131d15f 100644
--- a/gcc/testsuite/gfortran.dg/coarray/failed_images_1.f08
+++ b/gcc/testsuite/gfortran.dg/coarray/failed_images_1.f08
@@ -8,7 +8,7 @@ program test_failed_images_1
   integer :: i
 
   fi = failed_images()         ! OK
-  fi = failed_images(TEAM=1)   ! { dg-error "'team' argument of 
'failed_images' intrinsic at \\\\(1\\\\) not yet supported" }
+  fi = failed_images(TEAM=1)   ! { dg-error "'team' argument of 
'failed_images' intrinsic at \\\\(1\\\\) shall be of type 'team_type' from the 
intrinsic module 'ISO_FORTRAN_ENV'" }
   fi = failed_images(KIND=1)   ! OK
   fi = failed_images(KIND=4)   ! OK
   fi = failed_images(KIND=0)   ! { dg-error "'kind' argument of 
'failed_images' intrinsic at \\\\\\(1\\\\\\) must be positive" }
diff --git a/gcc/testsuite/gfortran.dg/coarray/failed_images_2.f08 
b/gcc/testsuite/gfortran.dg/coarray/failed_images_2.f08
index ca5fe4020d5..78d92daf071 100644
--- a/gcc/testsuite/gfortran.dg/coarray/failed_images_2.f08
+++ b/gcc/testsuite/gfortran.dg/coarray/failed_images_2.f08
@@ -1,17 +1,44 @@
 ! { dg-do run }
 
 program test_failed_images_2
+  use iso_fortran_env
   implicit none
 
+  type(team_type) :: t
   integer, allocatable :: fi(:)
   integer(kind=1), allocatable :: sfi(:)
+  integer, allocatable :: rem_images(:)
+  integer :: i, st
 
-  fi = failed_images()
-  if (size(fi) > 0) error stop "failed_images result shall be empty array"
-  sfi = failed_images(KIND=1)
-  if (size(sfi) > 0) error stop "failed_images result shall be empty array"
-  sfi = failed_images(KIND=8)
-  if (size(sfi) > 0) error stop "failed_images result shall be empty array"
+  associate(np => num_images())
+    form team (1, t)
+    fi = failed_images()
+    if (size(fi) > 0) stop 1
+    sfi = failed_images(KIND=1)
+    if (size(sfi) > 0) stop 2
+    sfi = failed_images(KIND=8)
+    if (size(sfi) > 0) stop 3
+    
+    fi = failed_images(t)
+    if (size(fi) > 0) stop 4
   
+    if (num_images() > 1) then
+      sync all
+      if (this_image() == 2) fail image
+      rem_images = (/ 1, ( i, i = 3, np )/)
+      ! Can't synchronize well on a failed image.  Try with a sleep.
+      do i = 0, 10
+        if (size(failed_images()) == 0) then
+          call sleep(1)
+        else
+          exit
+        end if
+      end do
+      if (i == 10 .AND. size(failed_images()) == 0) stop 5
+      sync images (rem_images, stat=st)
+      if (any(failed_images() /= [2])) stop 6
+      if (any(failed_images(t, 8) /= [2])) stop 7
+    end if
+  end associate
 end program test_failed_images_2
 
diff --git a/gcc/testsuite/gfortran.dg/coarray/image_status_1.f08 
b/gcc/testsuite/gfortran.dg/coarray/image_status_1.f08
index b7ec5a6a9c9..f725f81d4aa 100644
--- a/gcc/testsuite/gfortran.dg/coarray/image_status_1.f08
+++ b/gcc/testsuite/gfortran.dg/coarray/image_status_1.f08
@@ -18,7 +18,7 @@ program test_image_status_1
   isv = image_status(k2) ! Ok
   isv = image_status(k4) ! Ok
   isv = image_status(k8) ! Ok
-  isv = image_status(1, team=1) ! { dg-error "shall be of type 'team_type'" }
+  isv = image_status(1, team=1) ! { dg-error "'team' argument of 
'image_status' intrinsic at \\\\(1\\\\) shall be of type 'team_type'" }
   isv = image_status()          ! { dg-error "Missing actual argument 'image' 
in call to 'image_status' at \\\\(1\\\\)" }
   isv = image_status(team=1)    ! { dg-error "Missing actual argument 'image' 
in call to 'image_status' at \\\\(1\\\\)" }
 
diff --git a/gcc/testsuite/gfortran.dg/coarray/image_status_2.f08 
b/gcc/testsuite/gfortran.dg/coarray/image_status_2.f08
index fb49289cb78..8866f237481 100644
--- a/gcc/testsuite/gfortran.dg/coarray/image_status_2.f08
+++ b/gcc/testsuite/gfortran.dg/coarray/image_status_2.f08
@@ -1,12 +1,38 @@
 ! { dg-do run }
 
 program test_image_status_2
-  use iso_fortran_env , only : STAT_STOPPED_IMAGE
+  use iso_fortran_env
   implicit none
 
+  type(team_type) :: t
+  integer :: i, st
+  integer, allocatable :: rem_images(:)
+
+  form team (1, t)
+
   if (image_status(1) /= 0) error stop "Image 1 should report OK."
-  if (image_status(2) /= STAT_STOPPED_IMAGE) error stop "Image 2 should be 
stopped."
-  if (image_status(3) /= STAT_STOPPED_IMAGE) error stop "Image 3 should be 
stopped."
+  if (image_status(num_images() + 1) /= STAT_STOPPED_IMAGE) error stop "Image 
should be stopped."
+
+  if (image_status(1, t) /= 0) error stop "Image 1 in team t should report OK."
+
+  if (num_images() > 1) then
+    associate (np => num_images())
+      sync all
+      if (this_image() == 2) fail image 
+      rem_images = (/ 1, ( i, i = 3, np )/)
+      ! Can't synchronize well on failed image.  Try with a sleep.
+      do i = 0, 10
+        if (image_status(2) /= STAT_FAILED_IMAGE) then
+          call sleep(1)
+        else
+          exit
+        end if
+      end do
+      sync images (rem_images, stat=st)
+      if (image_status(2) /= STAT_FAILED_IMAGE) error stop "Image 2 has NOT 
status failed."
+      if (image_status(2, t) /= STAT_FAILED_IMAGE) error stop "Image 2 has NOT 
status failed."
+    end associate
+  end if
 
 end program test_image_status_2
 
diff --git a/gcc/testsuite/gfortran.dg/coarray/lock_2.f90 
b/gcc/testsuite/gfortran.dg/coarray/lock_2.f90
index 8e96154996d..3d445b9b5e8 100644
--- a/gcc/testsuite/gfortran.dg/coarray/lock_2.f90
+++ b/gcc/testsuite/gfortran.dg/coarray/lock_2.f90
@@ -58,6 +58,8 @@ if (stat /= 0) STOP 9
 UNLOCK(lock3(4), stat=stat)
 if (stat /= 0) STOP 10
 
+! Ensure all other (/=1) images have released the locks.
+sync all
 if (this_image() == 1) then
   acquired = .false.
   LOCK (lock1[this_image()], acquired_lock=acquired)
diff --git a/gcc/testsuite/gfortran.dg/coarray/poly_run_3.f90 
b/gcc/testsuite/gfortran.dg/coarray/poly_run_3.f90
index c284a566760..4da1b9569fe 100644
--- a/gcc/testsuite/gfortran.dg/coarray/poly_run_3.f90
+++ b/gcc/testsuite/gfortran.dg/coarray/poly_run_3.f90
@@ -12,28 +12,28 @@ allocate(a(1)[*])
 if (this_image() == 1 .and. any (this_image(a) /= lcobound(a))) &
   STOP 1
 if (any (lcobound(a) /= 1)) STOP 2
-if (any (ucobound(a) /= this_image())) STOP 3
+if (any (ucobound(a) /= num_images())) STOP 3
 deallocate(a)
 
 allocate(b[*])
 if (this_image() == 1 .and. any (this_image(b) /= lcobound(b))) &
   STOP 4
 if (any (lcobound(b) /= 1)) STOP 5
-if (any (ucobound(b) /= this_image())) STOP 6
+if (any (ucobound(b) /= num_images())) STOP 6
 deallocate(b)
 
 allocate(a(1)[-10:*])
 if (this_image() == 1 .and. any (this_image(a) /= lcobound(a))) &
   STOP 7
 if (any (lcobound(a) /= -10)) STOP 8
-if (any (ucobound(a) /= -11+this_image())) STOP 9
+if (any (ucobound(a) /= -11 + num_images())) STOP 9
 deallocate(a)
 
 allocate(d[23:*])
 if (this_image() == 1 .and. any (this_image(d) /= lcobound(d))) &
   STOP 10
 if (any (lcobound(d) /= 23)) STOP 11
-if (any (ucobound(d) /= 22+this_image())) STOP 12
+if (any (ucobound(d) /= 22 + num_images())) STOP 12
 deallocate(d)
 
 end
diff --git a/gcc/testsuite/gfortran.dg/coarray/scalar_alloc_1.f90 
b/gcc/testsuite/gfortran.dg/coarray/scalar_alloc_1.f90
index b0d27bdfb8f..8dd7df5d436 100644
--- a/gcc/testsuite/gfortran.dg/coarray/scalar_alloc_1.f90
+++ b/gcc/testsuite/gfortran.dg/coarray/scalar_alloc_1.f90
@@ -19,7 +19,7 @@ if (lcobound(a, dim=1) /= 1 .or. ucobound(a,dim=1) /= 
num_images()) &
 deallocate(a)
 
 allocate(a[4:*])
-a[this_image ()] = 8 - 2*this_image ()
+a[this_image () + 3] = 8 - 2*this_image ()
 
 if (lcobound(a, dim=1) /= 4 .or. ucobound(a,dim=1) /= 3 + num_images()) &
   STOP 4
@@ -30,6 +30,7 @@ n3 = 3
 allocate (B[n1:n2, n3:*])
 if (any (lcobound(b) /= [-1, 3]) .or. lcobound(B, dim=2) /= n3) &
   STOP 5
+sync all
 call sub(A, B)
 
 if (allocated (a)) STOP 6
@@ -47,7 +48,8 @@ contains
       STOP 8
     if (lcobound(x, dim=1) /= 4 .or. ucobound(x,dim=1) /= 3 + num_images()) &
       STOP 9
-    if (x[this_image ()] /= 8 - 2*this_image ()) STOP 3
+    if (x[this_image () + 3] /= 8 - 2*this_image ()) STOP 10
+    sync all
     deallocate(x)
   end subroutine sub
 
@@ -56,12 +58,13 @@ contains
     integer, allocatable, SAVE :: a[:]
 
     if (init) then
-      if (allocated(a)) STOP 10
+      if (allocated(a)) STOP 11
       allocate(a[*])
       a = 45
    else
-      if (.not. allocated(a)) STOP 11
-      if (a /= 45) STOP 12
+      if (.not. allocated(a)) STOP 12
+      if (a /= 45) STOP 13
+      sync all
       deallocate(a)
     end if
   end subroutine two
diff --git a/gcc/testsuite/gfortran.dg/coarray/stopped_images_1.f08 
b/gcc/testsuite/gfortran.dg/coarray/stopped_images_1.f08
index 403de585b9a..7658e6bb6bb 100644
--- a/gcc/testsuite/gfortran.dg/coarray/stopped_images_1.f08
+++ b/gcc/testsuite/gfortran.dg/coarray/stopped_images_1.f08
@@ -8,7 +8,7 @@ program test_stopped_images_1
   integer :: i
 
   gi = stopped_images()         ! OK
-  gi = stopped_images(TEAM=1)   ! { dg-error "'team' argument of 
'stopped_images' intrinsic at \\\\(1\\\\) not yet supported" }
+  gi = stopped_images(TEAM=1)   ! { dg-error "'team' argument of 
'stopped_images' intrinsic at \\\\(1\\\\) shall be of type 'team_type' from the 
intrinsic module 'ISO_FORTRAN_ENV'" }
   gi = stopped_images(KIND=1)   ! OK
   gi = stopped_images(KIND=4)   ! OK
   gi = stopped_images(KIND=0)   ! { dg-error "'kind' argument of 
'stopped_images' intrinsic at \\\\\\(1\\\\\\) must be positive" }
diff --git a/gcc/testsuite/gfortran.dg/coarray/stopped_images_2.f08 
b/gcc/testsuite/gfortran.dg/coarray/stopped_images_2.f08
index 0bf4a81a7e2..585d5e99c58 100644
--- a/gcc/testsuite/gfortran.dg/coarray/stopped_images_2.f08
+++ b/gcc/testsuite/gfortran.dg/coarray/stopped_images_2.f08
@@ -1,17 +1,45 @@
 ! { dg-do run }
+! { dg-options "-fcoarray=lib -lcaf_shmem"
 
 program test_stopped_images_2
+  use iso_fortran_env
   implicit none
 
+  type(team_type) :: t
   integer, allocatable :: si(:)
   integer(kind=1), allocatable :: ssi(:)
+  integer, allocatable :: rem_images(:)
+  integer :: i, st
 
-  si = stopped_images()
-  if (size(si) > 0) error stop "stopped_images result shall be empty array"
-  ssi = stopped_images(KIND=1)
-  if (size(ssi) > 0) error stop "stopped_images result shall be empty array"
-  ssi = stopped_images(KIND=8)
-  if (size(ssi) > 0) error stop "stopped_images result shall be empty array"
+  associate(np => num_images())
+    form team (1, t)
+    si = stopped_images()
+    if (size(si) > 0) stop 1
+    ssi = stopped_images(KIND=1)
+    if (size(ssi) > 0) stop 2
+    ssi = stopped_images(KIND=8)
+    if (size(ssi) > 0) stop 3
+    
+    si = stopped_images(t)  
+    if (size(si) > 0) stop 4
   
+    if (num_images() > 1) then
+      sync all
+      if (this_image() == 2) stop
+      rem_images = (/ 1, ( i, i = 3, np )/)
+      ! Can't synchronize well on a stopped image.  Try with a sleep.
+      do i = 0, 10
+        if (size(stopped_images()) == 0) then
+          call sleep(1)
+        else
+          exit
+        end if
+      end do
+      if (i == 10 .AND. size(stopped_images()) == 0) stop 5
+      sync images (rem_images, stat=st)
+      if (any(stopped_images() /= [2])) stop 6
+      if (any(stopped_images(t, 8) /= [2])) stop 7
+    end if
+  end associate
 end program test_stopped_images_2
 
diff --git a/gcc/testsuite/gfortran.dg/coarray/sync_1.f90 
b/gcc/testsuite/gfortran.dg/coarray/sync_1.f90
index 8633c4aa527..4abe5a3b548 100644
--- a/gcc/testsuite/gfortran.dg/coarray/sync_1.f90
+++ b/gcc/testsuite/gfortran.dg/coarray/sync_1.f90
@@ -26,7 +26,6 @@ n = 5
 sync all (stat=n,errmsg=str)
 if (n /= 0) STOP 2
 
-
 !
 ! Test SYNC MEMORY
 !
@@ -42,17 +41,21 @@ n = 5
 sync memory (errmsg=str,stat=n)
 if (n /= 0) STOP 4
 
-
 !
 ! Test SYNC IMAGES
 !
 sync images (*)
+
 if (this_image() == 1) then
     sync images (1)
     sync images (1, errmsg=str)
     sync images ([1])
 end if
 
+! Need to sync all here, because otherwise sync image 1 may overlap with the
+! sync images(*, stat=n) below and that may hang for num_images() > 1.
+sync all
+
 n = 5
 sync images (*, stat=n)
 if (n /= 0) STOP 5
@@ -61,4 +64,5 @@ n = 5
 sync images (*,errmsg=str,stat=n)
 if (n /= 0) STOP 6
 
+sync all
 end
diff --git a/gcc/testsuite/gfortran.dg/coarray/sync_3.f90 
b/gcc/testsuite/gfortran.dg/coarray/sync_3.f90
index fe1e4c548c8..ceb4b19d517 100644
--- a/gcc/testsuite/gfortran.dg/coarray/sync_3.f90
+++ b/gcc/testsuite/gfortran.dg/coarray/sync_3.f90
@@ -9,8 +9,9 @@
 ! PR fortran/18918
 
 implicit none
-integer :: n
-character(len=30) :: str
+integer :: n, st
+integer,allocatable :: others(:)
+character(len=40) :: str
 critical
 end critical
 myCr: critical
@@ -58,17 +59,32 @@ if (this_image() == 1) then
     sync images ([1])
 end if
 
+! Need to sync all here, because otherwise sync image 1 may overlap with the
+! sync images(*, stat=n) below and that may hang for num_images() > 1.
+sync all
+
 n = 5
 sync images (*, stat=n)
 if (n /= 0) STOP 5
 
 n = 5
-sync images (*,errmsg=str,stat=n)
+sync images (*, errmsg=str, stat=n)
 if (n /= 0) STOP 6
 
+if (this_image() == num_images()) then
+  others = (/( n, n=1, (num_images() - 1)) /)
+  sync images(others)
+else
+  sync images ( num_images() )
+end if 
+
 n = -1
-sync images ( num_images() )
-sync images (n) ! Invalid: "-1"
+st = 0
+sync images (n, errmsg=str, stat=st)
+if (st /= 1 .OR. str /= "Invalid image number -1 in SYNC IMAGES") STOP 7
+
+! Do this only on image 1, or output of error messages will clutter
+if (this_image() == 1) sync images (n) ! Invalid: "-1"
 
 end
 
diff --git a/gcc/testsuite/gfortran.dg/coarray_sync_memory.f90 
b/gcc/testsuite/gfortran.dg/coarray_sync_memory.f90
index c4e660b8cf7..0030d91257d 100644
--- a/gcc/testsuite/gfortran.dg/coarray_sync_memory.f90
+++ b/gcc/testsuite/gfortran.dg/coarray_sync_memory.f90
@@ -14,5 +14,5 @@ end
 
 ! { dg-final { scan-tree-dump-times "_gfortran_caf_sync_memory \\\\(0B, 0B, 
0\\\\);" 1 "original" } }
 ! { dg-final { scan-tree-dump-times "_gfortran_caf_sync_memory \\\\(&stat, 0B, 
0\\\\);" 1 "original" } }
-! { dg-final { scan-tree-dump-times "_gfortran_caf_sync_memory \\\\(0B, &&msg, 
42\\\\);" 1 "original" } }
-! { dg-final { scan-tree-dump-times "_gfortran_caf_sync_memory \\\\(&stat, 
&&msg, 42\\\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_sync_memory \\\\(0B, &msg, 
42\\\\);" 1 "original" } }
+! { dg-final { scan-tree-dump-times "_gfortran_caf_sync_memory \\\\(&stat, 
&msg, 42\\\\);" 1 "original" } }
diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am
index 46e7df5e728..c5c0fa5717c 100644
--- a/libgfortran/Makefile.am
+++ b/libgfortran/Makefile.am
@@ -58,13 +58,30 @@ libgfortran_la_LDFLAGS = -version-info \`grep -v '^\\#' 
\$(srcdir)/libtool-version\`
        \$(version_arg) -Wc,-shared-libgcc
 libgfortran_la_DEPENDENCIES = \$(version_dep) libgfortran.spec 
\$(LIBQUADLIB_DEP)
 
-cafexeclib_LTLIBRARIES = libcaf_single.la
+libcaf_shared_DEPS = caf/libcaf.h caf/caf_error.h
+libcaf_shared_SRCS = caf/caf_error.c
+
+cafexeclib_LTLIBRARIES = libcaf_single.la libcaf_shmem.la
 cafexeclibdir = \$(libdir)/gcc/\$(target_alias)/\$(gcc_version)\$(MULTISUBDIR)
-libcaf_single_la_SOURCES = caf/single.c
+libcaf_single_la_SOURCES = caf/single.c \$(libcaf_shared_SRCS)
 libcaf_single_la_LDFLAGS = -static
-libcaf_single_la_DEPENDENCIES = caf/libcaf.h
+libcaf_single_la_DEPENDENCIES = \$(libcaf_shared_DEPS)
 libcaf_single_la_LINK = \$(LINK) \$(libcaf_single_la_LDFLAGS)
 
+libcaf_shmem_la_SOURCES = \$(libcaf_shared_SRCS) \\
+       caf/shmem.c caf/shmem/alloc.c caf/shmem/allocator.c \\
+       caf/shmem/collective_subroutine.c caf/shmem/counter_barrier.c \\
+       caf/shmem/hashmap.c caf/shmem/shared_memory.c caf/shmem/supervisor.c \\
+       caf/shmem/sync.c caf/shmem/teams_mgmt.c caf/shmem/thread_support.c
+
+libcaf_shmem_la_LDFLAGS = -static
+libcaf_shmem_la_DEPENDENCIES = \$(libcaf_shared_DEPS) caf/shmem/alloc.h \\
+       caf/shmem/allocator.h caf/shmem/collective_subroutine.h \\
+       caf/shmem/counter_barrier.h caf/shmem/hashmap.h \\
+       caf/shmem/shared_memory.h caf/shmem/supervisor.h caf/shmem/sync.h \\
+       caf/shmem/teams_mgmt.h caf/shmem/thread_support.h
+libcaf_shmem_la_LINK = \$(LINK) \$(libcaf_shmem_la_LDFLAGS)
+
 if IEEE_SUPPORT
 fincludedir = 
\$(libdir)/gcc/\$(target_alias)/\$(gcc_version)\$(MULTISUBDIR)/finclude
 nodist_finclude_HEADERS = ieee_arithmetic.mod ieee_exceptions.mod 
ieee_features.mod
diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in
index 63c880cddcb..fe9a6ff7a42 100644
--- a/libgfortran/Makefile.in
+++ b/libgfortran/Makefile.in
@@ -219,21 +219,31 @@ am__installdirs = "\$(DESTDIR)\$(cafexeclibdir)" \\
        "\$(DESTDIR)\$(toolexeclibdir)" "\$(DESTDIR)\$(toolexeclibdir)" \\
        "\$(DESTDIR)\$(gfor_cdir)" "\$(DESTDIR)\$(fincludedir)"
 LTLIBRARIES = \$(cafexeclib_LTLIBRARIES) \$(toolexeclib_LTLIBRARIES)
-libcaf_single_la_LIBADD =
+libcaf_shmem_la_LIBADD =
 am__dirstamp = \$(am__leading_dot)dirstamp
-am_libcaf_single_la_OBJECTS = caf/single.lo
+am__objects_1 = caf/caf_error.lo
+am_libcaf_shmem_la_OBJECTS = \$(am__objects_1) caf/shmem.lo \\
+       caf/shmem/alloc.lo caf/shmem/allocator.lo \\
+       caf/shmem/collective_subroutine.lo \\
+       caf/shmem/counter_barrier.lo caf/shmem/hashmap.lo \\
+       caf/shmem/shared_memory.lo caf/shmem/supervisor.lo \\
+       caf/shmem/sync.lo caf/shmem/teams_mgmt.lo \\
+       caf/shmem/thread_support.lo
+libcaf_shmem_la_OBJECTS = \$(am_libcaf_shmem_la_OBJECTS)
+libcaf_single_la_LIBADD =
+am_libcaf_single_la_OBJECTS = caf/single.lo \$(am__objects_1)
 libcaf_single_la_OBJECTS = \$(am_libcaf_single_la_OBJECTS)
 libgfortran_la_LIBADD =
-@LIBGFOR_MINIMAL_TRUE@am__objects_1 = runtime/minimal.lo
-@LIBGFOR_MINIMAL_FALSE@am__objects_2 = runtime/backtrace.lo \\
+@LIBGFOR_MINIMAL_TRUE@am__objects_2 = runtime/minimal.lo
+@LIBGFOR_MINIMAL_FALSE@am__objects_3 = runtime/backtrace.lo \\
 @LIBGFOR_MINIMAL_FALSE@        runtime/convert_char.lo \\
 @LIBGFOR_MINIMAL_FALSE@        runtime/environ.lo runtime/error.lo \\
 @LIBGFOR_MINIMAL_FALSE@        runtime/fpu.lo runtime/main.lo \\
 @LIBGFOR_MINIMAL_FALSE@        runtime/pause.lo runtime/stop.lo
-am__objects_3 = runtime/bounds.lo runtime/compile_options.lo \\
+am__objects_4 = runtime/bounds.lo runtime/compile_options.lo \\
        runtime/deep_copy.lo runtime/memory.lo runtime/string.lo \\
-       runtime/select.lo \$(am__objects_1) \$(am__objects_2)
-am__objects_4 = generated/matmul_i1.lo generated/matmul_i2.lo \\
+       runtime/select.lo \$(am__objects_2) \$(am__objects_3)
+am__objects_5 = generated/matmul_i1.lo generated/matmul_i2.lo \\
        generated/matmul_i4.lo generated/matmul_i8.lo \\
        generated/matmul_i16.lo generated/matmul_r4.lo \\
        generated/matmul_r8.lo generated/matmul_r10.lo \\
@@ -241,9 +251,9 @@ am__objects_4 = generated/matmul_i1.lo 
generated/matmul_i2.lo \\
        generated/matmul_c4.lo generated/matmul_c8.lo \\
        generated/matmul_c10.lo generated/matmul_c16.lo \\
        generated/matmul_c17.lo
-am__objects_5 = generated/matmul_l4.lo generated/matmul_l8.lo \\
+am__objects_6 = generated/matmul_l4.lo generated/matmul_l8.lo \\
        generated/matmul_l16.lo
-am__objects_6 = generated/matmulavx128_i1.lo \\
+am__objects_7 = generated/matmulavx128_i1.lo \\
        generated/matmulavx128_i2.lo generated/matmulavx128_i4.lo \\
        generated/matmulavx128_i8.lo generated/matmulavx128_i16.lo \\
        generated/matmulavx128_r4.lo generated/matmulavx128_r8.lo \\
@@ -251,7 +261,7 @@ am__objects_6 = generated/matmulavx128_i1.lo \\
        generated/matmulavx128_r17.lo generated/matmulavx128_c4.lo \\
        generated/matmulavx128_c8.lo generated/matmulavx128_c10.lo \\
        generated/matmulavx128_c16.lo generated/matmulavx128_c17.lo
-am__objects_7 = generated/all_l1.lo generated/all_l2.lo \\
+am__objects_8 = generated/all_l1.lo generated/all_l2.lo \\
        generated/all_l4.lo generated/all_l8.lo generated/all_l16.lo \\
        generated/any_l1.lo generated/any_l2.lo generated/any_l4.lo \\
        generated/any_l8.lo generated/any_l16.lo \\
@@ -540,17 +550,17 @@ am__objects_7 = generated/all_l1.lo generated/all_l2.lo \\
        generated/pow_m8_m16.lo generated/pow_m16_m1.lo \\
        generated/pow_m16_m2.lo generated/pow_m16_m4.lo \\
        generated/pow_m16_m8.lo generated/pow_m16_m16.lo \\
-       \$(am__objects_4) \$(am__objects_5) \$(am__objects_6) \\
+       \$(am__objects_5) \$(am__objects_6) \$(am__objects_7) \\
        runtime/ISO_Fortran_binding.lo
-@LIBGFOR_MINIMAL_FALSE@am__objects_8 = io/close.lo io/file_pos.lo \\
+@LIBGFOR_MINIMAL_FALSE@am__objects_9 = io/close.lo io/file_pos.lo \\
 @LIBGFOR_MINIMAL_FALSE@        io/format.lo io/inquire.lo \\
 @LIBGFOR_MINIMAL_FALSE@        io/intrinsics.lo io/list_read.lo \\
 @LIBGFOR_MINIMAL_FALSE@        io/lock.lo io/open.lo io/read.lo \\
 @LIBGFOR_MINIMAL_FALSE@        io/transfer.lo io/transfer128.lo \\
 @LIBGFOR_MINIMAL_FALSE@        io/unit.lo io/unix.lo io/write.lo \\
 @LIBGFOR_MINIMAL_FALSE@        io/fbuf.lo io/async.lo
-am__objects_9 = io/size_from_kind.lo \$(am__objects_8)
-@LIBGFOR_MINIMAL_FALSE@am__objects_10 = intrinsics/access.lo \\
+am__objects_10 = io/size_from_kind.lo \$(am__objects_9)
+@LIBGFOR_MINIMAL_FALSE@am__objects_11 = intrinsics/access.lo \\
 @LIBGFOR_MINIMAL_FALSE@        intrinsics/c99_functions.lo \\
 @LIBGFOR_MINIMAL_FALSE@        intrinsics/chdir.lo intrinsics/chmod.lo \\
 @LIBGFOR_MINIMAL_FALSE@        intrinsics/clock.lo \\
@@ -574,8 +584,8 @@ am__objects_9 = io/size_from_kind.lo \$(am__objects_8)
 @LIBGFOR_MINIMAL_FALSE@        intrinsics/system_clock.lo \\
 @LIBGFOR_MINIMAL_FALSE@        intrinsics/time.lo intrinsics/umask.lo \\
 @LIBGFOR_MINIMAL_FALSE@        intrinsics/unlink.lo
-@IEEE_SUPPORT_TRUE@am__objects_11 = ieee/ieee_helper.lo
-am__objects_12 = intrinsics/associated.lo intrinsics/abort.lo \\
+@IEEE_SUPPORT_TRUE@am__objects_12 = ieee/ieee_helper.lo
+am__objects_13 = intrinsics/associated.lo intrinsics/abort.lo \\
        intrinsics/args.lo intrinsics/cshift0.lo \\
        intrinsics/eoshift0.lo intrinsics/eoshift2.lo \\
        intrinsics/erfc_scaled.lo intrinsics/extends_type_of.lo \\
@@ -590,12 +600,12 @@ am__objects_12 = intrinsics/associated.lo 
intrinsics/abort.lo \\
        intrinsics/selected_real_kind.lo intrinsics/trigd.lo \\
        intrinsics/unpack_generic.lo runtime/in_pack_generic.lo \\
        runtime/in_unpack_generic.lo runtime/in_pack_class.lo \\
-       runtime/in_unpack_class.lo \$(am__objects_10) \$(am__objects_11)
-@IEEE_SUPPORT_TRUE@am__objects_13 = ieee/ieee_arithmetic.lo \\
+       runtime/in_unpack_class.lo \$(am__objects_11) \$(am__objects_12)
+@IEEE_SUPPORT_TRUE@am__objects_14 = ieee/ieee_arithmetic.lo \\
 @IEEE_SUPPORT_TRUE@    ieee/ieee_exceptions.lo \\
 @IEEE_SUPPORT_TRUE@    ieee/ieee_features.lo
-am__objects_14 =
-am__objects_15 = generated/_abs_c4.lo generated/_abs_c8.lo \\
+am__objects_15 =
+am__objects_16 = generated/_abs_c4.lo generated/_abs_c8.lo \\
        generated/_abs_c10.lo generated/_abs_c16.lo \\
        generated/_abs_c17.lo generated/_abs_i4.lo \\
        generated/_abs_i8.lo generated/_abs_i16.lo \\
@@ -681,9 +691,9 @@ am__objects_15 = generated/_abs_c4.lo generated/_abs_c8.lo 
\\
        generated/_mod_r17.lo generated/misc_specifics.lo \\
        intrinsics/dprod_r8.lo intrinsics/f2c_specifics.lo \\
        intrinsics/random_init.lo
-am_libgfortran_la_OBJECTS = \$(am__objects_3) \$(am__objects_7) \\
-       \$(am__objects_9) \$(am__objects_12) \$(am__objects_13) \\
-       \$(am__objects_14) \$(am__objects_15)
+am_libgfortran_la_OBJECTS = \$(am__objects_4) \$(am__objects_8) \\
+       \$(am__objects_10) \$(am__objects_13) \$(am__objects_14) \\
+       \$(am__objects_15) \$(am__objects_16)
 libgfortran_la_OBJECTS = \$(am_libgfortran_la_OBJECTS)
 AM_V_P = \$(am__v_P_@AM_V@)
 am__v_P_ = \$(am__v_P_@AM_DEFAULT_V@)
@@ -748,7 +758,8 @@ AM_V_FC = \$(am__v_FC_@AM_V@)
 am__v_FC_ = \$(am__v_FC_@AM_DEFAULT_V@)
 am__v_FC_0 = @echo "  FC      " \$@;
 am__v_FC_1 = 
-SOURCES = \$(libcaf_single_la_SOURCES) \$(libgfortran_la_SOURCES)
+SOURCES = \$(libcaf_shmem_la_SOURCES) \$(libcaf_single_la_SOURCES) \\
+       \$(libgfortran_la_SOURCES)
 am__can_run_installinfo = \\
   case \$\$AM_UPDATE_INFO_DIR in \\
     n|no|NO) false;; \\
@@ -965,12 +976,28 @@ libgfortran_la_LDFLAGS = -version-info \`grep -v '^\\#' 
\$(srcdir)/libtool-version\`
        \$(version_arg) -Wc,-shared-libgcc
 
 libgfortran_la_DEPENDENCIES = \$(version_dep) libgfortran.spec 
\$(LIBQUADLIB_DEP)
-cafexeclib_LTLIBRARIES = libcaf_single.la
+libcaf_shared_DEPS = caf/libcaf.h caf/caf_error.h
+libcaf_shared_SRCS = caf/caf_error.c
+cafexeclib_LTLIBRARIES = libcaf_single.la libcaf_shmem.la
 cafexeclibdir = \$(libdir)/gcc/\$(target_alias)/\$(gcc_version)\$(MULTISUBDIR)
-libcaf_single_la_SOURCES = caf/single.c
+libcaf_single_la_SOURCES = caf/single.c \$(libcaf_shared_SRCS)
 libcaf_single_la_LDFLAGS = -static
-libcaf_single_la_DEPENDENCIES = caf/libcaf.h
+libcaf_single_la_DEPENDENCIES = \$(libcaf_shared_DEPS)
 libcaf_single_la_LINK = \$(LINK) \$(libcaf_single_la_LDFLAGS)
+libcaf_shmem_la_SOURCES = \$(libcaf_shared_SRCS) \\
+       caf/shmem.c caf/shmem/alloc.c caf/shmem/allocator.c \\
+       caf/shmem/collective_subroutine.c caf/shmem/counter_barrier.c \\
+       caf/shmem/hashmap.c caf/shmem/shared_memory.c caf/shmem/supervisor.c \\
+       caf/shmem/sync.c caf/shmem/teams_mgmt.c caf/shmem/thread_support.c
+
+libcaf_shmem_la_LDFLAGS = -static
+libcaf_shmem_la_DEPENDENCIES = \$(libcaf_shared_DEPS) caf/shmem/alloc.h \\
+       caf/shmem/allocator.h caf/shmem/collective_subroutine.h \\
+       caf/shmem/counter_barrier.h caf/shmem/hashmap.h \\
+       caf/shmem/shared_memory.h caf/shmem/supervisor.h caf/shmem/sync.h \\
+       caf/shmem/teams_mgmt.h caf/shmem/thread_support.h
+
+libcaf_shmem_la_LINK = \$(LINK) \$(libcaf_shmem_la_LDFLAGS)
 @IEEE_SUPPORT_TRUE@fincludedir = 
\$(libdir)/gcc/\$(target_alias)/\$(gcc_version)\$(MULTISUBDIR)/finclude
 @IEEE_SUPPORT_TRUE@nodist_finclude_HEADERS = ieee_arithmetic.mod 
ieee_exceptions.mod ieee_features.mod
 AM_CPPFLAGS = -iquote\$(srcdir)/io -I\$(srcdir)/\$(MULTISRCTOP)../gcc \\
@@ -1967,6 +1994,37 @@ caf/\$(am__dirstamp):
 caf/\$(DEPDIR)/\$(am__dirstamp):
        @\$(MKDIR_P) caf/\$(DEPDIR)
        @: > caf/\$(DEPDIR)/\$(am__dirstamp)
+caf/caf_error.lo: caf/\$(am__dirstamp) caf/\$(DEPDIR)/\$(am__dirstamp)
+caf/shmem.lo: caf/\$(am__dirstamp) caf/\$(DEPDIR)/\$(am__dirstamp)
+caf/shmem/\$(am__dirstamp):
+       @\$(MKDIR_P) caf/shmem
+       @: > caf/shmem/\$(am__dirstamp)
+caf/shmem/\$(DEPDIR)/\$(am__dirstamp):
+       @\$(MKDIR_P) caf/shmem/\$(DEPDIR)
+       @: > caf/shmem/\$(DEPDIR)/\$(am__dirstamp)
+caf/shmem/alloc.lo: caf/shmem/\$(am__dirstamp) \\
+       caf/shmem/\$(DEPDIR)/\$(am__dirstamp)
+caf/shmem/allocator.lo: caf/shmem/\$(am__dirstamp) \\
+       caf/shmem/\$(DEPDIR)/\$(am__dirstamp)
+caf/shmem/collective_subroutine.lo: caf/shmem/\$(am__dirstamp) \\
+       caf/shmem/\$(DEPDIR)/\$(am__dirstamp)
+caf/shmem/counter_barrier.lo: caf/shmem/\$(am__dirstamp) \\
+       caf/shmem/\$(DEPDIR)/\$(am__dirstamp)
+caf/shmem/hashmap.lo: caf/shmem/\$(am__dirstamp) \\
+       caf/shmem/\$(DEPDIR)/\$(am__dirstamp)
+caf/shmem/shared_memory.lo: caf/shmem/\$(am__dirstamp) \\
+       caf/shmem/\$(DEPDIR)/\$(am__dirstamp)
+caf/shmem/supervisor.lo: caf/shmem/\$(am__dirstamp) \\
+       caf/shmem/\$(DEPDIR)/\$(am__dirstamp)
+caf/shmem/sync.lo: caf/shmem/\$(am__dirstamp) \\
+       caf/shmem/\$(DEPDIR)/\$(am__dirstamp)
+caf/shmem/teams_mgmt.lo: caf/shmem/\$(am__dirstamp) \\
+       caf/shmem/\$(DEPDIR)/\$(am__dirstamp)
+caf/shmem/thread_support.lo: caf/shmem/\$(am__dirstamp) \\
+       caf/shmem/\$(DEPDIR)/\$(am__dirstamp)
+
+libcaf_shmem.la: \$(libcaf_shmem_la_OBJECTS) \$(libcaf_shmem_la_DEPENDENCIES) 
\$(EXTRA_libcaf_shmem_la_DEPENDENCIES) 
+       \$(AM_V_GEN)\$(libcaf_shmem_la_LINK) -rpath \$(cafexeclibdir) 
\$(libcaf_shmem_la_OBJECTS) \$(libcaf_shmem_la_LIBADD) \$(LIBS)
 caf/single.lo: caf/\$(am__dirstamp) caf/\$(DEPDIR)/\$(am__dirstamp)
 
 libcaf_single.la: \$(libcaf_single_la_OBJECTS) 
\$(libcaf_single_la_DEPENDENCIES) \$(EXTRA_libcaf_single_la_DEPENDENCIES) 
@@ -3776,6 +3834,8 @@ mostlyclean-compile:
        -rm -f *.\$(OBJEXT)
        -rm -f caf/*.\$(OBJEXT)
        -rm -f caf/*.lo
+       -rm -f caf/shmem/*.\$(OBJEXT)
+       -rm -f caf/shmem/*.lo
        -rm -f generated/*.\$(OBJEXT)
        -rm -f generated/*.lo
        -rm -f ieee/*.\$(OBJEXT)
@@ -3790,7 +3850,19 @@ mostlyclean-compile:
 distclean-compile:
        -rm -f *.tab.c
 
+@AMDEP_TRUE@@am__include@ @am__quote@caf/\$(DEPDIR)/caf_error.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@caf/\$(DEPDIR)/shmem.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@caf/\$(DEPDIR)/single.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@caf/shmem/\$(DEPDIR)/alloc.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ 
@am__quote@caf/shmem/\$(DEPDIR)/allocator.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ 
@am__quote@caf/shmem/\$(DEPDIR)/collective_subroutine.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ 
@am__quote@caf/shmem/\$(DEPDIR)/counter_barrier.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ 
@am__quote@caf/shmem/\$(DEPDIR)/hashmap.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ 
@am__quote@caf/shmem/\$(DEPDIR)/shared_memory.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ 
@am__quote@caf/shmem/\$(DEPDIR)/supervisor.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@caf/shmem/\$(DEPDIR)/sync.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ 
@am__quote@caf/shmem/\$(DEPDIR)/teams_mgmt.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ 
@am__quote@caf/shmem/\$(DEPDIR)/thread_support.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@generated/\$(DEPDIR)/all_l1.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ 
@am__quote@generated/\$(DEPDIR)/all_l16.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@generated/\$(DEPDIR)/all_l2.Plo@am__quote@
@@ -4556,6 +4628,7 @@ mostlyclean-libtool:
 clean-libtool:
        -rm -rf .libs _libs
        -rm -rf caf/.libs caf/_libs
+       -rm -rf caf/shmem/.libs caf/shmem/_libs
        -rm -rf generated/.libs generated/_libs
        -rm -rf ieee/.libs ieee/_libs
        -rm -rf intrinsics/.libs intrinsics/_libs
@@ -4723,6 +4796,8 @@ distclean-generic:
        -test . = "\$(srcdir)" || test -z "\$(CONFIG_CLEAN_VPATH_FILES)" || rm 
-f \$(CONFIG_CLEAN_VPATH_FILES)
        -rm -f caf/\$(DEPDIR)/\$(am__dirstamp)
        -rm -f caf/\$(am__dirstamp)
+       -rm -f caf/shmem/\$(DEPDIR)/\$(am__dirstamp)
+       -rm -f caf/shmem/\$(am__dirstamp)
        -rm -f generated/\$(DEPDIR)/\$(am__dirstamp)
        -rm -f generated/\$(am__dirstamp)
        -rm -f ieee/\$(DEPDIR)/\$(am__dirstamp)
@@ -4745,7 +4820,7 @@ clean-am: clean-cafexeclibLTLIBRARIES clean-generic 
clean-libtool \\
 
 distclean: distclean-am
        -rm -f \$(am__CONFIG_DISTCLEAN_FILES)
-       -rm -rf caf/\$(DEPDIR) generated/\$(DEPDIR) ieee/\$(DEPDIR) 
intrinsics/\$(DEPDIR) io/\$(DEPDIR) runtime/\$(DEPDIR)
+       -rm -rf caf/\$(DEPDIR) caf/shmem/\$(DEPDIR) generated/\$(DEPDIR) 
ieee/\$(DEPDIR) intrinsics/\$(DEPDIR) io/\$(DEPDIR) runtime/\$(DEPDIR)
        -rm -f Makefile
 distclean-am: clean-am distclean-compile distclean-generic \\
        distclean-hdr distclean-libtool distclean-local distclean-tags
@@ -4794,7 +4869,7 @@ installcheck-am:
 maintainer-clean: maintainer-clean-am
        -rm -f \$(am__CONFIG_DISTCLEAN_FILES)
        -rm -rf \$(top_srcdir)/autom4te.cache
-       -rm -rf caf/\$(DEPDIR) generated/\$(DEPDIR) ieee/\$(DEPDIR) 
intrinsics/\$(DEPDIR) io/\$(DEPDIR) runtime/\$(DEPDIR)
+       -rm -rf caf/\$(DEPDIR) caf/shmem/\$(DEPDIR) generated/\$(DEPDIR) 
ieee/\$(DEPDIR) intrinsics/\$(DEPDIR) io/\$(DEPDIR) runtime/\$(DEPDIR)
        -rm -f Makefile
 maintainer-clean-am: distclean-am maintainer-clean-generic \\
        maintainer-clean-local
diff --git a/libgfortran/acinclude.m4 b/libgfortran/acinclude.m4
index 23fd621e518..13097b4ab92 100644
--- a/libgfortran/acinclude.m4
+++ b/libgfortran/acinclude.m4
@@ -578,3 +578,15 @@ main ()
                        [Define to 1 if you have the \`\$1' function.])
   fi
 ])
+
+AC_DEFUN([LIBGFOR_CHECK_SANE_BUILTIN_CLZL], [
+  AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+      int main()
+      {
+       return __builtin_clzl(256) != 8;
+      }]], [[]])],
+    AC_DEFINE(HAVE_SANE_BUILTIN_CLZL, 1,
+      [Define if __builtin_clzl behaves as expected.])
+    AM_CONDITIONAL([HAVE_SANE_BUILTIN_CLZL],true),
+    [AM_CONDITIONAL([HAVE_SANE_BUILTIN_CLZL],false)])
+])
diff --git a/libgfortran/caf/libcaf.h b/libgfortran/caf/libcaf.h
index 06617a142b8..3e943d4ac67 100644
--- a/libgfortran/caf/libcaf.h
+++ b/libgfortran/caf/libcaf.h
@@ -26,9 +26,6 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If 
not, see
 #ifndef LIBCAF_H
 #define LIBCAF_H
 
-#include <stdbool.h>
-#include <stddef.h>    /* For size_t.  */
-
 #include "libgfortran.h"
 
 /* Definitions of the Fortran 2008 standard; need to kept in sync with
@@ -175,12 +172,9 @@ void _gfortran_caf_event_post (caf_token_t, size_t, int, 
int *, char *, size_t);
 void _gfortran_caf_event_wait (caf_token_t, size_t, int, int *, char *, 
size_t);
 void _gfortran_caf_event_query (caf_token_t, size_t, int, int *, int *);
 
-void _gfortran_caf_failed_images (gfc_descriptor_t *,
-                                 caf_team_t * __attribute__ ((unused)), int *);
-int _gfortran_caf_image_status (int, caf_team_t * __attribute__ ((unused)));
-void _gfortran_caf_stopped_images (gfc_descriptor_t *,
-                                  caf_team_t * __attribute__ ((unused)),
-                                  int *);
+void _gfortran_caf_failed_images (gfc_descriptor_t *, caf_team_t *, int *);
+int _gfortran_caf_image_status (int, caf_team_t *);
+void _gfortran_caf_stopped_images (gfc_descriptor_t *, caf_team_t *, int *);
 
 void _gfortran_caf_random_init (bool, bool);
 
diff --git a/libgfortran/caf/single.c b/libgfortran/caf/single.c
index 7e02dff25d8..43c83e65ec4 100644
--- a/libgfortran/caf/single.c
+++ b/libgfortran/caf/single.c
@@ -129,7 +129,7 @@ caf_internal_error (const char *msg, int *stat, char 
*errmsg,
       *stat = 1;
       if (errmsg_len > 0)
        {
-         int len = snprintf (errmsg, errmsg_len, msg, args);
+         int len = vsnprintf (errmsg, errmsg_len, msg, args);
          if (len >= 0 && errmsg_len > (size_t) len)
            memset (&errmsg[len], ' ', errmsg_len - len);
        }
diff --git a/libgfortran/config.h.in b/libgfortran/config.h.in
index da2c44c1af1..1a66ee7e513 100644
--- a/libgfortran/config.h.in
+++ b/libgfortran/config.h.in
@@ -777,6 +777,9 @@
 /* Define to 1 if you have the \`mkstemp' function. */
 #undef HAVE_MKSTEMP
 
+/* Define to 1 if you have the \`mmap' function. */
+#undef HAVE_MMAP
+
 /* Define to 1 if you have the \`newlocale' function. */
 #undef HAVE_NEWLOCALE
 
@@ -828,6 +831,9 @@
 /* Define to 1 if you have the \`roundl' function. */
 #undef HAVE_ROUNDL
 
+/* Define if __builtin_clzl behaves as expected. */
+#undef HAVE_SANE_BUILTIN_CLZL
+
 /* Define to 1 if you have the \`scalbn' function. */
 #undef HAVE_SCALBN
 
@@ -843,6 +849,9 @@
 /* Define to 1 if you have the \`secure_getenv' function. */
 #undef HAVE_SECURE_GETENV
 
+/* Define to 1 if you have the \`setenv' function. */
+#undef HAVE_SETENV
+
 /* Define to 1 if you have the \`setmode' function. */
 #undef HAVE_SETMODE
 
@@ -945,6 +954,9 @@
 /* Define to 1 if you have the \`symlink' function. */
 #undef HAVE_SYMLINK
 
+/* Define to 1 if you have the <sys/mman.h> header file. */
+#undef HAVE_SYS_MMAN_H
+
 /* Define to 1 if you have the <sys/random.h> header file. */
 #undef HAVE_SYS_RANDOM_H
 
diff --git a/libgfortran/configure b/libgfortran/configure
index 38d6c3cf3a0..4bcf9a14cfd 100755
--- a/libgfortran/configure
+++ b/libgfortran/configure
@@ -637,6 +637,8 @@ am__EXEEXT_TRUE
 LTLIBOBJS
 LIBOBJS
 get_gcc_base_ver
+HAVE_SANE_BUILTIN_CLZL_FALSE
+HAVE_SANE_BUILTIN_CLZL_TRUE
 HAVE_AVX128_FALSE
 HAVE_AVX128_TRUE
 tmake_file
@@ -2620,6 +2622,7 @@ as_fn_append ac_header_list " fpxcp.h"
 as_fn_append ac_header_list " pwd.h"
 as_fn_append ac_header_list " complex.h"
 as_fn_append ac_header_list " xlocale.h"
+as_fn_append ac_header_list " sys/mman.h"
 as_fn_append ac_func_list " getrusage"
 as_fn_append ac_func_list " times"
 as_fn_append ac_func_list " mkstemp"
@@ -2639,6 +2642,8 @@ as_fn_append ac_func_list " sleep"
 as_fn_append ac_func_list " ttyname"
 as_fn_append ac_func_list " sigaction"
 as_fn_append ac_func_list " waitpid"
+as_fn_append ac_func_list " mmap"
+as_fn_append ac_func_list " setenv"
 as_fn_append ac_func_list " alarm"
 as_fn_append ac_func_list " access"
 as_fn_append ac_func_list " fork"
@@ -13236,7 +13241,11 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=\$lt_dlunknown
   cat > conftest.\$ac_ext <<_LT_EOF
+<<<<<<< HEAD
 #line 13239 "configure"
+=======
+#line 13229 "configure"
+>>>>>>> a38ef687797 (WIP: Latest shared memory coarray.)
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -13342,7 +13351,11 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=\$lt_dlunknown
   cat > conftest.\$ac_ext <<_LT_EOF
+<<<<<<< HEAD
 #line 13345 "configure"
+=======
+#line 13335 "configure"
+>>>>>>> a38ef687797 (WIP: Latest shared memory coarray.)
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -17127,6 +17140,8 @@ done
 
 
 
+
+
 
 
 
@@ -17728,6 +17743,10 @@ done
 
 
 
+
+
+
+
 
 
 
@@ -31827,6 +31846,57 @@ rm -f core conftest.err conftest.\$ac_objext 
conftest.\$ac_ext
   CFLAGS="\$ac_save_CFLAGS"
 
 
+# Check if __builtin_clzl behaves (it doesn't on Msys2/ucrt64).
+
+  if test "\$cross_compiling" = yes; then :
+  { { \$as_echo "\$as_me:\${as_lineno-\$LINENO}: error: in \\\`\$ac_pwd':" >&5
+\$as_echo "\$as_me: error: in \\\`\$ac_pwd':" >&2;}
+as_fn_error \$? "cannot run test program while cross compiling
+See \\\`config.log' for more details" "\$LINENO" 5; }
+else
+  cat confdefs.h - <<_ACEOF >conftest.\$ac_ext
+/* end confdefs.h.  */
+
+      int main()
+      {
+       return __builtin_clzl(256) != 8;
+      }
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "\$LINENO"; then :
+
+\$as_echo "#define HAVE_SANE_BUILTIN_CLZL 1" >>confdefs.h
+
+     if true; then
+  HAVE_SANE_BUILTIN_CLZL_TRUE=
+  HAVE_SANE_BUILTIN_CLZL_FALSE='#'
+else
+  HAVE_SANE_BUILTIN_CLZL_TRUE='#'
+  HAVE_SANE_BUILTIN_CLZL_FALSE=
+fi
+
+else
+   if false; then
+  HAVE_SANE_BUILTIN_CLZL_TRUE=
+  HAVE_SANE_BUILTIN_CLZL_FALSE='#'
+else
+  HAVE_SANE_BUILTIN_CLZL_TRUE='#'
+  HAVE_SANE_BUILTIN_CLZL_FALSE=
+fi
+
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest\$ac_exeext \\
+  conftest.\$ac_objext conftest.beam conftest.\$ac_ext
+fi
+
+
+
 # Determine what GCC version number to use in filesystem paths.
 
   get_gcc_base_ver="cat"
@@ -32118,6 +32188,14 @@ if test -z "\${HAVE_AVX128_TRUE}" && test -z 
"\${HAVE_AVX128_FALSE}"; then
   as_fn_error \$? "conditional \\"HAVE_AVX128\\" was never defined.
 Usually this means the macro was only invoked conditionally." "\$LINENO" 5
 fi
+if test -z "\${HAVE_SANE_BUILTIN_CLZL_TRUE}" && test -z 
"\${HAVE_SANE_BUILTIN_CLZL_FALSE}"; then
+  as_fn_error \$? "conditional \\"HAVE_SANE_BUILTIN_CLZL\\" was never defined.
+Usually this means the macro was only invoked conditionally." "\$LINENO" 5
+fi
+if test -z "\${HAVE_SANE_BUILTIN_CLZL_TRUE}" && test -z 
"\${HAVE_SANE_BUILTIN_CLZL_FALSE}"; then
+  as_fn_error \$? "conditional \\"HAVE_SANE_BUILTIN_CLZL\\" was never defined.
+Usually this means the macro was only invoked conditionally." "\$LINENO" 5
+fi
 
 : "\${CONFIG_STATUS=./config.status}"
 ac_write_fail=0
diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac
index cca1ea0ea97..b165dff1e05 100644
--- a/libgfortran/configure.ac
+++ b/libgfortran/configure.ac
@@ -298,7 +298,7 @@ AC_CHECK_TYPES([ptrdiff_t])
 AC_CHECK_HEADERS_ONCE(unistd.h sys/random.h sys/time.h sys/times.h \\
 sys/resource.h sys/types.h sys/stat.h sys/uio.h sys/wait.h \\
 floatingpoint.h ieeefp.h fenv.h fptrap.h \\
-fpxcp.h pwd.h complex.h xlocale.h)
+fpxcp.h pwd.h complex.h xlocale.h sys/mman.h)
 
 GCC_HEADER_STDINT(gstdint.h)
 
@@ -334,7 +334,7 @@ if test "\${hardwire_newlib:-0}" -eq 1; then
 else
    AC_CHECK_FUNCS_ONCE(getrusage times mkstemp strtof strtold snprintf \\
    ftruncate chsize chdir getentropy getlogin gethostname kill link symlink \\
-   sleep ttyname sigaction waitpid \\
+   sleep ttyname sigaction waitpid mmap setenv\\
    alarm access fork posix_spawn setmode fcntl writev \\
    gettimeofday stat fstat lstat getpwuid vsnprintf dup \\
    getcwd localtime_r gmtime_r getpwuid_r ttyname_r clock_gettime \\
@@ -789,6 +789,9 @@ LIBGFOR_CHECK_FMA4
 # Check if AVX128 works
 LIBGFOR_CHECK_AVX128
 
+# Check if __builtin_clzl behaves (it doesn't on Msys2/ucrt64).
+LIBGFOR_CHECK_SANE_BUILTIN_CLZL
+
 # Determine what GCC version number to use in filesystem paths.
 GCC_BASE_VER
 
------

LAST_UPDATED: Fri Feb  6 13:42:12 UTC 2026 (revision r16-7363-g9b85fcc00eb)

Native configuration is aarch64-unknown-linux-gnu

                === libatomic tests ===


Running target unix

                === libatomic Summary ===

# of expected passes            54
                === libgomp tests ===


Running target unix
FAIL: libgomp.c/pr122356.c execution test
UNRESOLVED: libgomp.fortran/uses_allocators-7.f90   -O  compilation failed to 
produce executable

                === libgomp Summary ===

# of expected passes            17345
# of unexpected failures        1
# of expected failures          287
# of unresolved testcases       1
# of unsupported tests          854
                === libitm tests ===


Running target unix

                === libitm Summary ===

# of expected passes            44
# of expected failures          3
# of unsupported tests          1
                === libstdc++ tests ===


Running target unix

                === libstdc++ Summary ===

# of expected passes            17714
# of expected failures          120
# of unsupported tests          807
                === gcc tests ===


Running target unix
FAIL: gcc.dg/rtl/aarch64/subs_adds_sp.c (internal compiler error: in 
df_scan_verify, at df-scan.cc:4232)
FAIL: gcc.dg/rtl/aarch64/subs_adds_sp.c (test for excess errors)
UNRESOLVED: gcc.dg/rtl/aarch64/subs_adds_sp.c scan-assembler-not adds\\\\tsp
UNRESOLVED: gcc.dg/rtl/aarch64/subs_adds_sp.c scan-assembler-not subs\\\\tsp
UNRESOLVED: gcc.dg/rtl/aarch64/subs_adds_sp.c scan-assembler-times 
adds\\\\tx[0-9]+, sp 1
UNRESOLVED: gcc.dg/rtl/aarch64/subs_adds_sp.c scan-assembler-times 
subs\\\\tx[0-9]+, sp 1
FAIL: gcc.dg/tree-ssa/predcom-8.c scan-tree-dump-not pcom "Invalid sum"
FAIL: gcc.dg/vect/complex/fast-math-complex-add-pattern-half-float.c -flto 
-ffat-lto-objects  scan-tree-dump-times vect "add new stmt: 
[^\\n\\r]*COMPLEX_ADD_ROT90" 3
FAIL: gcc.dg/vect/complex/fast-math-complex-add-pattern-half-float.c 
scan-tree-dump-times vect "add new stmt: [^\\n\\r]*COMPLEX_ADD_ROT90" 3
FAIL: gcc.dg/vect/complex/fast-math-complex-mls-double.c -flto 
-ffat-lto-objects  scan-tree-dump vect "Found COMPLEX_ADD_ROT270"
FAIL: gcc.dg/vect/complex/fast-math-complex-mls-double.c scan-tree-dump vect 
"Found COMPLEX_ADD_ROT270"
FAIL: gcc.dg/vect/complex/fast-math-complex-mls-float.c -flto -ffat-lto-objects 
 scan-tree-dump vect "Found COMPLEX_ADD_ROT270"
FAIL: gcc.dg/vect/complex/fast-math-complex-mls-float.c scan-tree-dump vect 
"Found COMPLEX_ADD_ROT270"
FAIL: gcc.dg/vect/complex/vect-complex-operations-run.c -flto -ffat-lto-objects 
execution test
FAIL: gcc.dg/vect/complex/vect-complex-operations-run.c execution test
FAIL: gcc.dg/vect/pr122475.c -flto -ffat-lto-objects execution test
FAIL: gcc.dg/vect/pr122475.c execution test
XPASS: gcc.dg/vect/vect-fncall-mask-math.c -flto -ffat-lto-objects  
scan-tree-dump-not ifcvt " gimple_call <expf, _2, _1>"
XPASS: gcc.dg/vect/vect-fncall-mask-math.c scan-tree-dump-not ifcvt " 
gimple_call <expf, _2, _1>"
XPASS: gcc.dg/vect/vect-reduc-dot-s8b.c -flto -ffat-lto-objects  
scan-tree-dump-times vect "vect_recog_dot_prod_pattern: detected(?:(?!Analysis 
failed).)*Analysis succeeded" 1
XPASS: gcc.dg/vect/vect-reduc-dot-s8b.c scan-tree-dump-times vect 
"vect_recog_dot_prod_pattern: detected(?:(?!Analysis failed).)*Analysis 
succeeded" 1
XPASS: gcc.dg/vect/vect-reduc-pattern-2c.c -flto -ffat-lto-objects  
scan-tree-dump-times vect "vect_recog_widen_sum_pattern: detected" 1
XPASS: gcc.dg/vect/vect-reduc-pattern-2c.c scan-tree-dump-times vect 
"vect_recog_widen_sum_pattern: detected" 1
FAIL: gcc.target/aarch64/sme/streaming_mode_1.c  (test for errors, line 10)
FAIL: gcc.target/aarch64/sme/streaming_mode_1.c  (test for errors, line 121)
FAIL: gcc.target/aarch64/sme/streaming_mode_1.c  (test for errors, line 16)
FAIL: gcc.target/aarch64/sme/streaming_mode_1.c  (test for errors, line 30)
FAIL: gcc.target/aarch64/sme/streaming_mode_1.c  (test for errors, line 36)
FAIL: gcc.target/aarch64/sme/streaming_mode_1.c  (test for errors, line 4)
FAIL: gcc.target/aarch64/sme/streaming_mode_1.c  (test for errors, line 42)
FAIL: gcc.target/aarch64/sme/za_state_1.c  (test for errors, line 10)
FAIL: gcc.target/aarch64/sme/za_state_1.c  (test for errors, line 142)
FAIL: gcc.target/aarch64/sme/za_state_1.c  (test for errors, line 16)
FAIL: gcc.target/aarch64/sme/za_state_1.c  (test for errors, line 30)
FAIL: gcc.target/aarch64/sme/za_state_1.c  (test for errors, line 36)
FAIL: gcc.target/aarch64/sme/za_state_1.c  (test for errors, line 4)
FAIL: gcc.target/aarch64/sme/za_state_1.c  (test for errors, line 42)
FAIL: gcc.target/aarch64/sme/za_state_2.c  (test for errors, line 27)
FAIL: gcc.target/aarch64/sme/za_state_2.c  (test for errors, line 33)
FAIL: gcc.target/aarch64/sme/za_state_2.c  (test for errors, line 39)
FAIL: gcc.target/aarch64/sme/za_state_2.c  (test for errors, line 45)
FAIL: gcc.target/aarch64/sme/za_state_2.c (test for excess errors)
FAIL: gcc.target/aarch64/sve/pr123898.c (internal compiler error: in 
convert_mult_to_fma, at tree-ssa-math-opts.cc:3649)
FAIL: gcc.target/aarch64/sve/pr123898.c (test for excess errors)
FAIL: gcc.target/aarch64/sve/pr123898.c scan-tree-dump-times widening_mul 
".FMA" 1

                === gcc Summary ===

# of expected passes            395572
# of unexpected failures        35
# of unexpected successes       6
# of expected failures          1929
# of unresolved testcases       4
# of unsupported tests          5574
/dev/shm/bld3155406/gcc/xgcc  version 16.0.1 20260206 (experimental) [master 
r16-7363-g9b85fcc00eb] (GCC) 

                === gfortran tests ===


Running target unix

                === gfortran Summary ===

# of expected passes            74300
# of expected failures          343
# of unsupported tests          208
/dev/shm/bld3155406/gcc/gfortran  version 16.0.1 20260206 (experimental) 
[master r16-7363-g9b85fcc00eb] (GCC) 

                === g++ tests ===


Running target unix
FAIL: g++.dg/analyzer/fanalyzer-show-events-in-system-headers.C  -std=c++20 
(test for excess errors)
FAIL: g++.dg/analyzer/fanalyzer-show-events-in-system-headers.C  -std=c++26 
(test for excess errors)
FAIL: g++.dg/coroutines/torture/func-params-07.C   -O3 -g  execution test
FAIL: g++.dg/coroutines/torture/pr103953.C   -O2  execution test
FAIL: g++.dg/coroutines/torture/pr103953.C   -O3 -g  execution test
FAIL: g++.dg/cpp1z/constexpr-asm-5.C  -std=gnu++23  (test for errors, line 343)
FAIL: g++.dg/cpp1z/constexpr-asm-5.C  -std=gnu++26  (test for errors, line 343)
XPASS: g++.dg/ipa/devirt-23.C  -std=gnu++20  scan-ipa-dump cp "Discovered a 
virtual call to"
XPASS: g++.dg/ipa/devirt-23.C  -std=gnu++26  scan-ipa-dump cp "Discovered a 
virtual call to"
XPASS: g++.dg/ipa/devirt-23.C  -std=gnu++98  scan-ipa-dump cp "Discovered a 
virtual call to"
FAIL: g++.dg/reflect/extract1.C  -std=c++26 (internal compiler error: 
Segmentation fault)
FAIL: g++.dg/reflect/extract1.C  -std=c++26 (test for excess errors)
FAIL: g++.dg/lto/devirt-23 cp_lto_devirt-23_0.o-cp_lto_devirt-23_0.o execute 
-O3 -fno-early-inlining -fno-ipa-sra -fdump-ipa-cp -flto 
-fno-devirtualize-speculatively
FAIL: g++.target/aarch64/pr117048.C scan-assembler \\\\txar\\\\tv[0-9]+\\\\.2d, 
v[0-9]+\\\\.2d, v[0-9]+\\\\.2d, 32\\\\n

                === g++ Summary ===

# of expected passes            453755
# of unexpected failures        11
# of unexpected successes       3
# of expected failures          2670
# of unsupported tests          3424
/dev/shm/bld3155406/gcc/xg++  version 16.0.1 20260206 (experimental) [master 
r16-7363-g9b85fcc00eb] (GCC) 


Compiler version: 16.0.1 20260206 (experimental) [master r16-7363-g9b85fcc00eb] 
(GCC) 
Platform: aarch64-unknown-linux-gnu
configure flags: --prefix=/home/toon/compilers/install/gcc --with-gnu-as 
--with-gnu-ld --enable-languages=fortran --disable-multilib --disable-nls 
--enable-checking=yes,extra,rtl,df,gcac

Reply via email to