public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/31282] New: [gdb/fortran] logical type doesn't match documentation of TYPE_CODE_BOOL
@ 2024-01-23 20:27 vries at gcc dot gnu.org
  2024-01-24  1:10 ` [Bug fortran/31282] " tromey at sourceware dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: vries at gcc dot gnu.org @ 2024-01-23 20:27 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31282

            Bug ID: 31282
           Summary: [gdb/fortran] logical type doesn't match documentation
                    of TYPE_CODE_BOOL
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: fortran
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Consider the fortran type logical.

Here (
https://gcc.gnu.org/onlinedocs/gfortran/Internal-representation-of-LOGICAL-variables.html
) we read:
...
The Fortran standard does not specify how variables of LOGICAL type are
represented, beyond requiring that LOGICAL variables of default kind have the
same storage size as default INTEGER and REAL variables. The GNU Fortran
internal representation is as follows.

A LOGICAL(KIND=N) variable is represented as an INTEGER(KIND=N) variable,
however, with only two permissible values: 1 for .TRUE. and 0 for .FALSE.. Any
other integer value results in undefined behavior. 
...

OK, that's clear.  So how does this look in dwarf? Like so:
...
 <1><106>: Abbrev Number: 1 (DW_TAG_base_type)
    <107>   DW_AT_byte_size   : 4
    <108>   DW_AT_encoding    : 2       (boolean)
    <109>   DW_AT_name        : (indirect string, offset: 0x6): logical(kind=4)
...

So, is there a clue to tell what the values of true/false are, other than
looking at the producer string and searching for "GNU Fortran"?

DW_AT_encoding ATE_boolean has the description of "true or false", so that
doesn't seem to help much.

However, internally in gdb, this type is mapped onto:
...
/* * Boolean type.  0 is false, 1 is true, and other values are
   non-boolean (e.g. FORTRAN "logical" used as unsigned int).  */
OP (TYPE_CODE_BOOL)
...

That doesn't seem correct.  If .TRUE. is, say 2, then using TYPE_CODE_BOOL
tells us to view it as non-boolean.

AFAICT this doesn't cause any trouble because there's special handling to deal
with this discrepancy, for instance here in f-valprint.c:
...
          /* The Fortran standard doesn't specify how logical types are         
             represented.  Different compilers use different non zero           
             values to represent logical true.  */
          if (longval == 0)
            gdb_puts (f_decorations.false_name, stream);
          else
            gdb_puts (f_decorations.true_name, stream);
...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-01-25 14:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-23 20:27 [Bug fortran/31282] New: [gdb/fortran] logical type doesn't match documentation of TYPE_CODE_BOOL vries at gcc dot gnu.org
2024-01-24  1:10 ` [Bug fortran/31282] " tromey at sourceware dot org
2024-01-24 11:11 ` vries at gcc dot gnu.org
2024-01-24 12:16 ` vries at gcc dot gnu.org
2024-01-24 13:49 ` vries at gcc dot gnu.org
2024-01-24 16:58 ` tromey at sourceware dot org
2024-01-25 12:29 ` vries at gcc dot gnu.org
2024-01-25 14:57 ` tromey at sourceware dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).