[PATCH, Fortran] Allow CHARACTER literals in assignments and DATA statements - for review

Mark Eggleston mark.eggleston@codethink.co.uk
Mon Oct 21 14:41:00 GMT 2019


This is an extension to support a legacy feature supported by other 
compilers such as flang and the sun compiler.  As I understand it this 
feature is associated with DEC so it enabled using 
-fdec-char-conversions and by -fdec.

It allows character literals to be assigned to numeric (INTEGER, REAL, 
COMPLEX) and LOGICAL variables by direct assignment or in DATA statements.

Please find attached the patch which includes changes to the gfortran 
manual.

Tested on x86_64 using "make check-fortran".

Change logs:

gcc/fortran/ChangeLog

     Jim MacArthur  <jim.macarthur@codethink.co.uk>
     Mark Eggleston  <mark.eggleston@codethink.com>

     * arith.c (hollerith2representation): Use OPT_Wcharacter_truncation in
     call to gfc_warning.  Add character2representation, gfc_character2int,
     gfc_character2real, gfc_character2complex and gfc_character2logical.
     * arith.h: Add prototypes for gfc_character2int, gfc_character2real,
     gfc_character2complex and gfc_character2logical.
     * expr.c (gfc_check_assign): Return true if left hand side is numeric
     or logical and the right hand side is character.
     * gfortran.texi: Add -fdec-char-conversions.
     * intrinsic.c (add_convdersions): Add conversions from character to
     integer, real, complex and logical types for their supported kinds.
     * invoke.texi: Add option to list of options.
     * invoke.texi: Add Character conversion subsection to Extensions
     section.
     * lang.opt: Add new option.
     * options.c (set_dec_flags): Add SET_BITFLAG for
     flag_dec_char_conversions.
     * resolve.c (resolve_ordindary_assign): Issue error if the left hand
     side is numeric or logical and the right hand side is a character
     variable.
     * simplify.c (gfc_convert_constant): Assign the conversion function
     depending on destination type.
     * trans-const.c (gfc_constant_to_tree): Use OPT_Wsurprising in
     gfc_warning allowing the warning to be switched off.

gcc/testsuite/ChangeLog

     Jim MacArthur <jim.macarthur@codethink.co.uk>
     Mark Eggleston <mark.eggleston@codethink.com>

     PR fortran/89103
     * gfortran.dg/dec_char_conversion_in_assignment_1.f90: New test.
     * gfortran.dg/dec_char_conversion_in_assignment_2.f90: New test.
     * gfortran.dg/dec_char_conversion_in_assignment_3.f90: New test.
     * gfortran.dg/dec_char_conversion_in_data_1.f90: New test.
     * gfortran.dg/dec_char_conversion_in_data_2.f90: New test.
     * gfortran.dg/dec_char_conversion_in_data_3.f90: New test.
     * gfortran.dg/dec_char_conversion_in_data_4.f90: New test.
     * gfortran.dg/hollerith5.f90: Add -Wsurprising to options.
     * gfortran.dg/hollerith_legacy.f90: Add -Wsurprising to options.
     * gfortran.dg/no_char_to_numeric_assign.f90: New test.

-- 
https://www.codethink.co.uk/privacy.html

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Allow-CHARACTER-literals-in-assignments-and-data-sta.patch
Type: text/x-patch
Size: 30243 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20191021/4c1e064a/attachment.bin>


More information about the Gcc-patches mailing list