https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79524
--- Comment #26 from Christopher Albert <albert at tugraz dot at> --- (In reply to [email protected] from comment #23) > (In reply to David Binderman from comment #0) > > I just tried to compile the above fortran code on a recent > > valgrind version of trunk gfortran. > > > > /home/dcb/gcc/results.245439/bin/gfortran -c > > gfortran.dg/fimplicit_none_2.f90 > > > > After some errors, it said > > > > ==28421== Invalid read of size 8 > > ==28421== at 0x6B1095: check_host_association (resolve.c:5401) > > ==28421== by 0x6B1095: gfc_resolve_expr(gfc_expr*) (resolve.c:6470) > > ==28421== by 0x6B44AB: resolve_charlen(gfc_charlen*) [clone .part.60] > > (resolv > > e.c:11401) > > ==28421== by 0x6BE77F: resolve_charlen (resolve.c:11392) > > What is meant by a valgrind version in this original report. > > With Christophers patch on gcc16 (trunk) I do not see any errors. > > However, I don't get any errors with gcc15 either with the testcase. I am not > sure I am testing this correctly. Thanks Jerry and David for the feedback. > What is meant by a valgrind version in this original report. As David noted in comment #24, the original reporter configured GCC with --enable-checking=valgrind, which instruments f951 so that valgrind can detect heap-use-after-free. Without valgrind or ASan the freed memory usually has not been overwritten yet, so the dangling read succeeds and the compiler continues without crashing. The testcase in the patch uses dg-set-target-env-var MALLOC_PERTURB_ 165 which makes glibc fill freed regions with a byte pattern. With that, unpatched trunk actually segfaults on the second declaration (character(n+1)) because the operator-expression walk hits the overwritten memory: MALLOC_PERTURB_=165 ./f951 reproducer.f90 -quiet Error: Cannot initialize parameter array at (1) with variable length elements Error: Cannot initialize parameter array at (1) with variable length elements f951: internal compiler error: Segmentation fault > However, I don't get any errors with gcc15 either with the testcase. > I am not sure I am testing this correctly. The bug is present on all active release branches (gcc-13 through trunk). To trigger it reliably without an ASan build: MALLOC_PERTURB_=165 f951 reproducer.f90 -quiet or run under valgrind: valgrind f951 reproducer.f90 -quiet Updated patch attached (only change from attachment 64114 is adding a trailing newline to the test file). Rebased on current trunk, regtested on x86_64-pc-linux-gnu with 0 FAIL/XPASS.
