]> git.ipfire.org Git - thirdparty/gcc.git/commit
fortran: Fix debug info for unsigned(kind=1) and unsigned(kind=4) [PR120193]
authorJakub Jelinek <jakub@redhat.com>
Sat, 10 May 2025 19:20:09 +0000 (21:20 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 10 May 2025 19:20:09 +0000 (21:20 +0200)
commit512371d786e70d27dbaef38d60e9036c11f458c6
tree5a864f6110a3b52fdc394964987287d7d802978c
parent5d9e66493afaa9b0450f03b53f0cb99afb411816
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  <jakub@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.
gcc/fortran/trans-types.cc
gcc/testsuite/gfortran.dg/guality/pr120193.f90 [new file with mode: 0644]