<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 - OpenMP declare reduction in C does not require an initializer"
   href="https://bugs.llvm.org/show_bug.cgi?id=48740">48740</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>OpenMP declare reduction in C does not require an initializer
          </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>enhancement
          </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>rofirrim@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following C snippet:

  // t.c
  struct S {
    int x;
  };

  #pragma omp declare reduction(udr_int : int : omp_out)
  #pragma omp declare reduction(udr_agg : struct S : omp_out)

  int main() {
    int x = 0;
    struct S s = {};
    #pragma omp parallel reduction(udr_int : x)
    { }
    #pragma omp parallel reduction(udr_agg : s)
    { }
  }
  // end of t.c

When compiled using

  clang -c t.c -fopenmp

emits the following diagnostic

  t.c:12:42: error: list item of type 'int' is not valid for specified
reduction operation: unable to provide default initialization value
  #pragma omp parallel reduction(udr_int : x)
                                 ~~~~~~~   ^
  t.c:10:7: note: 'x' defined here
    int x = 0;
        ^
  t.c:14:42: error: list item of type 'struct S' is not valid for specified
reduction operation: unable to provide default initialization value
  #pragma omp parallel reduction(udr_agg : s)
                                 ~~~~~~~   ^
  t.c:11:12: note: 's' defined here
    struct S s = {};
             ^
  2 errors generated.

but my reading of the OpenMP spec suggests that this is actually not required
for C[1]

  (C) If no initializer-clause is specified, the private variables will be
  initialized following the rules for initialization of objects with static
  storage duration.

GCC accepts this code.

This issue can be worked around using an `initializer` clause such as
`initializer(omp_priv = {})` for `udr_agg`.

[1] <a href="https://www.openmp.org/spec-html/5.1/openmpsu117.html">https://www.openmp.org/spec-html/5.1/openmpsu117.html</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>