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

            Bug ID: 125172
           Summary: complex-part-ref, associate construct, and contained
                    function leads to wrong code
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kargl at gcc dot gnu.org
  Target Milestone: ---

Created attachment 64360
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64360&action=edit
Demonstrate wrong code is generated

The attached testcase leads to wrong code.

It is important to note that three conditions
seem to be needed.  The associate construct
is used with a contained function, and a
complex-part-ref is taken.

   associate (r => (f(cmplx(x, h, 8))) )
      if (r%im == 0) stop 1
!
! If above line is commented out and the below line
! is uncommented, then the code executes without
! hitting 'stop 2'
!
!      if (aimag(r) == 0) stop 2
   end associate


Note f() has a type of complex(8).  The above 
translates to 

  {
    complex(kind=4) r;

    {
      complex(kind=8) D.4686;

      D.4686 = COMPLEX_EXPR <x, h>;
      r = COMPLEX_EXPR <(real(kind=4)) REALPART_EXPR <SAVE_EXPR <((f
(&D.4686)))>>, (real(kind=4)) IMAGPART_EXPR <SAVE_EXPR <((f (&D.4686)))>>>;
    }
    if (IMAGPART_EXPR <r> == 0.0)
      {
        _gfortran_stop_numeric (1, 0);
      }

The associate-name has been given the type complex(4)!

Reply via email to