Bug 116468 - Segmentation fault at intrinsic assignment to allocatable array component of derived type with kind type parameter
Summary: Segmentation fault at intrinsic assignment to allocatable array component of ...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 14.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: PDT
  Show dependency treegraph
 
Reported: 2024-08-23 01:43 UTC by Damian Rouson
Modified: 2024-08-26 03:09 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2024-08-23 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Damian Rouson 2024-08-23 01:43:13 UTC
A program compiled with gfortran terminates with a segmentation fault at an intrinsic assignment to an allocatable array component of a derived type with a kind type parameter.  Please see below.  I tried several workarounds, including replacing the intrinsic assignment with a type-bound defined assignment, a non-type-bound defined assignment, and a source allocation.  I also tried compiling code below with gfortran 12, 13, and 14.  The only workaround that eliminates the segmentation fault is switching to source allocation.  The code below terminates normally with the NAG and LLVM Flang (Flang-new) compilers. 

% cat reproducer.f90     
  implicit none

  type foo_t(k)
    integer, kind :: k
    real(k), allocatable :: bar(:)
  end type

  type(foo_t(kind(0.))) foo
  
  foo%bar = [0.]
end

% gfortran reproducer.f90

% ./a.out                

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x102dfad2f
#1  0x102df9d83
#2  0x194afa583
#3  0x1027c7f4b
zsh: segmentation fault  ./a.out

% gfortran --version        
GNU Fortran (Homebrew GCC 14.1.0_2) 14.1.0
Comment 1 Jerry DeLisle 2024-08-23 02:15:50 UTC
Confirmed on latest trunk.

$ gfc -g pr116468.f90 
$ ./a.out 

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x7f066e64fcff in ???
#1  0x401173 in MAIN__
	at /home/jerry/dev/test/pr116468/pr116468.f90:10
#2  0x4011b4 in main
	at /home/jerry/dev/test/pr116468/pr116468.f90:11
Segmentation fault (core dumped)
Comment 2 kargls 2024-08-23 02:54:42 UTC
(In reply to Damian Rouson from comment #0)

>   type foo_t(k)
>     integer, kind :: k
>     real(k), allocatable :: bar(:)
>   end type

Unfortunately, PDTs are broken in gfortran.  There are 58 open bug reports.