Bug 115193 - using indices with character type within a select type causes ICE
Summary: using indices with character type within a select type causes ICE
Status: RESOLVED DUPLICATE of bug 114874
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: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2024-05-22 17:18 UTC by Ryan Mulhall
Modified: 2024-05-22 17:55 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan Mulhall 2024-05-22 17:18:18 UTC
This bug seems to be a regression from past versions, gfortran 10-13 worked without error.

Bug #100860 describes a similar issue, but gfortran 14.1.0 generates an ICE while the original issue had a seg fault.

I believe the error is coming from the usage of indices to get a substring from a class(*) type.

I've simplified the test program from the original report to be more compact:


program test

  implicit none

  character (len=:), allocatable :: str

  str = "examplestring"
  call foo(str,13)

  contains

  subroutine foo(bar, strlen)
    class(*), intent (in)  :: bar
    integer,  intent (in)  :: strlen
   
    select type (bar)
    type is (character(*))
      print *, 'String is "', bar(1:strlen), '"' ! fails here 
    class default
      print *, "Not the right type"
    end select
  end subroutine

end program test
Comment 1 Ryan Mulhall 2024-05-22 17:22:36 UTC
Error output:


test2.F90:18:43:

   18 |       print *, 'String is "', bar(1:strlen), '"' ! fails here
      |                                           1
internal compiler error: Segmentation fault
0xe5329f crash_signal
	../.././gcc/toplev.cc:319
0x8ced67 gfc_conv_scalarized_array_ref
	../.././gcc/fortran/trans-array.cc:3938
0x8cfc46 gfc_conv_array_ref(gfc_se*, gfc_array_ref*, gfc_expr*, locus*)
	../.././gcc/fortran/trans-array.cc:4094
0x90a946 gfc_conv_variable
	../.././gcc/fortran/trans-expr.cc:3189
0x90d6c2 gfc_conv_expr_reference(gfc_se*, gfc_expr*)
	../.././gcc/fortran/trans-expr.cc:9943
0x9336f2 gfc_trans_transfer(gfc_code*)
	../.././gcc/fortran/trans-io.cc:2609
0x8c48c7 trans_code
	../.././gcc/fortran/trans.cc:2583
0x9312d9 build_dt
	../.././gcc/fortran/trans-io.cc:2053
0x8c4827 trans_code
	../.././gcc/fortran/trans.cc:2555
0x950234 gfc_trans_block_construct(gfc_code*)
	../.././gcc/fortran/trans-stmt.cc:2377
0x8c4aa7 trans_code
	../.././gcc/fortran/trans.cc:2459
0x9472dc gfc_trans_select_type_cases
	../.././gcc/fortran/trans-stmt.cc:3020
0x9519a9 gfc_trans_select_type(gfc_code*)
	../.././gcc/fortran/trans-stmt.cc:3729
0x8c4a07 trans_code
	../.././gcc/fortran/trans.cc:2479
0x950234 gfc_trans_block_construct(gfc_code*)
	../.././gcc/fortran/trans-stmt.cc:2377
0x8c4aa7 trans_code
	../.././gcc/fortran/trans.cc:2459
0x8f4b24 gfc_generate_function_code(gfc_namespace*)
	../.././gcc/fortran/trans-decl.cc:7880
0x8f4914 gfc_generate_contained_functions
	../.././gcc/fortran/trans-decl.cc:5995
0x8f4914 gfc_generate_function_code(gfc_namespace*)
	../.././gcc/fortran/trans-decl.cc:7812
0x866986 translate_all_program_units
	../.././gcc/fortran/parse.cc:7099
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Comment 2 anlauf 2024-05-22 17:55:45 UTC
This bug has already been reported as pr114874 and just been fixed last week.

*** This bug has been marked as a duplicate of bug 114874 ***