[PATCH] D121101: [clang] Fix OpenMP critical hint parameter check

Peixin Qiao via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 7 03:41:14 PST 2022


peixin created this revision.
peixin added a reviewer: ABataev.
peixin added a project: OpenMP.
Herald added subscribers: guansong, yaxunl.
Herald added a project: All.
peixin requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: cfe-commits, sstefan1.
Herald added a project: clang.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121101

Files:
  clang/lib/Sema/SemaOpenMP.cpp
  clang/test/OpenMP/critical_messages.cpp


Index: clang/test/OpenMP/critical_messages.cpp
===================================================================
--- clang/test/OpenMP/critical_messages.cpp
+++ clang/test/OpenMP/critical_messages.cpp
@@ -67,10 +67,14 @@
   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 @@
   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();
Index: clang/lib/Sema/SemaOpenMP.cpp
===================================================================
--- clang/lib/Sema/SemaOpenMP.cpp
+++ clang/lib/Sema/SemaOpenMP.cpp
@@ -21402,7 +21402,8 @@
   // 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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121101.413411.patch
Type: text/x-patch
Size: 2324 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220307/f1e7a7e8/attachment.bin>


More information about the cfe-commits mailing list