llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.6k stars 11.82k forks source link

[OpenMP5.0] A worksharing region closely nested inside a worksharing region should return an error #45704

Open llvmbot opened 4 years ago

llvmbot commented 4 years ago
Bugzilla Link 46359
Version unspecified
OS Linux
Reporter LLVM Bugzilla Contributor
CC @alexey-bataev

Extended Description

According to OpenMP5.0's Restriction:

2.20 Nesting of Regions A worksharing region may not be closely nested inside a worksharing, loop, task, taskloop, critical, ordered, atomic, or master region. https://www.openmp.org/spec-html/5.0/openmpse28.html#x143-6330002.20

closely nested construct: A construct nested inside another construct with no other construct nested between them. https://www.openmp.org/spec-html/5.0/openmpsu2.html#x9-80001.2.2

The following examples are non-conforming because the inner and outer loop regions are closely nested,clang should report an error for case nesting_restrict.2.c as nesting_restrict.1.c.

These testcases are from: https://www.openmp.org/wp-content/uploads/openmp-examples-5.0.0.pdf p378

nesting_restrict.1.c

void work(int i, int j) {}

void wrong1(int n) {

pragma omp parallel default(shared)

{ int i, j;

pragma omp for

for (i=0; i<n; i++) {
   /* incorrect nesting of loop regions */
   #pragma omp for
     for (j=0; j<n; j++)
       work(i, j);
}

} }

clang -fopenmp-version=50 -fopenmp -S Example_nesting_restrict.1.c

Example_nesting_restrict.1.c:20:8: error: region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp for' directive into a parallel region?

pragma omp for

   ^

1 error generated.

nesting_restrict.2.c

void work(int i, int j) {} void work1(int i, int n) { int j; / incorrect nesting of loop regions /

pragma omp for

for (j=0; j<n; j++)
  work(i, j);

}

void wrong2(int n) {

pragma omp parallel default(shared)

{ int i;

pragma omp for

  for (i=0; i<n; i++)
     work1(i, n);

} }

clang -fopenmp-version=50 -fopenmp -S Example_nesting_restrict.2.c

alexey-bataev commented 4 years ago

I tend to disagree with this. According to the standard, "closely nested construct" is "A construct nested inside another construct with no other construct nested between them." and "nested construct" is "A construct (lexically) enclosed by another construct.". The basic word here is "lexically". In the second example, the construct lexically is not enclosed into the first worksharing construct.

llvmbot commented 4 years ago

Add test information:

clang --version

clang version 10.0.0 Target: x86_64-unknown-linux-gnu Thread model: posix