https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66775
Bug ID: 66775 Summary: Allocatable function result type(t) produces segfault when uninitialized Product: gcc Version: 6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: vehre at gcc dot gnu.org Target Milestone: --- Created attachment 35917 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35917&action=edit Full pseudo code of failing example. The following code produces a segfault: ! { dg-do run } module test_alloc_func_mod implicit none type t integer :: i = 5 end type contains type(t) function t_init() ! { dg-warning "not set" } allocatable :: t_init end function end module test_alloc_func_mod program test_alloc_func use test_alloc_func_mod type(t), allocatable :: temp temp = t_init() ! <-- This derefs a null-pointer currently if (allocated (temp)) call abort() end program The pseudo code in question is: t_init () { struct t * __result_t_init; __result_t_init = 0B; // Setting NULL-pointer. return __result_t_init; } for t_init, and reduced to the essential line (full pseudo code is attached) struct t * temp; struct t * D.3388; temp = (struct t *) __builtin_malloc (4); D.3388 = t_init (); *temp = *D.3388; // D.3388 is NULL; dereferencing it here is hazardous. This error was experienced during patching of pr58586.