From: Kwok Cheung Yeung Date: Tue, 15 Jul 2025 14:26:26 +0000 (+0100) Subject: openmp, fortran: Fix ICE when the procedure name cannot be found in declare variant... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c9965c37cd153b7764f147a77489db9827071ad0;p=thirdparty%2Fgcc.git openmp, fortran: Fix ICE when the procedure name cannot be found in declare variant directives [PR104428] 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. (cherry picked from commit a05c4f4ee48f76e518dbd2a96e5083f4df833df7) --- diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index 2a48d4af527..0dfb3379892 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -9703,11 +9703,12 @@ gfc_trans_omp_declare_variant (gfc_namespace *ns, gfc_namespace *parent_ns) { 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 diff --git a/gcc/testsuite/gfortran.dg/gomp/pr104428.f90 b/gcc/testsuite/gfortran.dg/gomp/pr104428.f90 new file mode 100644 index 00000000000..639b331ff5b --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/pr104428.f90 @@ -0,0 +1,15 @@ +! { 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