[llvm-bugs] [Bug 48740] New: OpenMP declare reduction in C does not require an initializer

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jan 13 07:59:09 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=48740

            Bug ID: 48740
           Summary: OpenMP declare reduction in C does not require an
                    initializer
           Product: OpenMP
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Clang Compiler Support
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rofirrim at gmail.com
                CC: llvm-bugs at lists.llvm.org

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] https://www.openmp.org/spec-html/5.1/openmpsu117.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210113/6fdcaf9d/attachment.html>


More information about the llvm-bugs mailing list