https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125860
Bug ID: 125860
Summary: UBAN reports member access within null pointer at
fortran/interface.cc:4717 since
r17-1502-g9d868e49122b4c
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: jamborm at gcc dot gnu.org
CC: tkoenig at gcc dot gnu.org
Blocks: 63426
Target Milestone: ---
Host: x86_64-linux
Target: x86_64-linux
With UBSAN instrumented compiler, compiling the testcase
gfortran.dg/altreturn_5.f90 at -O3 fails with:
/home/worker/buildworker/ubsan/build/gcc/fortran/interface.cc:4717:27:
runtime error: member access within null pointer of type 'struct gfc_expr'
The relevant of code is:
if (implicit)
for (a = *ap; a; a = a->next)
gfc_value_set_and_used (a->expr, &a->expr->where, VALUE_ARG,
VALUE_MAYBE_USED);
and UBSAN is apparently not happy that we take address of
a->expr->where when a->expr is NULL.
I looks like the following testcases have the same issue:
- gfortran.dg/altreturn_1.f90
- gfortran.dg/altreturn_10.f90
- gfortran.dg/altreturn_4.f90
- gfortran.dg/whole_file_32.f90
- gfortran.dg/pr88248.f90
To configure the compiler with UBSAN, bootstrap it with option
--with-build-config=bootstrap-ubsan like for example:
../src/configure --prefix=/tmp/inst --enable-languages=c,c++,fortran
--enable-checking=release --disable-multilib --enable-host-shared
--with-build-config=bootstrap-ubsan --disable-libgomp
The issue can also be reproduced by simply asserting that a->expr is
not NULL before calling gfc_value_set_and_used.
I have bisected the issue to revision r17-1502-g9d868e49122b4c (Thomas
Koenig: Implement warnings based on variable definition and use.)
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63426
[Bug 63426] [meta-bug] Issues found with -fsanitize=undefined