https://gcc.gnu.org/g:9d70d3894bda3e6529639e4ae0beb2fe14b9189e
commit r17-1659-g9d70d3894bda3e6529639e4ae0beb2fe14b9189e Author: Martin Jambor <[email protected]> Date: Thu Jun 18 14:17:14 2026 +0200 fortran: Fix UBSAN error member access within null pointer (PR125860) 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' This patch adds the necessary guard to avoid passing an invalid LOC to gfc_value_set_and_used even when the EXPR parameter is NULL and the function will just return. I have left the NULL-check in gfc_value_set_and_used intact so that the behavior of the function is consistent with gfc_value_used_expr (and possibly other functions). gcc/fortran/ChangeLog: 2026-06-16 Martin Jambor <[email protected]> PR fortran/125860 * interface.cc (gfc_procedure_use): Check a->expr is not NULL before calling gfc_value_set_and_used. Diff: --- gcc/fortran/interface.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/interface.cc b/gcc/fortran/interface.cc index ad6885698128..58308aec9da1 100644 --- a/gcc/fortran/interface.cc +++ b/gcc/fortran/interface.cc @@ -4714,8 +4714,9 @@ gfc_procedure_use (gfc_symbol *sym, gfc_actual_arglist **ap, locus *where) if (implicit) for (a = *ap; a; a = a->next) - gfc_value_set_and_used (a->expr, &a->expr->where, VALUE_ARG, - VALUE_MAYBE_USED); + if (a->expr) + gfc_value_set_and_used (a->expr, &a->expr->where, VALUE_ARG, + VALUE_MAYBE_USED); return true; }
