[clang] Fix OpenMP critical hint parameter check

The paramemter of hint clause in OpenMP critical hint should be
non-negative. The omp_lock_hint_none is 0 in omp.h.

Reviewed By: Alexey Bataev

Differential Revision: https://reviews.llvm.org/D121101
This commit is contained in:
Peixin-Qiao 2022-03-08 09:04:31 +08:00
parent 5b87e0521d
commit 4e159e4c7b
2 changed files with 8 additions and 3 deletions

View File

@ -21402,7 +21402,8 @@ OMPClause *Sema::ActOnOpenMPHintClause(Expr *Hint, SourceLocation StartLoc,
// OpenMP [2.13.2, critical construct, Description]
// ... where hint-expression is an integer constant expression that evaluates
// to a valid lock hint.
ExprResult HintExpr = VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint);
ExprResult HintExpr =
VerifyPositiveIntegerConstantInClause(Hint, OMPC_hint, false);
if (HintExpr.isInvalid())
return nullptr;
return new (Context)

View File

@ -67,10 +67,14 @@ int tmain(int argc, char **argv) { // expected-note {{declared here}}
foo();
#pragma omp critical (name2) hint(argc) // expected-error {{integral constant expression}} expected-note 0+{{constant expression}}
foo();
#pragma omp critical (name) hint(N) // expected-error {{argument to 'hint' clause must be a strictly positive integer value}} expected-error {{constructs with the same name must have a 'hint' clause with the same value}} expected-note {{'hint' clause with value '4'}}
#pragma omp critical (name) hint(N) // expected-error {{argument to 'hint' clause must be a non-negative integer value}} expected-error {{constructs with the same name must have a 'hint' clause with the same value}} expected-note {{'hint' clause with value '4'}}
foo();
#pragma omp critical hint(N) // expected-error {{the name of the construct must be specified in presence of 'hint' clause}}
foo();
const int omp_lock_hint_none = 0;
#pragma omp critical (name3) hint(omp_lock_hint_none)
foo();
return 0;
}
@ -132,7 +136,7 @@ int main(int argc, char **argv) { // expected-note {{declared here}}
foo();
#pragma omp critical (name) hint(23) // expected-note {{previous 'hint' clause with value '23'}}
foo();
#pragma omp critical hint(-5) // expected-error {{argument to 'hint' clause must be a strictly positive integer value}}
#pragma omp critical hint(-5) // expected-error {{argument to 'hint' clause must be a non-negative integer value}}
foo();
#pragma omp critical hint(1) // expected-error {{the name of the construct must be specified in presence of 'hint' clause}}
foo();