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

            Bug ID: 116668
           Summary: A very strange error when trying to copy substrings
                    from a select type generic
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jordan4ibanez at gmail dot com
  Target Milestone: ---

This was a simple test I was doing making a threading library for Fortran on
the latest for Linux Mint 22 on gfortran 14.
I had talked to one of the devs of the LLVM fortran compiler to solve this
problem. But I still wanted to show this because it told me to report it.

I have made the mistake of not using the report function of gfortran. If you
would like more in depth review of this, here is a freeze frame of the fix I
have mentioned:
https://github.com/jordan4ibanez/Formine/tree/cbc3f7c602b9acaf84bb405f0ab7959526a8adbb

BEGIN REPORT

BEGIN TERMINAL OUTPUT

testament.f90                          done.
thread_filo_queue.f90                  failed.
[  5%] Compiling...
././src/bindings/thread/thread_filo_queue.f90:239:78:

  239 |         new_queue_element_pointer%string(1:string_len) =
generic(1:string_len)
      |                                                                        
     1
internal compiler error: Segmentation fault
0x15967a3 crash_signal
        ../../src/gcc/toplev.cc:319
0x79f8c244531f ???
        ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
0xf04d67 gfc_conv_scalarized_array_ref
        ../../src/gcc/fortran/trans-array.cc:3938
0xf05c36 gfc_conv_array_ref(gfc_se*, gfc_array_ref*, gfc_expr*, locus*)
        ../../src/gcc/fortran/trans-array.cc:4094
0xf48146 gfc_conv_variable
        ../../src/gcc/fortran/trans-expr.cc:3181
0xf4e918 gfc_trans_assignment_1
        ../../src/gcc/fortran/trans-expr.cc:12273
0xef9b27 trans_code
        ../../src/gcc/fortran/trans.cc:2363
0xf99038 gfc_trans_block_construct(gfc_code*)
        ../../src/gcc/fortran/trans-stmt.cc:2377
0xef9bf7 trans_code
        ../../src/gcc/fortran/trans.cc:2459
0xf99038 gfc_trans_block_construct(gfc_code*)
        ../../src/gcc/fortran/trans-stmt.cc:2377
0xef9bf7 trans_code
        ../../src/gcc/fortran/trans.cc:2459
0xf8f7e4 gfc_trans_select_type_cases
        ../../src/gcc/fortran/trans-stmt.cc:3020
0xf9a9ad gfc_trans_select_type(gfc_code*)
        ../../src/gcc/fortran/trans-stmt.cc:3729
0xef9967 trans_code
        ../../src/gcc/fortran/trans.cc:2479
0xf99038 gfc_trans_block_construct(gfc_code*)
        ../../src/gcc/fortran/trans-stmt.cc:2377
0xef9bf7 trans_code
        ../../src/gcc/fortran/trans.cc:2459
0xf2ef2b gfc_generate_function_code(gfc_namespace*)
        ../../src/gcc/fortran/trans-decl.cc:7879
0xefef41 gfc_generate_module_code(gfc_namespace*)
        ../../src/gcc/fortran/trans.cc:2785
0xea188d translate_all_program_units
        ../../src/gcc/fortran/parse.cc:7086
0xea188d gfc_parse_file()
        ../../src/gcc/fortran/parse.cc:7413
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <file:///usr/share/doc/gcc-14/README.Bugs> for instructions.
<ERROR> Compilation failed for object "
src_bindings_thread_thread_filo_queue.f90.o "
<ERROR> stopping due to failed compilation
STOP 1
make: *** [Makefile:27: test] Error 1

END TERMINAL OUTPUT

BEGIN SOURCE CODE

  function queue_data_constructor(generic) result(new_queue_element_pointer)
    implicit none

    type(queue_data), pointer :: new_queue_element_pointer
    class(*), intent(in), target :: generic

    allocate(new_queue_element_pointer)

    select type(generic)
     type is (integer(c_int))
      new_queue_element_pointer%type = QUEUE_I32
      allocate(new_queue_element_pointer%i32)
      new_queue_element_pointer%i32 = generic

     type is (integer(c_int64_t))
      new_queue_element_pointer%type = QUEUE_I64
      allocate(new_queue_element_pointer%i64)
      new_queue_element_pointer%i64 = generic

     type is (real(c_float))
      new_queue_element_pointer%type = QUEUE_F32
      allocate(new_queue_element_pointer%f32)
      new_queue_element_pointer%f32 = generic

     type is (real(c_double))
      new_queue_element_pointer%type = QUEUE_F64
      allocate(new_queue_element_pointer%f64)
      new_queue_element_pointer%f64 = generic

     type is (logical)
      new_queue_element_pointer%type = QUEUE_BOOL
      allocate(new_queue_element_pointer%bool)
      new_queue_element_pointer%bool = generic

     type is (character(len = *, kind = c_char))
      new_queue_element_pointer%type = QUEUE_STRING
      associate (string_len => len(generic))
        allocate(character(len = string_len, kind = c_char) ::
new_queue_element_pointer%string)
        new_queue_element_pointer%string(1:string_len) = generic(1:string_len)
      end associate

     class default
      !? We will check if this thing is a pointer.
      !! If it's not, it's going to blow up.
      new_queue_element_pointer%type = QUEUE_GENERIC
      new_queue_element_pointer%generic => generic
    end select
  end function queue_data_constructor

END SOURCE CODE

END REPORT

Reply via email to