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

            Bug ID: 128876
           Summary: {17 regression} free(): invalid pointer / SIGSEGV at
                    run time.with PDTs
           Product: gcc
           Version: 16.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pault at gcc dot gnu.org
  Target Milestone: ---

Created attachment 66225
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66225&action=edit
Reproducer for the bug

This bug is due to a bit of forgetfulness on my part an is fixed by the patch
in the next attachment.

It is a regression from r17 6335. Mea culpa!

Two further tests are to be found below.

Paul

! { dg-do compile }
! { dg-options "-fcheck=bounds" }
! CLASS dummy of a PDT type with -fcheck=bounds: ICE (gcc_unreachable) in
! gfc_trans_deferred_vars.  -fcheck=bounds defers the dummy's init, and
! the CLASS PDT branch there now requires !CLASS_DATA (sym)->attr.pointer,
! which is never true: _data of a class container always has attr.pointer;
! a CLASS POINTER entity is attr.class_pointer.
! Regression from r17 6335154826f, PDT (9/16) [PR82173]; works with 16.2.1.
! Found building fiats (example/learn-addition.F90, fpm debug profile).
module pdt_class_dummy_m
  implicit none
  type t(k)
    integer, kind :: k = kind(1.0)
    real(k) :: x
  end type
contains
  subroutine s (a)
    class(t), intent(in) :: a
    print *, a%x
  end subroutine
end module

and

! { dg-do run }
! Type-bound call on a PDT component of a PDT variable: ICE in
! gfc_spec_list_type (expr.cc), called from the hidden-PDT-argument code
! in gfc_conv_procedure_call, which takes the base variable's param_list
! ('m' of c_t) and looks it up in the component's type (h_t).
! Regression from r17 6335154826f, PDT (9/16) [PR82173]; works with 16.2.1.
! Found building fiats (src/fiats/training_configuration_s.F90:36).
module pdtmod
  implicit none
  type h_t(k)
    integer, kind :: k = kind(1.0)
    real(k) :: x = real(1, k)
  contains
    generic :: to_i => r4_to_i, r8_to_i
    procedure, private :: r4_to_i, r8_to_i
  end type
  type c_t(m)
    integer, kind :: m = kind(1.0)
    type(h_t(m)) :: h
  end type
contains
  pure integer function r4_to_i (self)
    class(h_t(kind(1.0))), intent(in) :: self
    r4_to_i = int (self%x)
  end function
  pure integer function r8_to_i (self)
    class(h_t(kind(1.0d0))), intent(in) :: self
    r8_to_i = 2 * int (self%x)
  end function
end module pdtmod
program p
  use pdtmod
  implicit none
  type(c_t) :: c
  type(c_t(kind(1.0d0))) :: d
  if (c%h%to_i () /= 1) stop 1
  if (d%h%to_i () /= 2) stop 2
end program

Reply via email to