From: Tobias Burnus Date: Mon, 31 Mar 2025 09:44:26 +0000 (+0200) Subject: OpenMP: modify_call_for_omp_dispatch - fix invalid memory access after 'error' [PR119541] X-Git-Tag: basepoints/gcc-16~490 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f3899e0fd3f9aa6b579a21e87b50c61ea5c448df;p=thirdparty%2Fgcc.git OpenMP: modify_call_for_omp_dispatch - fix invalid memory access after 'error' [PR119541] OpenMP requires that the number of dispatch 'interop' clauses (ninterop) is less or equal to the number of declare variant 'append_args' interop objects (nappend). While 'nappend < ninterop' was diagnosed as error, the processing continues, which lead to an invalid out-of-bounds memory access. Solution: only process the first nappend 'interop' clauses. gcc/ChangeLog: PR middle-end/119541 * gimplify.cc (modify_call_for_omp_dispatch): Limit interop claues processing by the number of append_args arguments. --- diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 422ad1265a6..a8399dc8363 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -3949,6 +3949,7 @@ modify_call_for_omp_dispatch (tree expr, tree dispatch_clauses, : DECL_SOURCE_LOCATION (fndecl), "% candidate %qD declared here", fndecl); + ninterop = nappend; } } if (dispatch_interop && !dispatch_device_num) @@ -3971,7 +3972,7 @@ modify_call_for_omp_dispatch (tree expr, tree dispatch_clauses, buffer[i] = CALL_EXPR_ARG (expr, i); } int j = ninterop; - for (tree t = dispatch_interop; t; t = TREE_CHAIN (t)) + for (tree t = dispatch_interop; t && j > 0; t = TREE_CHAIN (t)) if (OMP_CLAUSE_CODE (t) == OMP_CLAUSE_INTEROP) buffer[i + --j] = OMP_CLAUSE_DECL (t); gcc_checking_assert (j == 0);