The result of searching for the procedure name symbol should be checked in
case the symbol cannot be found to avoid a null dereference.
gcc/fortran/
PR fortran/104428
* trans-openmp.cc (gfc_trans_omp_declare_variant): Check that proc_st
is non-NULL before dereferencing. Add line number to error message.
gcc/testsuite/
PR fortran/104428
* gfortran.dg/gomp/pr104428.f90: New.
{
gfc_symtree *proc_st;
gfc_find_sym_tree (variant_proc_name, gfc_current_ns, 1, &proc_st);
- variant_proc_sym = proc_st->n.sym;
+ variant_proc_sym = proc_st ? proc_st->n.sym : NULL;
}
if (variant_proc_sym == NULL)
{
- gfc_error ("Cannot find symbol %qs", variant_proc_name);
+ gfc_error ("Cannot find symbol %qs at %L", variant_proc_name,
+ &odv->where);
continue;
}
set_selectors = omp_check_context_selector
--- /dev/null
+! { dg-do compile }
+
+program p
+ interface
+ subroutine x
+ end subroutine x
+ end interface
+contains
+ subroutine foo
+ !$omp declare variant(x) match(construct={do})
+ end
+ subroutine bar
+ !$omp declare variant(y) match(construct={do}) ! { dg-error "Cannot find symbol 'y'" }
+ end
+end