Skip to content

Commit bea53ee

Browse files
Harshil-JaniNimishMishra
authored andcommitted
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
1 parent 446e7c6 commit bea53ee

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

flang/lib/Semantics/check-directive-structure.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ void DirectiveStructureChecker<D, C, PC,
551551
ClauseEnumSize>::RequiresPositiveParameter(const C &clause,
552552
const parser::ScalarIntExpr &i, llvm::StringRef paramName) {
553553
if (const auto v{GetIntValue(i)}) {
554-
if (*v <= 0) {
554+
if (*v < 0) {
555555
context_.Say(GetContext().clauseSource,
556556
"The %s of the %s clause must be "
557557
"a positive integer expression"_err_en_US,

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1656,7 +1656,6 @@ CHECK_SIMPLE_CLAUSE(Default, OMPC_default)
16561656
CHECK_SIMPLE_CLAUSE(Depobj, OMPC_depobj)
16571657
CHECK_SIMPLE_CLAUSE(Destroy, OMPC_destroy)
16581658
CHECK_SIMPLE_CLAUSE(Detach, OMPC_detach)
1659-
CHECK_SIMPLE_CLAUSE(Device, OMPC_device)
16601659
CHECK_SIMPLE_CLAUSE(DeviceType, OMPC_device_type)
16611660
CHECK_SIMPLE_CLAUSE(DistSchedule, OMPC_dist_schedule)
16621661
CHECK_SIMPLE_CLAUSE(DynamicAllocators, OMPC_dynamic_allocators)
@@ -1721,6 +1720,7 @@ CHECK_REQ_SCALAR_INT_CLAUSE(NumTeams, OMPC_num_teams)
17211720
CHECK_REQ_SCALAR_INT_CLAUSE(NumThreads, OMPC_num_threads)
17221721
CHECK_REQ_SCALAR_INT_CLAUSE(Priority, OMPC_priority)
17231722
CHECK_REQ_SCALAR_INT_CLAUSE(ThreadLimit, OMPC_thread_limit)
1723+
CHECK_REQ_SCALAR_INT_CLAUSE(Device, OMPC_device)
17241724

17251725
CHECK_REQ_CONSTANT_SCALAR_INT_CLAUSE(Collapse, OMPC_collapse)
17261726
CHECK_REQ_CONSTANT_SCALAR_INT_CLAUSE(Safelen, OMPC_safelen)

flang/test/Semantics/omp-clause-validity01.f90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,4 +556,8 @@
556556
do i = 1, N
557557
a = 3.14
558558
enddo
559+
560+
!$omp target enter data map(alloc:A) device(0)
561+
!$omp target exit data map(delete:A) device(0)
562+
559563
end program

flang/test/Semantics/omp-device-constructs.f90

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ program main
129129
enddo
130130
!$omp end target data
131131

132+
!ERROR: The parameter of the DEVICE clause must be a positive integer expression
133+
!$omp target enter data map(alloc:A) device(-2)
134+
135+
!ERROR: The parameter of the DEVICE clause must be a positive integer expression
136+
!$omp target exit data map(delete:A) device(-2)
137+
132138
!ERROR: At most one IF clause can appear on the TARGET ENTER DATA directive
133139
!$omp target enter data map(to:a) if(.true.) if(.false.)
134140

0 commit comments

Comments
 (0)