From 32bef8ff8090a0d108fa14fc4088e55e57a5e6d5 Mon Sep 17 00:00:00 2001 From: Mark Eggleston Date: Mon, 25 Nov 2019 10:36:25 +0000 Subject: DEC comparisons - allow Hollerith constants in comparisons. The -fdec option enables the use of Hollerith comparisons in comparisons with INTEGER, COMPLEX, REAL and CHARACTER expressions. Mark Eggleston Jim MacArthur * gfortran.texi: Update Hollerith constants support for character types and use in comparisons. * invoke.texi: Tidy up list of options. Update description of -fdec-char-conversions. * resolve.c (is_character_based): New. (Convert_hollerith_to_character): New. (convert_to_numeric): New. (resolve_operator): If both sides are character based and -fdec is enabled convert Hollerith to character. If an operand is Hollerith, the other is numeric and -fdec is enabled convert to numeric. (resolve_ordinary_assign): Add check for -fdec-char-conversions for assignment of character literals. Mark Eggleston Jim MacArthur * gfortran.dg/dec-comparison-character_1.f90: New test. * gfortran.dg/dec-comparison-character_2.f90: New test. * gfortran.dg/dec-comparison-character_3.f90: New test. * gfortran.dg/dec-comparison-complex_1.f90: New test. * gfortran.dg/dec-comparison-complex_2.f90: New test. * gfortran.dg/dec-comparison-complex_3.f90: New test. * gfortran.dg/dec-comparison-int_1.f90: New test. * gfortran.dg/dec-comparison-int_2.f90: New test. * gfortran.dg/dec-comparison-int_3.f90: New test. * gfortran.dg/dec-comparison-real_1.f90: New test. * gfortran.dg/dec-comparison-real_2.f90: New test. * gfortran.dg/dec-comparison-real_3.f90: New test. * gfortran.dg/dec-comparison.f90: New test. Co-Authored-By: Jim MacArthur From-SVN: r278674 --- gcc/fortran/resolve.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'gcc/fortran/resolve.c') diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 2371a9e..278dad3 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -3900,6 +3900,42 @@ impure_function_callback (gfc_expr **e, int *walk_subtrees ATTRIBUTE_UNUSED, return 0; } +/* Return true if TYPE is character based, false otherwise. */ + +static int +is_character_based (bt type) +{ + return type == BT_CHARACTER || type == BT_HOLLERITH; +} + + +/* If expression is a hollerith, convert it to character and issue a warning + for the conversion. */ + +static void +convert_hollerith_to_character (gfc_expr *e) +{ + if (e->ts.type == BT_HOLLERITH) + { + gfc_typespec t; + gfc_clear_ts (&t); + t.type = BT_CHARACTER; + t.kind = e->ts.kind; + gfc_convert_type_warn (e, &t, 2, 1); + } +} + +/* Convert to numeric and issue a warning for the conversion. */ + +static void +convert_to_numeric (gfc_expr *a, gfc_expr *b) +{ + gfc_typespec t; + gfc_clear_ts (&t); + t.type = b->ts.type; + t.kind = b->ts.kind; + gfc_convert_type_warn (a, &t, 2, 1); +} /* Resolve an operator expression node. This can involve replacing the operation with a user defined function call. */ @@ -4100,6 +4136,15 @@ resolve_operator (gfc_expr *e) case INTRINSIC_EQ_OS: case INTRINSIC_NE: case INTRINSIC_NE_OS: + + if (flag_dec + && is_character_based (op1->ts.type) + && is_character_based (op2->ts.type)) + { + convert_hollerith_to_character (op1); + convert_hollerith_to_character (op2); + } + if (op1->ts.type == BT_CHARACTER && op2->ts.type == BT_CHARACTER && op1->ts.kind == op2->ts.kind) { @@ -4137,6 +4182,13 @@ resolve_operator (gfc_expr *e) if (op1->ts.type == BT_REAL && !gfc_boz2real (op2, op1->ts.kind)) return false; } + if (flag_dec + && op1->ts.type == BT_HOLLERITH && gfc_numeric_ts (&op2->ts)) + convert_to_numeric (op1, op2); + + if (flag_dec + && gfc_numeric_ts (&op1->ts) && op2->ts.type == BT_HOLLERITH) + convert_to_numeric (op2, op1); if (gfc_numeric_ts (&op1->ts) && gfc_numeric_ts (&op2->ts)) { @@ -10693,7 +10745,7 @@ resolve_ordinary_assign (gfc_code *code, gfc_namespace *ns) if ((gfc_numeric_ts (&lhs->ts) || lhs->ts.type == BT_LOGICAL) && rhs->ts.type == BT_CHARACTER - && rhs->expr_type != EXPR_CONSTANT) + && (rhs->expr_type != EXPR_CONSTANT || !flag_dec_char_conversions)) { /* Use of -fdec-char-conversions allows assignment of character data to non-character variables. This not permited for nonconstant -- cgit v1.1