]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
openmp: Fix regression in libgomp.c++/target-6.C testcase [PR113436]
authorKwok Cheung Yeung <kcyeung@baylibre.com>
Fri, 20 Feb 2026 16:07:45 +0000 (16:07 +0000)
committerKwok Cheung Yeung <kcyeung@baylibre.com>
Fri, 20 Feb 2026 16:55:59 +0000 (16:55 +0000)
The fix for PR113436 introduced a regression causing the
libgomp.c++/target-6.C testcase to fail on some configurations.

This was caused by a change in how is_variable_sized is applied for variables
that are references in private clauses, causing the path that was intended for
variables that are variable-sized in themselves to be taken, instead of
that for referencing a variable-sized object.

2026-02-20  Kwok Cheung Yeung  <kcyeung@baylibre.com>

gcc/

PR middle-end/113436
* omp-low.cc (omp_lower_target):  Do not check for variable-length
variables in private clauses by reference when allocating memory.

gcc/testsuite/

PR middle-end/113436
* g++.dg/gomp/pr113436-2.C: New.

gcc/omp-low.cc
gcc/testsuite/g++.dg/gomp/pr113436-2.C [new file with mode: 0644]

index 15245eae9decb90ed7774cbcef3ba69054a34353..aeed1d25e8af4bffe866a320ebb6486925b8ade1 100644 (file)
@@ -14458,7 +14458,7 @@ lower_omp_target (gimple_stmt_iterator *gsi_p, omp_context *ctx)
          case OMP_CLAUSE_PRIVATE:
            var = OMP_CLAUSE_DECL (c);
            by_ref = omp_privatize_by_reference (var);
-           if (is_variable_sized (var, by_ref))
+           if (is_variable_sized (var))
              {
                tree new_var = lookup_decl (var, ctx);
                tree *allocate_ptr = alloc_map.get (new_var);
diff --git a/gcc/testsuite/g++.dg/gomp/pr113436-2.C b/gcc/testsuite/g++.dg/gomp/pr113436-2.C
new file mode 100644 (file)
index 0000000..70f6ffc
--- /dev/null
@@ -0,0 +1,17 @@
+// PR middle-end/113436
+// { dg-do "compile" }
+// { dg-options "-fopenmp -fdump-tree-omplower" }
+
+void f(int x)
+{
+  int a[x];
+  int (&c)[x] = a;
+
+  #pragma omp target private (c)
+  {
+    c[0] = 1;
+  }
+}
+
+// Ensure that the size of memory allocated for the VLA is from a variable rather than a constant.
+// { dg-final { scan-tree-dump "D\\\.\[0-9\]\+ = __builtin_alloca_with_align \\\(D\\\.\[0-9\]\+, \[0-9\]\+\\\);" "omplower" } }