diff options
author | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2007-05-19 01:04:03 +0000 |
---|---|---|
committer | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2007-05-19 01:04:03 +0000 |
commit | c152efbb10508ad7714aa5e14c89bcfc7f0d1697 (patch) | |
tree | e363e48aa8385b05ad91d014553d9aa4d1ea607d /libgfortran | |
parent | cc25a1c4582663ccd8fce97612339d59439efbb6 (diff) | |
download | gcc-c152efbb10508ad7714aa5e14c89bcfc7f0d1697.zip gcc-c152efbb10508ad7714aa5e14c89bcfc7f0d1697.tar.gz gcc-c152efbb10508ad7714aa5e14c89bcfc7f0d1697.tar.bz2 |
re PR fortran/31964 ([4.2, 4.1 only]ishftc fails with certain thrid argument)
2007-05-18 Jerry DeLisle <jvdelisle@gcc.gnu.org>
PR libfortran/31964
* intrinsics/ishftc.c (ishftc4, ishftc8, ishftc16): Fix mask to handle
shift of bit-size number of bits.
From-SVN: r124846
Diffstat (limited to 'libgfortran')
-rw-r--r-- | libgfortran/ChangeLog | 6 | ||||
-rw-r--r-- | libgfortran/intrinsics/ishftc.c | 42 |
2 files changed, 33 insertions, 15 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index 6d3e78e..07199e7 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,9 @@ +2007-05-18 Jerry DeLisle <jvdelisle@gcc.gnu.org> + + PR libfortran/31964 + * intrinsics/ishftc.c (ishftc4, ishftc8, ishftc16): Fix mask to handle + shift of bit-size number of bits. + 2007-05-17 Tobias Burnus <burnus@net-b.de> PR fortran/31917 diff --git a/libgfortran/intrinsics/ishftc.c b/libgfortran/intrinsics/ishftc.c index a147b96..68cc4cb 100644 --- a/libgfortran/intrinsics/ishftc.c +++ b/libgfortran/intrinsics/ishftc.c @@ -36,8 +36,7 @@ export_proto(ishftc4); GFC_INTEGER_4 ishftc4 (GFC_INTEGER_4 i, GFC_INTEGER_4 shift, GFC_INTEGER_4 size) { - GFC_INTEGER_4 mask; - GFC_UINTEGER_4 bits; + GFC_UINTEGER_4 mask, bits; if (shift < 0) shift = shift + size; @@ -45,9 +44,14 @@ ishftc4 (GFC_INTEGER_4 i, GFC_INTEGER_4 shift, GFC_INTEGER_4 size) if (shift == 0 || shift == size) return i; - mask = (~(GFC_INTEGER_4)0) << size; - bits = i & ~mask; - return (i & mask) | (bits >> (size - shift)) | ((i << shift) & ~mask); + /* In C, the result of the shift operator is undefined if the right operand + is greater than or equal to the number of bits in the left operand. So we + have to special case it for fortran. */ + mask = ~((size == 32) ? (GFC_UINTEGER_4)0 : (~(GFC_UINTEGER_4)0 << size)); + + bits = i & mask; + + return (i & ~mask) | ((bits << shift) & mask) | (bits >> (size - shift)); } extern GFC_INTEGER_8 ishftc8 (GFC_INTEGER_8, GFC_INTEGER_4, GFC_INTEGER_4); @@ -56,8 +60,7 @@ export_proto(ishftc8); GFC_INTEGER_8 ishftc8 (GFC_INTEGER_8 i, GFC_INTEGER_4 shift, GFC_INTEGER_4 size) { - GFC_INTEGER_8 mask; - GFC_UINTEGER_8 bits; + GFC_UINTEGER_8 mask, bits; if (shift < 0) shift = shift + size; @@ -65,9 +68,14 @@ ishftc8 (GFC_INTEGER_8 i, GFC_INTEGER_4 shift, GFC_INTEGER_4 size) if (shift == 0 || shift == size) return i; - mask = (~(GFC_INTEGER_8)0) << size; - bits = i & ~mask; - return (i & mask) | (bits >> (size - shift)) | ((i << shift) & ~mask); + /* In C, the result of the shift operator is undefined if the right operand + is greater than or equal to the number of bits in the left operand. So we + have to special case it for fortran. */ + mask = ~((size == 64) ? (GFC_UINTEGER_8)0 : (~(GFC_UINTEGER_8)0 << size)); + + bits = i & mask; + + return (i & ~mask) | ((bits << shift) & mask) | (bits >> (size - shift)); } #ifdef HAVE_GFC_INTEGER_16 @@ -77,8 +85,7 @@ export_proto(ishftc16); GFC_INTEGER_16 ishftc16 (GFC_INTEGER_16 i, GFC_INTEGER_4 shift, GFC_INTEGER_4 size) { - GFC_INTEGER_16 mask; - GFC_UINTEGER_16 bits; + GFC_UINTEGER_16 mask, bits; if (shift < 0) shift = shift + size; @@ -86,8 +93,13 @@ ishftc16 (GFC_INTEGER_16 i, GFC_INTEGER_4 shift, GFC_INTEGER_4 size) if (shift == 0 || shift == size) return i; - mask = (~(GFC_INTEGER_16)0) << size; - bits = i & ~mask; - return (i & mask) | (bits >> (size - shift)) | ((i << shift) & ~mask); + /* In C, the result of the shift operator is undefined if the right operand + is greater than or equal to the number of bits in the left operand. So we + have to special case it for fortran. */ + mask = ~((size == 128) ? (GFC_UINTEGER_16)0 : (~(GFC_UINTEGER_16)0 << size)); + + bits = i & mask; + + return (i & ~mask) | ((bits << shift) & mask) | (bits >> (size - shift)); } #endif |