--- /dev/null
+! { dg-do run }
+! { dg-options "-fcoarray=lib -lcaf_single" }
+
+program check_caf_send_by_ref
+
+ implicit none
+
+ type T
+ integer, allocatable :: scal
+ integer, allocatable :: array(:)
+ end type T
+
+ type(T), save :: obj[*]
+ integer :: me, np, i
+
+ me = this_image()
+ np = num_images()
+
+ obj[np]%scal = 42
+
+ ! Check the token for the scalar is set.
+ if (obj[np]%scal /= 42) call abort()
+
+ ! Now the same for arrays.
+ obj[np]%array = [(i * np + me, i = 1, 15)]
+ if (any(obj[np]%array /= [(i * np + me, i = 1, 15)])) call abort()
+
+end program check_caf_send_by_ref
+
if ((size_t)errmsg_len > len)
memset (&errmsg[len], ' ', errmsg_len - len);
}
+ va_end (args);
return;
}
else
if (unlikely (local == NULL || *token == NULL))
{
+ /* Freeing the memory conditionally seems pointless, but
+ caf_internal_error () may return, when a stat is given and then the
+ memory may be lost. */
+ if (local)
+ free (local);
+ if (*token)
+ free (*token);
caf_internal_error (alloc_fail_msg, stat, errmsg, errmsg_len);
return;
}
bool array_extent_fixed = false;
realloc_needed = realloc_required = GFC_DESCRIPTOR_DATA (dst) == NULL;
- assert (!realloc_needed || (realloc_needed && dst_reallocatable));
+ assert (!realloc_needed || dst_reallocatable);
if (stat)
*stat = 0;
GFC_DESCRIPTOR_DATA (&static_dst) = NULL;
GFC_DESCRIPTOR_DTYPE (&static_dst)
= GFC_DESCRIPTOR_DTYPE (src);
- /* The component may be allocated now, because it is a
+ /* The component can be allocated now, because it is a
scalar. */
- single_token = *(caf_single_token_t*)
- (ds + ref->u.c.caf_token_offset);
_gfortran_caf_register (ref->item_size,
CAF_REGTYPE_COARRAY_ALLOC,
- (caf_token_t *)&single_token,
+ ds + ref->u.c.caf_token_offset,
&static_dst, stat, NULL, 0);
+ single_token = *(caf_single_token_t *)
+ (ds + ref->u.c.caf_token_offset);
/* In case of an error in allocation return. When stat is
NULL, then register_component() terminates on error. */
if (stat != NULL && *stat)
/* The size of the array is given by size. */
_gfortran_caf_register (size * ref->item_size,
CAF_REGTYPE_COARRAY_ALLOC,
- (void **)&single_token,
+ ds + ref->u.c.caf_token_offset,
dst, stat, NULL, 0);
/* In case of an error in allocation return. When stat is
NULL, then register_component() terminates on error. */
if (stat != NULL && *stat)
return;
- /* The memptr, descriptor and the token are set below. */
- *(caf_single_token_t *)(ds + ref->u.c.caf_token_offset)
- = single_token;
}
single_token = *(caf_single_token_t*)(ds + ref->u.c.caf_token_offset);
send_by_ref (ref->next, i, src_index, single_token,