<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Variable used by task inside a template function is not made firstprivate by default"
   href="https://bugs.llvm.org/show_bug.cgi?id=47621">47621</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Variable used by task inside a template function is not made firstprivate by default
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>OpenMP
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Clang Compiler Support
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>fmorac@udel.edu
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23992" name="attach_23992" title="Full test">attachment 23992</a> <a href="attachment.cgi?id=23992&action=edit" title="Full test">[details]</a></span>
Full test

Description:
  Variable used by a task region inside a template function is not made 
firstprivate by default as per defined in the OpenMP specification at the end
of section 2.19.1.1.

Extract from test.cpp where the bug is located:
====================================================================
template <typename T = void> int template_test(int n) {
  std::vector<int> values(n, 0);
#pragma omp parallel
  {
#pragma omp single
    {
      for (int i = 0; i < n; ++i)
#pragma omp task
        values[i] = i;
    }
  }
  int diffs = 0;
  for (int i = 0; i < n; ++i)
    if (values[i] != i)
      ++diffs;
  return diffs;
}
====================================================================
The expected return value for the template_test function is 0.

Expected test results:
====================================================================
Non-template test:                           PASS
Template test:                               PASS
Template test with first-private clause:     PASS
====================================================================

Tested compilers:
  clang-9, clang-10, clang-12

Compilers where the bug can be found:
  clang-9, clang-10, clang-12

Testing platform:
  Debian testing, Ubuntu Bionic Beaver

Current test results:
====================================================================
Non-template test:                           PASS
Template test:                               FAIL
Template test with first-private clause:     PASS
====================================================================

Steps to reproduce:
  1. clang++ -fopenmp test.cpp -o test
  2. ./test

Related bug: 
  <a class="bz_bug_link 
          bz_status_RESOLVED  bz_closed"
   title="RESOLVED FIXED - Variable used by task is not made firstprivate by default as suggested by the Spec (end of section 2.15.1.1)"
   href="show_bug.cgi?id=39422">https://bugs.llvm.org/show_bug.cgi?id=39422</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>