This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gfortran] Fix PR 16579: Signed/Unsigned confusion in ICHAR
- From: Tobias Schlüter <tobias dot schlueter at physik dot uni-muenchen dot de>
- To: GCC Fortran mailing list <fortran at gcc dot gnu dot org>,patch <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 29 Aug 2004 21:11:10 +0200
- Subject: [gfortran] Fix PR 16579: Signed/Unsigned confusion in ICHAR
Default character is a signed type. This is 50% of the problem in
gfc_trans_intrinsic_ichar. Should we change this to an unsigned type? It seems
to make sense. With the signed type in place I had to insert an explicit
conversion to unsigned char in our implementation of ICHAR.
The other 50% were that we didn't get the return type right: this should be
default integer, and not the type of the argument (= default character =
INTEGER*1) as before.
Built and tested, new testcase attached. I named the testcase
intrinsic_i_char, because it tests (I)CHAR.
- Tobi
2004-08-29 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de>
* trans-intrinsic.c (gfc_conv_intrinsic_ichar): Fix signed/unsigned
error.
Index: trans-intrinsic.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-intrinsic.c,v
retrieving revision 1.19
diff -u -p -r1.19 trans-intrinsic.c
--- trans-intrinsic.c 29 Aug 2004 15:58:13 -0000 1.19
+++ trans-intrinsic.c 29 Aug 2004 19:00:19 -0000
@@ -1980,10 +1980,13 @@ gfc_conv_intrinsic_ichar (gfc_se * se, g
arg = TREE_VALUE (TREE_CHAIN (arg));
assert (POINTER_TYPE_P (TREE_TYPE (arg)));
arg = build1 (NOP_EXPR, pchar_type_node, arg);
- type = gfc_typenode_for_spec (&expr->ts);
+ type = gfc_get_int_type (gfc_default_integer_kind);
se->expr = gfc_build_indirect_ref (arg);
- se->expr = convert (type, se->expr);
+ /* We convert too unsigned char first, so that we don't get a sign
+ extended result, when converting to default integer afterwards. */
+ se->expr = fold_convert (type,
+ fold_convert(unsigned_char_type_node, se->expr));
}
! simple test for the CHAR and ICHAR intrinsics
! PR 16579
DO I=0,255
IF (ICHAR(CHAR(I)) /= I) CALL ABORT()
END DO
END