Author: Harshil Jain
Date: 2022-02-13T16:51:19+05:30
New Revision: bea53eead1de84a28affc6a7cbf88f87a258fed4

URL: 
https://github.com/llvm/llvm-project/commit/bea53eead1de84a28affc6a7cbf88f87a258fed4
DIFF: 
https://github.com/llvm/llvm-project/commit/bea53eead1de84a28affc6a7cbf88f87a258fed4.diff

LOG: The device expression must evaluate to a non-negative integer value.

Device clause when it occurs with **target enter data** and **target exit 
data** must be declared with some non negative value. So some changes were made 
to evaluate the device clause argument to non negative value and throw the 
expected error when it takes negative value as argument.

Reviewed By: clementval

Differential Revision: https://reviews.llvm.org/D119141

Added: 
    

Modified: 
    flang/lib/Semantics/check-directive-structure.h
    flang/lib/Semantics/check-omp-structure.cpp
    flang/test/Semantics/omp-clause-validity01.f90
    flang/test/Semantics/omp-device-constructs.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-directive-structure.h 
b/flang/lib/Semantics/check-directive-structure.h
index 0a0fe1cad4ce..c1b00d2cac95 100644
--- a/flang/lib/Semantics/check-directive-structure.h
+++ b/flang/lib/Semantics/check-directive-structure.h
@@ -551,7 +551,7 @@ void DirectiveStructureChecker<D, C, PC,
     ClauseEnumSize>::RequiresPositiveParameter(const C &clause,
     const parser::ScalarIntExpr &i, llvm::StringRef paramName) {
   if (const auto v{GetIntValue(i)}) {
-    if (*v <= 0) {
+    if (*v < 0) {
       context_.Say(GetContext().clauseSource,
           "The %s of the %s clause must be "
           "a positive integer expression"_err_en_US,

diff  --git a/flang/lib/Semantics/check-omp-structure.cpp 
b/flang/lib/Semantics/check-omp-structure.cpp
index 802fdf650a07..9c9fb800bb15 100644
--- a/flang/lib/Semantics/check-omp-structure.cpp
+++ b/flang/lib/Semantics/check-omp-structure.cpp
@@ -1656,7 +1656,6 @@ CHECK_SIMPLE_CLAUSE(Default, OMPC_default)
 CHECK_SIMPLE_CLAUSE(Depobj, OMPC_depobj)
 CHECK_SIMPLE_CLAUSE(Destroy, OMPC_destroy)
 CHECK_SIMPLE_CLAUSE(Detach, OMPC_detach)
-CHECK_SIMPLE_CLAUSE(Device, OMPC_device)
 CHECK_SIMPLE_CLAUSE(DeviceType, OMPC_device_type)
 CHECK_SIMPLE_CLAUSE(DistSchedule, OMPC_dist_schedule)
 CHECK_SIMPLE_CLAUSE(DynamicAllocators, OMPC_dynamic_allocators)
@@ -1721,6 +1720,7 @@ CHECK_REQ_SCALAR_INT_CLAUSE(NumTeams, OMPC_num_teams)
 CHECK_REQ_SCALAR_INT_CLAUSE(NumThreads, OMPC_num_threads)
 CHECK_REQ_SCALAR_INT_CLAUSE(Priority, OMPC_priority)
 CHECK_REQ_SCALAR_INT_CLAUSE(ThreadLimit, OMPC_thread_limit)
+CHECK_REQ_SCALAR_INT_CLAUSE(Device, OMPC_device)
 
 CHECK_REQ_CONSTANT_SCALAR_INT_CLAUSE(Collapse, OMPC_collapse)
 CHECK_REQ_CONSTANT_SCALAR_INT_CLAUSE(Safelen, OMPC_safelen)

diff  --git a/flang/test/Semantics/omp-clause-validity01.f90 
b/flang/test/Semantics/omp-clause-validity01.f90
index a4712a27c440..4391fad25138 100644
--- a/flang/test/Semantics/omp-clause-validity01.f90
+++ b/flang/test/Semantics/omp-clause-validity01.f90
@@ -556,4 +556,8 @@
   do i = 1, N
      a = 3.14
   enddo
+
+  !$omp target enter data map(alloc:A) device(0) 
+  !$omp target exit data map(delete:A) device(0) 
+
 end program

diff  --git a/flang/test/Semantics/omp-device-constructs.f90 
b/flang/test/Semantics/omp-device-constructs.f90
index d5a1acc69721..586cec6f8a94 100644
--- a/flang/test/Semantics/omp-device-constructs.f90
+++ b/flang/test/Semantics/omp-device-constructs.f90
@@ -129,6 +129,12 @@ program main
   enddo
   !$omp end target data
 
+  !ERROR: The parameter of the DEVICE clause must be a positive integer 
expression
+  !$omp target enter data map(alloc:A) device(-2)
+
+  !ERROR: The parameter of the DEVICE clause must be a positive integer 
expression
+  !$omp target exit data map(delete:A) device(-2)
+
   !ERROR: At most one IF clause can appear on the TARGET ENTER DATA directive
   !$omp target enter data map(to:a) if(.true.) if(.false.)
 


        
_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to