This is an archive of the discontinued LLVM Phabricator instance.

[OpenMP] [Reduction] Allow PLUS (+) operator on reduction clauses in OMP > 52
ClosedPublic

Authored by mdfazlay on Jul 18 2023, 1:24 PM.

Details

Summary

Currently, clang gives an incorrect reduction identifier error for the PLUS
operator for OpenMP version > 52. But, PLUS operator is allowed in OpenMP
version > 52. This revision fixes this issue and also modified the error
messages to show the correct expected operators in the message based on the OpenMP
version used (prior to OMP 6.0 and since OMP 6.0).

Test Src:

void foo() {
 int a = 0 ;
  #pragma omp parallel reduction(+:a)
     ;
   #pragma omp parallel reduction(-:a)
     ;
 }

Before this revision:

$ clang -fopenmp -fopenmp-version=60 test.c -c
test.c:3:34: error: incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'int'
  3 |   #pragma omp parallel reduction(+:a)
    |                                  ^
test.c:5:34: error: incorrect reduction identifier, expected one of '+', '-', '*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'int'
  5 |   #pragma omp parallel reduction(-:a)
    |                                  ^
2 errors generated.

With this revision:

$  clang -fopenmp -fopenmp-version=60 test.c -c
test.c:5:34: error: incorrect reduction identifier, expected one of '+', '*', '&', '|', '^', '&&', '||', 'min' or 'max' or declare reduction for type 'int'
    5 |   #pragma omp parallel reduction(-:a)
      |                                  ^

Reference:
(1) OpenMP 5.2 Page 627 Line 18
(2) OpenMP 5.2 Page 124 (Section 5.5) Line 18 and 20
(3) https://reviews.llvm.org/D150394

Diff Detail

Event Timeline

mdfazlay created this revision.Jul 18 2023, 1:24 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 18 2023, 1:24 PM
mdfazlay requested review of this revision.Jul 18 2023, 1:24 PM
Herald added a project: Restricted Project. · View Herald Transcript
mdfazlay edited the summary of this revision. (Show Details)Jul 18 2023, 1:32 PM

Tests?

I think I need to use -fopenmp-version=60 to test this revision. As OMP 6.0 is not official yet, am I allowed to use -fopenmp-version=60 in my LIT test?

Tests?

I think I need to use -fopenmp-version=60 to test this revision. As OMP 6.0 is not official yet, am I allowed to use -fopenmp-version=60 in my LIT test?

Yes

mdfazlay updated this revision to Diff 542628.Jul 20 2023, 12:15 PM

Tests?

I think I need to use -fopenmp-version=60 to test this revision. As OMP 6.0 is not official yet, am I allowed to use -fopenmp-version=60 in my LIT test?

Yes

I have added a few LIT tests.

This revision is now accepted and ready to land.Jul 20 2023, 12:52 PM
This revision was landed with ongoing or failed builds.Jul 20 2023, 2:26 PM
This revision was automatically updated to reflect the committed changes.