nncarlson / petaca

Petaca: A collection of foundational Fortran modules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

23.12 not working with gfortran

nncarlson opened this issue · comments

The refactored parameter_list module code in version 23.12 triggers a bug in gfortran 12.3. Here's a small reproducer:

use parameter_list_type
call bug
contains
  subroutine bug
    type(parameter_list) :: params
    type(parameter_list), pointer :: plist
    plist => params%sublist('foo')
    call plist%set('bar', 'fubarfubarfubarfubarfubarfu')
  end subroutine
end

And its output when run:

$ ./a.out
malloc(): corrupted top size

Program received signal SIGABRT: Process abort signal.

Backtrace for this error:
#0  0x7f22ca21599f in ???
#1  0x7f22ca267834 in ???
#2  0x7f22ca2158ed in ???
#3  0x7f22ca1fd8fe in ???
#4  0x7f22ca1fe7cf in ???
#5  0x7f22ca2717a4 in ???
#6  0x7f22ca2751cb in ???
#7  0x7f22ca275e21 in ???
#8  0x7f22ca829590 in __parameter_list_type_MOD___final_parameter_list_type_Parameter_list
	at /opt/src/petaca/petaca/src/parameter_list_type.F90:1695
#9  0x401343 in ???
#10  0x401362 in ???
#11  0x401398 in ???
#12  0x7f22ca1ff149 in ???
#13  0x7f22ca1ff20a in ???
#14  0x4010d4 in ???
#15  0xffffffffffffffff in ???
Aborted (core dumped)

The abort happens when returning from the subroutine, and looks to be associated with finalization of the local params variable in some way.

Note that the current parameter_list unit tests all pass -- this failure was first observed in application code.

Running under valgrind shows a memory error, and even better is compiling with -fsanitize=address (requires a GCC configured with -enable-libsanitizer). The error is associated with an assignment between class(*) variables when the dynamic type of the rhs is character. I've submitted an error report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114827

I've worked around the bug by using sourced allocation instead. This eliminates the errors reported by libsanitizer, and hopefully resolves the error seen in the application code.