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

            Bug ID: 128093
           Summary: [17 Regression] pdt_bug9.f90 / pdt_bug10.f90 ICE after
                    r17-5389-g40c4b9dcd9be3e
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: iains at gcc dot gnu.org
                CC: pault at gcc dot gnu.org
  Target Milestone: ---

r17-5389-g40c4b9dcd9be3e introduces a fix for fortran/82173, but the fix,
itself contains a new problem.

trans-expr.cc:7830 : gfc_replace_expr (init_expr, var); 

this free()s var ending its lifetime.

however, lines 7832-35 then go on to use var, which is UB.  The consequence
seems to be quite platform dependent (nature of UB) but it fails consistently
on modern Darwin (likely because of the new allocator).

The remedy is to use init_expr instead of var in those lines .. 
patch under test (that does ^^^ )


LLM-reduced testcase:

module mj
  type :: base(k, n)
    integer, kind :: k = 4
    integer, len :: n = 1
    real(k) :: v(n)
  end type
end module
program j1
  use mj
  class(*), allocatable :: u
  allocate (base(16, 4) :: u)
end

Reply via email to