]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
OpenMP: modify_call_for_omp_dispatch - fix invalid memory access after 'error' [PR119541]
authorTobias Burnus <tburnus@baylibre.com>
Mon, 31 Mar 2025 09:44:26 +0000 (11:44 +0200)
committerTobias Burnus <tburnus@baylibre.com>
Mon, 31 Mar 2025 12:55:41 +0000 (14:55 +0200)
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.

(cherry picked from commit f3899e0fd3f9aa6b579a21e87b50c61ea5c448df)

gcc/ChangeLog.omp
gcc/gimplify.cc
gcc/testsuite/ChangeLog.omp

index 3e349ac218730dad649584ead0bbb2b9bc4e212c..5287d53338957125b0db6499a6810de72e8d76a1 100644 (file)
@@ -1,3 +1,12 @@
+2025-03-31  Tobias Burnus  <tburnus@baylibre.com>
+
+       Backported from master:
+       2025-03-31  Tobias Burnus  <tburnus@baylibre.com>
+
+       PR middle-end/119541
+       * gimplify.cc (modify_call_for_omp_dispatch): Limit interop claues
+       processing by the number of append_args arguments.
+
 2025-03-27  Tobias Burnus  <tburnus@baylibre.com>
 
        Backported from master:
index 49ff5ace9bcf6d0dbd8d29db2ed9955149fbb51a..f85a722e2d5cec3797bea748e9be1876033eb447 100644 (file)
@@ -3969,6 +3969,7 @@ modify_call_for_omp_dispatch (tree expr, tree dispatch_clauses,
                  : DECL_SOURCE_LOCATION (fndecl),
                  "%<declare variant%> candidate %qD declared here",
                  fndecl);
+         ninterop = nappend;
        }
     }
   if (dispatch_interop && !dispatch_device_num)
@@ -3991,7 +3992,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);
index 675f1ba3792d95c34360f27fbe1023cb88f6157c..0c39103e3b3318fb1bca7e06275f8785b4fc059f 100644 (file)
@@ -1,3 +1,11 @@
+2025-03-30  Tobias Burnus  <tburnus@baylibre.com>
+
+       Backported from master:
+       2025-03-30  Tobias Burnus  <tburnus@baylibre.com>
+
+       * g++.dg/gomp/append-args-8.C: Remove bogus '3' after \.\[0-9\]+
+       pattern.
+
 2025-03-27  Tobias Burnus  <tburnus@baylibre.com>
 
        Backported from master: