/* Scalar transfer statement.
- TRANSFER (source, mold) = VIEW_CONVERT_EXPR<typeof<mold> >source. */
+ TRANSFER (source, mold) = memcpy(&tmpdecl, &source, size), tmpdecl. */
static void
gfc_conv_intrinsic_transfer (gfc_se * se, gfc_expr * expr)
tree type;
tree ptr;
gfc_ss *ss;
+ tree tmpdecl, tmp, args;
/* Get a pointer to the source. */
arg = expr->value.function.actual;
arg = arg->next;
type = gfc_typenode_for_spec (&expr->ts);
+
if (expr->ts.type == BT_CHARACTER)
{
ptr = convert (build_pointer_type (type), ptr);
}
else
{
- tree tmp = build_fold_indirect_ref (ptr);
- se->expr = fold_build1 (VIEW_CONVERT_EXPR, type, tmp);
+ tree moldsize;
+ tmpdecl = gfc_create_var (type, "transfer");
+ moldsize = size_in_bytes (type);
+
+ /* Use memcpy to do the transfer. */
+ tmp = build1 (ADDR_EXPR, build_pointer_type (type), tmpdecl);
+ tmp = fold_convert (pvoid_type_node, tmp);
+ args = gfc_chainon_list (NULL_TREE, tmp);
+ tmp = fold_convert (pvoid_type_node, ptr);
+ args = gfc_chainon_list (args, tmp);
+ args = gfc_chainon_list (args, moldsize);
+ tmp = built_in_decls[BUILT_IN_MEMCPY];
+ tmp = build_function_call_expr (tmp, args);
+ gfc_add_expr_to_block (&se->pre, tmp);
+
+ se->expr = tmpdecl;
}
}
--- /dev/null
+program test_convert
+
+ implicit none
+ character(len=4) :: byte_string
+ character(len=1),dimension(4) :: byte_array
+ integer*4 :: value,value1,n,i
+
+ byte_string(1:1) = char(157)
+ byte_string(2:2) = char(127)
+ byte_string(3:3) = char(100)
+ byte_string(4:4) = char(0)
+
+ byte_array(1:4) = (/char(157),char(127),char(100),char(0)/)
+
+ value = transfer(byte_string(1:4),value)
+ value1 = transfer(byte_array(1:4),value1)
+
+ if (value .ne. value1) call abort()
+end program test_convert