public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/102599] New: Wrong simplification of inquiry parameters for complex arrays
@ 2021-10-04 20:06 anlauf at gcc dot gnu.org
  2021-10-04 21:33 ` [Bug fortran/102599] " anlauf at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-10-04 20:06 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102599
           Summary: Wrong simplification of inquiry parameters for complex
                    arrays
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anlauf at gcc dot gnu.org
  Target Milestone: ---

Consider:

program p
  implicit none
  complex, parameter :: x(2) = 1
  real,    parameter :: r(*) = x%re
  real,    parameter :: i(*) = x%im
  print *, r,    all(r    == 1) ! wrong
  print *, i,    all(i    == 0) ! wrong
  print *, x%re, all(x%re == 1) ! OK
  print *, x%im, all(x%im == 0) ! OK
end

This prints:

   1.00000000       0.00000000     T
   1.00000000       0.00000000     F
   1.00000000       1.00000000     T
   0.00000000       0.00000000     T

The first two lines should be identical to the last two.

The dump-tree has:

  static real(kind=4) r[2] = {__complex__ (1.0e+0, 0.0), __complex__ (1.0e+0,
0.0)};
  static real(kind=4) i[2] = {__complex__ (1.0e+0, 0.0), __complex__ (1.0e+0,
0.0)};
  static complex(kind=4) x[2] = {__complex__ (1.0e+0, 0.0), __complex__
(1.0e+0, 0.0)};

which is nonsense for r, i.

Furthermore, all(x%re == 1) and all(x%im == 0) are not simplified, but that's
another story...

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

* [Bug fortran/102599] Wrong simplification of inquiry parameters for complex arrays
  2021-10-04 20:06 [Bug fortran/102599] New: Wrong simplification of inquiry parameters for complex arrays anlauf at gcc dot gnu.org
@ 2021-10-04 21:33 ` anlauf at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-10-04 21:33 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-valid-code

--- Comment #1 from anlauf at gcc dot gnu.org ---
Replacing

  real,    parameter :: r(*) = x%re
  real,    parameter :: i(*) = x%im

by

  real,    parameter :: r(*) = real (x)
  real,    parameter :: i(*) = imag (x)

fixes things.

Similarly, the scalar variant

  real,    parameter :: y    = real (x(1))
  real,    parameter :: z    = imag (x(1))
  print *, y, z

works fine, but

  real,    parameter :: y    = x(1)%re
  real,    parameter :: z    = x(1)%im
  print *, y, z

ICEs in trans-array::gfc_get_descriptor_field, since we miss the
simplification.

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

end of thread, other threads:[~2021-10-04 21:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-04 20:06 [Bug fortran/102599] New: Wrong simplification of inquiry parameters for complex arrays anlauf at gcc dot gnu.org
2021-10-04 21:33 ` [Bug fortran/102599] " anlauf 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).