public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/114618] New: Format produces incorrect output when contains 1x, ok when uses " "
@ 2024-04-06  3:05 urbanjost at comcast dot net
  2024-04-06  9:11 ` [Bug libfortran/114618] " anlauf at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: urbanjost at comcast dot net @ 2024-04-06  3:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114618
           Summary: Format produces incorrect output when contains 1x, ok
                    when uses " "
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: urbanjost at comcast dot net
  Target Milestone: ---

The format gen2 does what I would expect the format gen1 does,
but get very strange output when use 1x (in gen1)  instead of space character
(in gen2).

program tryit
   implicit none
   integer, parameter :: wp = kind(0d0)
   real(kind=wp) :: pi  =
3.14159265358979323846264338327950288419716939937510582097494459230_wp
   character(len=*), parameter:: gen1 = '(19("."),t1,g0,1x,t21,g0)'
   character(len=*), parameter:: gen2 = '(19("."),t1,g0," ",t21,g0)'
   character(len=:), allocatable :: fmt
   integer :: i, j
   do i=1,2
      select case(i)
      case(1); fmt=gen1
      case(2); fmt=gen2
      end select
      do j=1,2
         write (*, fmt) 'PI', pi
         write (*, fmt) 'REAL(PI)', real(pi)
         write (*, fmt) 'DBLE(PI)', dble(pi)
         write (*, fmt) 'RADIX', radix(pi)
         write (*, fmt) 'RANGE', range(pi)
         write (*, fmt) 'PRECISION', precision(pi)
         write (*,'(80("-"))')
      enddo
   enddo
end program tryit

PI.................^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@ 3.1415926535897931
REAL(PI)...........^@^@^@^@^@^@^@^@^@^@^@ 3.14159274
DBLE(PI)...........^@^@^@^@^@^@^@^@^@^@^@ 3.1415926535897931
RADIX..............^@^@^@^@^@^@^@^@^@^@^@ 3. 2
RANGE..............^@^@^@^@^@^@^@^@^@^@^@ 3. 307
PRECISION..........^@^@^@^@^@^@^@^@^@^@ 15
--------------------------------------------------------------------------------
PI.................----------------- 3.1415926535897931
REAL(PI)...........----------- 3.14159274
DBLE(PI)...........----------- 3.1415926535897931
RADIX..............----------- 3. 2
RANGE..............----------- 3. 307
PRECISION..........---------- 15
--------------------------------------------------------------------------------
PI ................ 3.1415926535897931
REAL(PI) .......... 3.14159274
DBLE(PI) .......... 3.1415926535897931
RADIX ............. 2
RANGE ............. 307
PRECISION ......... 15
--------------------------------------------------------------------------------
PI ................ 3.1415926535897931
REAL(PI) .......... 3.14159274
DBLE(PI) .......... 3.1415926535897931
RADIX ............. 2
RANGE ............. 307
PRECISION ......... 15
--------------------------------------------------------------------------------

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

* [Bug libfortran/114618] Format produces incorrect output when contains 1x, ok when uses " "
  2024-04-06  3:05 [Bug fortran/114618] New: Format produces incorrect output when contains 1x, ok when uses " " urbanjost at comcast dot net
@ 2024-04-06  9:11 ` anlauf at gcc dot gnu.org
  2024-04-06 13:59 ` jvdelisle at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-04-06  9:11 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|fortran                     |libfortran
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=109358

--- Comment #1 from anlauf at gcc dot gnu.org ---
Likely a dup of pr109358.

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

* [Bug libfortran/114618] Format produces incorrect output when contains 1x, ok when uses " "
  2024-04-06  3:05 [Bug fortran/114618] New: Format produces incorrect output when contains 1x, ok when uses " " urbanjost at comcast dot net
  2024-04-06  9:11 ` [Bug libfortran/114618] " anlauf at gcc dot gnu.org
@ 2024-04-06 13:59 ` jvdelisle at gcc dot gnu.org
  2024-04-07 18:47 ` jvdelisle at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2024-04-06 13:59 UTC (permalink / raw)
  To: gcc-bugs

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

Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jvdelisle at gcc dot gnu.org

--- Comment #2 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
Possibly a dup. I will try to get a closer look later today.

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

* [Bug libfortran/114618] Format produces incorrect output when contains 1x, ok when uses " "
  2024-04-06  3:05 [Bug fortran/114618] New: Format produces incorrect output when contains 1x, ok when uses " " urbanjost at comcast dot net
  2024-04-06  9:11 ` [Bug libfortran/114618] " anlauf at gcc dot gnu.org
  2024-04-06 13:59 ` jvdelisle at gcc dot gnu.org
@ 2024-04-07 18:47 ` jvdelisle at gcc dot gnu.org
  2024-04-14  0:17 ` jvdelisle at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2024-04-07 18:47 UTC (permalink / raw)
  To: gcc-bugs

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

Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #3 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
It is a duplicate of 113897 which I am still workimng on as i get time.

*** This bug has been marked as a duplicate of bug 113897 ***

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

* [Bug libfortran/114618] Format produces incorrect output when contains 1x, ok when uses " "
  2024-04-06  3:05 [Bug fortran/114618] New: Format produces incorrect output when contains 1x, ok when uses " " urbanjost at comcast dot net
                   ` (2 preceding siblings ...)
  2024-04-07 18:47 ` jvdelisle at gcc dot gnu.org
@ 2024-04-14  0:17 ` jvdelisle at gcc dot gnu.org
  2024-04-14 18:14 ` jvdelisle at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2024-04-14  0:17 UTC (permalink / raw)
  To: gcc-bugs

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

Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|DUPLICATE                   |---
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-04-14

--- Comment #4 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
Reopening this. I started working on the 'duplicate' portion of this which is
the 1X vs ' ' portion of it.  Then I realized the first sets of output have a
bunch of garbage in the output. My first thought was the allocatable strings
aspect of this.

I reduced this by removing those aspects of the original post to get the
following.

program tryit
   implicit none
   integer, parameter :: wp = kind(0d0)
   real(kind=wp) :: pi  =
3.14159265358979323846264338327950288419716939937510582097494459230_wp
   character(40) gen1
   character(40) gen2


   gen1 = '(19("."),t1,g0,1x,t21,g0)'
   gen2 = '(19("."),t1,g0," ",t21,g0)'

   write (*, gen1) 'PI', pi
   write (*, gen1) 'REAL(PI)', real(pi)
   write (*, gen1) 'DBLE(PI)', dble(pi)
   write (*, gen1) 'RADIX', radix(pi)
   write (*, gen1) 'RANGE', range(pi)
   write (*, gen1) 'PRECISION', precision(pi)
   write (*,'(80("-"))')
   write (*, gen2) 'PI', pi
   write (*, gen2) 'REAL(PI)', real(pi)
   write (*, gen2) 'DBLE(PI)', dble(pi)
   write (*, gen2) 'RADIX', radix(pi)
   write (*, gen2) 'RANGE', range(pi)
   write (*, gen2) 'PRECISION', precision(pi)
   write (*,'(80("-"))')
end program tryit

Which gives:

$ ./a.out 
PI................. 3.1415926535897931
REAL(PI)........... 3.14159274
DBLE(PI)........... 3.1415926535897931
RADIX.............. 3. 2
RANGE.............. 3. 307
PRECISION.......... 15
--------------------------------------------------------------------------------
PI ................ 3.1415926535897931
REAL(PI) .......... 3.14159274
DBLE(PI) .......... 3.1415926535897931
RADIX ............. 2
RANGE ............. 307
PRECISION ......... 15
--------------------------------------------------------------------------------

I will focus on the 1X vs ' ' aspect of this as it fits into the 113897 that I
am currently working.

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

* [Bug libfortran/114618] Format produces incorrect output when contains 1x, ok when uses " "
  2024-04-06  3:05 [Bug fortran/114618] New: Format produces incorrect output when contains 1x, ok when uses " " urbanjost at comcast dot net
                   ` (3 preceding siblings ...)
  2024-04-14  0:17 ` jvdelisle at gcc dot gnu.org
@ 2024-04-14 18:14 ` jvdelisle at gcc dot gnu.org
  2024-04-14 18:18 ` jvdelisle at gcc dot gnu.org
  2024-04-16 22:17 ` jvdelisle at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2024-04-14 18:14 UTC (permalink / raw)
  To: gcc-bugs

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

Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |jvdelisle at gcc dot gnu.org

--- Comment #5 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
A further reduction:

program tryit
   implicit none
   integer, parameter :: wp = kind(0d0)
   real(kind=wp) :: pi  =
3.14159265358979323846264338327950288419716939937510582097494459230_wp
   character(40) gen1
   character(40) gen2
   gen1 = '(19("."),t1,g0,1x,t21,g0)'
   gen2 = '(19("."),t1,g0," ",t21,g0)'

   write (*, gen1) 'RADIX', radix(pi)
   write (*, gen1) 'RANGE', range(pi)
   write (*,'(80("-"))')
   write (*, gen2) 'RADIX', radix(pi)
   write (*, gen2) 'RANGE', range(pi)
end program tryit

This is indeed ugly. Note the embedded NULLs.

$ ./a.out >newdata
$ xxd newdata
00000000: 5241 4449 582e 2e2e 2e2e 2e2e 2e2e 2e2e  RADIX...........
00000010: 2e2e 2e00 0000 0000 0000 0000 0000 0000  ................
00000020: 0020 320a 5241 4e47 452e 2e2e 2e2e 2e2e  . 2.RANGE.......
00000030: 2e2e 2e2e 2e2e 2e00 0000 0000 0000 0000  ................
00000040: 0000 0000 0020 3330 370a 2d2d 2d2d 2d2d  ..... 307.------
00000050: 2d2d 2d2d 2d2d 2d2d 2d2d 2d2d 2d2d 2d2d  ----------------
00000060: 2d2d 2d2d 2d2d 2d2d 2d2d 2d2d 2d2d 2d2d  ----------------
00000070: 2d2d 2d2d 2d2d 2d2d 2d2d 2d2d 2d2d 2d2d  ----------------
00000080: 2d2d 2d2d 2d2d 2d2d 2d2d 2d2d 2d2d 2d2d  ----------------
00000090: 2d2d 2d2d 2d2d 2d2d 2d2d 0a52 4144 4958  ----------.RADIX
000000a0: 202e 2e2e 2e2e 2e2e 2e2e 2e2e 2e2e 2032   ............. 2
000000b0: 0a52 414e 4745 202e 2e2e 2e2e 2e2e 2e2e  .RANGE .........
000000c0: 2e2e 2e2e 2033 3037 0a                   .... 307.

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

* [Bug libfortran/114618] Format produces incorrect output when contains 1x, ok when uses " "
  2024-04-06  3:05 [Bug fortran/114618] New: Format produces incorrect output when contains 1x, ok when uses " " urbanjost at comcast dot net
                   ` (4 preceding siblings ...)
  2024-04-14 18:14 ` jvdelisle at gcc dot gnu.org
@ 2024-04-14 18:18 ` jvdelisle at gcc dot gnu.org
  2024-04-16 22:17 ` jvdelisle at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2024-04-14 18:18 UTC (permalink / raw)
  To: gcc-bugs

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

Jerry DeLisle <jvdelisle at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |NEW
         Depends on|                            |113897, 109358


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109358
[Bug 109358] Wrong formatting with T-descriptor during stream output
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113897
[Bug 113897] Consecutive tab and/or nX edits in format are not processed
correctly.

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

* [Bug libfortran/114618] Format produces incorrect output when contains 1x, ok when uses " "
  2024-04-06  3:05 [Bug fortran/114618] New: Format produces incorrect output when contains 1x, ok when uses " " urbanjost at comcast dot net
                   ` (5 preceding siblings ...)
  2024-04-14 18:18 ` jvdelisle at gcc dot gnu.org
@ 2024-04-16 22:17 ` jvdelisle at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jvdelisle at gcc dot gnu.org @ 2024-04-16 22:17 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jerry DeLisle <jvdelisle at gcc dot gnu.org> ---
Created attachment 57965
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57965&action=edit
Preliminary patch to fix several issues.

The attached patch is very preliminary and appears to fix the X format issue
and does some code factoring. I have yet to explore the same situation with TR
following the 19 '.' printed.  This also fixes the problem with embedded
garbage in the output.

It does regression test with the new test cases, so getting close.

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

end of thread, other threads:[~2024-04-16 22:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-06  3:05 [Bug fortran/114618] New: Format produces incorrect output when contains 1x, ok when uses " " urbanjost at comcast dot net
2024-04-06  9:11 ` [Bug libfortran/114618] " anlauf at gcc dot gnu.org
2024-04-06 13:59 ` jvdelisle at gcc dot gnu.org
2024-04-07 18:47 ` jvdelisle at gcc dot gnu.org
2024-04-14  0:17 ` jvdelisle at gcc dot gnu.org
2024-04-14 18:14 ` jvdelisle at gcc dot gnu.org
2024-04-14 18:18 ` jvdelisle at gcc dot gnu.org
2024-04-16 22:17 ` jvdelisle at gcc dot gnu.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).