https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69055
--- Comment #3 from Steve Kargl <sgk at troutmask dot apl.washington.edu> --- On Sat, Dec 26, 2015 at 05:43:56PM +0000, sgk at troutmask dot apl.washington.edu wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69055 > > --- Comment #2 from Steve Kargl <sgk at troutmask dot apl.washington.edu> --- > On Sat, Dec 26, 2015 at 05:15:27PM +0000, kargl at gcc dot gnu.org wrote: > > > > > > N=daten(j)%daten > > > > > > > The code is non-conforming Fortran. daten(j)%daten is used uninitialized. > > gfortan can do anything it wants with the code, including throwing an > > error. > > > > After making the code at least conform to the Fortran > standard and removing the overuse of "daten", the error > still occurs. > > subroutine tstd > implicit none > integer n > type a > real(8) b > end type a > type(a) :: daten(10) > integer :: j = 1 > daten(:)%b = 42 > n = daten(j)%b > end subroutine tstd > > The -fdump-tree-original output is > > tstd () > { > struct a daten[10]; > static integer(kind=4) j = 1; > integer(kind=4) n; > > { > integer(kind=4) S.0; > > S.0 = 1; > while (1) > { > if (S.0 > 10) goto L.1; > daten[S.0 + -1].b = 4.2e+1; > S.0 = S.0 + 1; > } > L.1:; > } > n = (integer(kind=4)) daten[NON_LVALUE_EXPR <j> + -1].b; > } > > which looks like what I expect. It seems that -fsanitize=float-cast-overflow > option has a false positive. > Here's the backtrace. Program received signal SIGSEGV, Segmentation fault. 0x08a9852b in build_call_expr_loc_array(unsigned int, tree_node*, int, tree_nod**) () (gdb) bt #0 0x08a9852b in build_call_expr_loc_array(unsigned int, tree_node*, int, treenode**) () #1 0x08a986d0 in build_call_expr_loc(unsigned int, tree_node*, int, ...) () #2 0x08808f7a in ubsan_instrument_float_cast (loc=<optimized out>, type=<optimized out>, expr=<optimized out>, arg=<optimized out>) at /mnt/kargl/gcc/gcc/ubsan.c:1609 #3 0x083df160 in convert_to_integer_1 (type=0x296533c0, expr=0x2a10d654, dofold=<optimized out>) at /mnt/kargl/gcc/gcc/convert.c:923 #4 0x083de656 in convert_to_integer (type=0x296533c0, expr=0x2a114214) at /mnt/kargl/gcc/gcc/convert.c:968 #5 0x08293b1f in convert (type=<optimized out>, expr=0x2a114214) at /mnt/kargl/gcc/gcc/fortran/convert.c:101 #6 0x08309ce8 in gfc_conv_intrinsic_conversion (se=0xbfbfe318, expr=<optimized out>) at /mnt/kargl/gcc/gcc/fortran/trans-intrinsic.c:336 #7 0x082ff1cb in gfc_conv_intrinsic_function (se=0xbfbfe318, expr=0x29e13690) at /mnt/kargl/gcc/gcc/fortran/trans-intrinsic.c:7877 #8 0x082fad05 in gfc_conv_function_expr (se=0xbfbfe318, expr=0x29e13690) at /mnt/kargl/gcc/gcc/fortran/trans-expr.c:6527 #9 0x082e2a4f in gfc_conv_expr (se=0xbfbfe318, expr=0x29e13690) at /mnt/kargl/gcc/gcc/fortran/trans-expr.c:7522 #10 0x082eac96 in gfc_trans_assignment_1 (expr1=0x29e13620, expr2=<optimized out>, init_flag=<optimized out>, dealloc=<optimized out>) at /mnt/kargl/gcc/gcc/fortran/trans-expr.c:9249 #11 gfc_trans_assignment (expr1=0x29e13620, expr2=0x29e13690, init_flag=false, dealloc=<optimized out>) at /mnt/kargl/gcc/gcc/fortran/trans-expr.c:9485 #12 0x082fb64b in gfc_trans_assign (code=0x29e13770) at /mnt/kargl/gcc/gcc/fortran/trans-expr.c:9497 #13 0x082af9b2 in trans_code (code=<optimized out>, cond=0x0) at /mnt/kargl/gcc/gcc/fortran/trans.c:1660 #14 0x082dd58c in gfc_generate_function_code (ns=<optimized out>) at /mnt/kargl/gcc/gcc/fortran/trans-decl.c:6083 #15 0x0824737f in translate_all_program_units ( gfc_global_ns_list=<optimized out>) at /mnt/kargl/gcc/gcc/fortran/parse.c:5612 #16 gfc_parse_file () at /mnt/kargl/gcc/gcc/fortran/parse.c:5818 #17 0x082974b8 in gfc_be_parse_file () at /mnt/kargl/gcc/gcc/fortran/f95-lang.c:201 #18 0x087e4e38 in compile_file () at /mnt/kargl/gcc/gcc/toplev.c:464 #19 0x087e4a9d in do_compile () at /mnt/kargl/gcc/gcc/toplev.c:1977 #20 toplev::main (this=<optimized out>, argc=<optimized out>, argv=<optimized out>) at /mnt/kargl/gcc/gcc/toplev.c:2084 #21 0x08fcd3ee in main (argc=<optimized out>, argv=<optimized out>) at /mnt/kargl/gcc/gcc/main.c:39 Note, using an explicit Fortran conversion function, avoids the ICE. subroutine tstd implicit none integer n type a real(8) b end type a type(a) :: daten(10) integer :: j = 1 daten(:)%b = 42 n = int(daten(j)%b) end subroutine tstd Note, the -ftree-dump-original is identical to the above dump! Looks like -fsanitize=float-cast-overflow does not understand Fortran mix-mode math semantics.