diff options
author | tkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-07-14 20:39:10 +0000 |
---|---|---|
committer | tkoenig <tkoenig@138bc75d-0d04-0410-961f-82ee72b054a4> | 2007-07-14 20:39:10 +0000 |
commit | 014e0d24c3051cbb990be704f980cd2958994d82 (patch) | |
tree | 882fafe4edcc95b5b0f95aa140ea91d799393487 /gcc/fortran/iresolve.c | |
parent | e85b06c54b44b0da44f3130aafd1a2d3b26244eb (diff) | |
download | gcc-014e0d24c3051cbb990be704f980cd2958994d82.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@126644 138bc75d-0d04-0410-961f-82ee72b054a4
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 b0a1c37dda6..66a3c2f52e5 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" : ""); |