Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29590 Diskussionen

Regression: defined assignment called multiple times

WileyOne
Neuer Beitragender I
130Aufrufe

Compiler: ifx (IFX) 2026.0.0

OS: Ubuntu 22.04.05 LTS (Jammy Jellyfish)

The most recent compiler release fixed a bug I reported a while back (many thanks compiler team). Slightly modifying that example, however, still reveals problems. In short, the defined assignment is called multiple times when it should only be called once. Here is a minimal example:

module Classes_Header

    implicit none

    type :: class1
        integer :: ii
        contains
        generic,   public  :: assignment(=) => copy
        procedure, private :: copy
    end type

    type :: class2
        character(:), allocatable :: name
        type(class1) :: myClass1
    end type

    type :: class3
        type(class2) :: myClass2
    end type

    type :: class4
        type(class3), allocatable :: myClass3
    end type

    contains

    subroutine copy(lhs,rhs)
        class(class1), intent(out) :: lhs
        class(class1), intent(in)  :: rhs

        lhs%ii = 7
        print *, 'copy was called'
    end subroutine

    function constructor() result(this)
        type(class4) :: this

        allocate(this%myClass3)
        this%myClass3%myClass2%myClass1%ii = 42
    end function

end module

program main

    use Classes_Header

    implicit none
    type(class4) :: myClass4

    myClass4 = constructor()

end program

The defined assignment should only be called once, but it runs twice:

WileyOne_0-1782928752194.png

There are 2 differences from the previous bug: a "name" component was added to "class2", and the "class3" component of "class4" is "type" rather than "class". The example also exhibits the issue when the latter is "class"; both are included below.

This is a regression because this specific example worked with a previous compiler version (2024.2.0 at least); that is, the defined assignment was only called once.

While the defined assignment being called an extra time may seem like small potatoes, it is causing nasty segfaults in my actual code. Random memory is being accessed, which really ruins your day.

Please let me know if I can provide additional clarification or examples.

0 Kudos
0 Antworten
Antworten