https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120193

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:512371d786e70d27dbaef38d60e9036c11f458c6

commit r16-516-g512371d786e70d27dbaef38d60e9036c11f458c6
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Sat May 10 21:20:09 2025 +0200

    fortran: Fix debug info for unsigned(kind=1) and unsigned(kind=4)
[PR120193]

    As the following testcase shows, debug info for unsigned(kind=1)
    and unsigned(kind=4) vars is wrong while unsigned(kind=2), unsigned(kind=8)
    and unsigned(kind=16) look right.
    Instead of objects having unsigned(kind=1) type they have character(kind=1)
    and instead of unsigned(kind=4) they have character(kind=4).
    This means in gdb e.g. unsigned(kind=1) :: a(2) variable initialized to
    97 will print as 'aa' rather than (97, 97) etc.
    While there can be just one unsigned_char_type_node and one
    unsigned_type_node type, each can have arbitrary number of variants
    (e.g. consider C
    typedef unsigned char uc;
    where uc is a variant type to unsigned char) or even distinct types
    with different TYPE_MAIN_VARIANT.

    The following patch uses a variant of the character(kind=4) type
    for unsigned(kind=4) and a distinct type based on character(kind=1)
    type for unsigned(kind=1).  The reason for the latter is that
    unsigned_char_type_node has TYPE_STRING_FLAG set on it, so it has
    DW_AT_encoding DW_ATE_unsigned_char rather than DW_ATE_unsigned and
    so the debugger then likes to print it as characters rather than numbers.
    That is IMHO in Fortran desirable for character(kind=1) but not for
    unsigned(kind=1).  I've made sure TYPE_CANONICAL of the unsigned(kind=1)
    type is still character(kind=1), so they are considered compatible by
    the middle-end also e.g. for aliasing etc.

    2025-05-10  Jakub Jelinek  <ja...@redhat.com>

            PR fortran/120193
            * trans-types.cc (gfc_init_types): For flag_unsigned use
            build_distinct_type_copy or build_variant_type_copy from
            gfc_character_types[index_char] if index_char > -1 instead of
            gfc_character_types[index_char] or
            gfc_build_unsigned_type (&gfc_unsigned_kinds[index]).

            * gfortran.dg/guality/pr120193.f90: New test.

Reply via email to