diff options
author | Thomas Koenig <tkoenig@gcc.gnu.org> | 2007-07-14 20:39:10 +0000 |
---|---|---|
committer | Thomas Koenig <tkoenig@gcc.gnu.org> | 2007-07-14 20:39:10 +0000 |
commit | 3b3620db92522cb3c4d64e476ec1ce6a540044ef (patch) | |
tree | 882fafe4edcc95b5b0f95aa140ea91d799393487 /gcc/fortran/iresolve.c | |
parent | 27e3a7bc8d8101c0f85ac2e057a8784cb8d24326 (diff) | |
download | gcc-3b3620db92522cb3c4d64e476ec1ce6a540044ef.zip gcc-3b3620db92522cb3c4d64e476ec1ce6a540044ef.tar.gz gcc-3b3620db92522cb3c4d64e476ec1ce6a540044ef.tar.bz2 |
re PR libfortran/32731 (pack/unpack with kind=1 or kind=2 mask)
2007-07-14 Thomas Koenig <tkoenig@gcc.gnu.org>
PR libfortran/32731
* iresolve.c(gfc_resolve_pack): A scalar mask has
to be kind=4, an array mask with kind<4 is converted
to gfc_default_logical_kind automatically.
(gfc_resolve_unpack): Convert mask to gfc_default_lotical_kind
if it has a kind<4.
2007-07-14 Thomas Koenig <tkoenig@gcc.gnu.org>
PR libfortran/32731
* gfortran.dg/pack_mask_1.f90: New test.
* gfortran.dg/unpack_mask_1.f90: New test.
From-SVN: r126644
Diffstat (limited to 'gcc/fortran/iresolve.c')
-rw-r--r-- | gcc/fortran/iresolve.c | 54 |
1 files changed, 39 insertions, 15 deletions
diff --git a/gcc/fortran/iresolve.c b/gcc/fortran/iresolve.c index b0a1c37..66a3c2f 100644 --- a/gcc/fortran/iresolve.c +++ b/gcc/fortran/iresolve.c @@ -1556,29 +1556,42 @@ void gfc_resolve_pack (gfc_expr *f, gfc_expr *array, gfc_expr *mask, gfc_expr *vector ATTRIBUTE_UNUSED) { + int newkind; + f->ts = array->ts; f->rank = 1; - if (mask->rank != 0) - f->value.function.name = (array->ts.type == BT_CHARACTER - ? PREFIX ("pack_char") : PREFIX ("pack")); + /* The mask can be kind 4 or 8 for the array case. For the scalar + case, coerce it to kind=4 unconditionally (because this is the only + kind we have a library function for). */ + + newkind = 0; + if (mask->rank == 0) + { + if (mask->ts.kind != 4) + newkind = 4; + } else { - /* We convert mask to default logical only in the scalar case. - In the array case we can simply read the array as if it were - of type default logical. */ - if (mask->ts.kind != gfc_default_logical_kind) - { - gfc_typespec ts; + if (mask->ts.kind < 4) + newkind = gfc_default_logical_kind; + } - ts.type = BT_LOGICAL; - ts.kind = gfc_default_logical_kind; - gfc_convert_type (mask, &ts, 2); - } + if (newkind) + { + gfc_typespec ts; - f->value.function.name = (array->ts.type == BT_CHARACTER - ? PREFIX ("pack_s_char") : PREFIX ("pack_s")); + ts.type = BT_LOGICAL; + ts.kind = gfc_default_logical_kind; + gfc_convert_type (mask, &ts, 2); } + + if (mask->rank != 0) + f->value.function.name = (array->ts.type == BT_CHARACTER + ? PREFIX ("pack_char") : PREFIX ("pack")); + else + f->value.function.name = (array->ts.type == BT_CHARACTER + ? PREFIX ("pack_s_char") : PREFIX ("pack_s")); } @@ -2339,6 +2352,17 @@ gfc_resolve_unpack (gfc_expr *f, gfc_expr *vector, gfc_expr *mask, f->ts = vector->ts; f->rank = mask->rank; + /* Coerce the mask to default logical kind if it has kind < 4. */ + + if (mask->ts.kind < 4) + { + gfc_typespec ts; + + ts.type = BT_LOGICAL; + ts.kind = gfc_default_logical_kind; + gfc_convert_type (mask, &ts, 2); + } + f->value.function.name = gfc_get_string (PREFIX ("unpack%d%s"), field->rank > 0 ? 1 : 0, vector->ts.type == BT_CHARACTER ? "_char" : ""); |