]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp, fortran: Fix ICE when the procedure name cannot be found in declare variant...
authorKwok Cheung Yeung <kcyeung@baylibre.com>
Tue, 15 Jul 2025 14:26:26 +0000 (15:26 +0100)
committerKwok Cheung Yeung <kcyeung@baylibre.com>
Tue, 15 Jul 2025 14:27:22 +0000 (15:27 +0100)
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.

gcc/fortran/trans-openmp.cc
gcc/testsuite/gfortran.dg/gomp/pr104428.f90 [new file with mode: 0644]

index f3d7cd4ffee9f8f146fe48eaab8b211dd434b9cf..278e91c2c495b93305e8ab571c5042cc01cdad3c 100644 (file)
@@ -9714,11 +9714,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 (file)
index 0000000..639b331
--- /dev/null
@@ -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