case BT_LOGICAL:
return size_logical (e->ts.kind);
case BT_CHARACTER:
- return size_character (e->value.character.length, e->ts.kind);
+ if (e->expr_type == EXPR_SUBSTRING && e->ref)
+ {
+ int start, end;
+
+ gfc_extract_int (e->ref->u.ss.start, &start);
+ gfc_extract_int (e->ref->u.ss.end, &end);
+ return size_character (MAX(end - start + 1, 0), e->ts.kind);
+ }
+ else
+ return size_character (e->value.character.length, e->ts.kind);
case BT_HOLLERITH:
return e->representation.length;
case BT_DERIVED:
return encode_array (source, buffer, buffer_size);
gcc_assert (source->expr_type == EXPR_CONSTANT
- || source->expr_type == EXPR_STRUCTURE);
+ || source->expr_type == EXPR_STRUCTURE
+ || source->expr_type == EXPR_SUBSTRING);
/* If we already have a target-memory representation, we use that rather
than recreating one. */
return encode_logical (source->ts.kind, source->value.logical, buffer,
buffer_size);
case BT_CHARACTER:
- return encode_character (source->ts.kind, source->value.character.length,
- source->value.character.string, buffer,
- buffer_size);
+ if (source->expr_type == EXPR_CONSTANT || source->ref == NULL)
+ return encode_character (source->ts.kind,
+ source->value.character.length,
+ source->value.character.string, buffer,
+ buffer_size);
+ else
+ {
+ int start, end;
+
+ gcc_assert (source->expr_type == EXPR_SUBSTRING);
+ gfc_extract_int (source->ref->u.ss.start, &start);
+ gfc_extract_int (source->ref->u.ss.end, &end);
+ return encode_character (source->ts.kind,
+ MAX(end - start + 1, 0),
+ &source->value.character.string[start-1],
+ buffer, buffer_size);
+ }
+
case BT_DERIVED:
return encode_derived (source, buffer, buffer_size);
default:
{
int size;
size = gfc_interpret_float (kind, &buffer[0], buffer_size, real);
- size += gfc_interpret_float (kind, &buffer[size], buffer_size - size, imaginary);
+ size += gfc_interpret_float (kind, &buffer[size], buffer_size - size,
+ imaginary);
return size;
}
--- /dev/null
+! { dg-do run }
+!
+! Various checks on simplification of TRANSFER of substrings
+ character(len=4), parameter :: t = "xyzt"
+ integer, parameter :: w = transfer(t,0)
+ integer :: i = 1
+ if (transfer(t,0) /= w) call abort
+ if (transfer(t(:),0) /= w) call abort
+ if (transfer(t(1:4),0) /= w) call abort
+ if (transfer(t(i:i+3),0) /= w) call abort
+
+ if (transfer(t(1:1), 0_1) /= transfer("x", 0_1)) call abort
+ if (transfer(t(2:2), 0_1) /= transfer("y", 0_1)) call abort
+ if (transfer(t(i:i), 0_1) /= transfer("x", 0_1)) call abort
+ if (transfer(t(i+1:i+1), 0_1) /= transfer("y", 0_1)) call abort
+ if (transfer(t(1:2), 0_2) /= transfer("xy", 0_2)) call abort
+ if (transfer(t(3:4), 0_2) /= transfer("zt", 0_2)) call abort
+
+ if (transfer(transfer(-1, t), 0) /= -1) call abort
+ if (transfer(transfer(-1, t(:)), 0) /= -1) call abort
+ if (any (transfer(transfer(-1, (/t(1:1)/)), (/0_1/)) /= -1)) call abort
+ if (transfer(transfer(-1, t(1:1)), 0_1) /= -1) call abort
+ end