Skip to content

Commit 2f40e20

Browse files
committed
[flang][openacc] Fix device_num and device_type clauses for init directive
This patch fix the device_num and device_type clauses used in the init clause. device_num was not spelled correctly in the parser and was to restrictive with scalarIntConstantExpr instead of scalarIntExpr. device_type is now taking a list of ScalarIntExpr. Reviewed By: kiranchandramohan Differential Revision: https://reviews.llvm.org/D88571
1 parent 7993d61 commit 2f40e20

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

flang/lib/Parser/openacc-parsers.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ TYPE_PARSER("AUTO" >> construct<AccClause>(construct<AccClause::Auto>()) ||
5757
parenthesized(Parser<AccObjectList>{}))) ||
5858
"DEVICEPTR" >> construct<AccClause>(construct<AccClause::Deviceptr>(
5959
parenthesized(Parser<AccObjectList>{}))) ||
60-
"DEVICENUM" >> construct<AccClause>(construct<AccClause::DeviceNum>(
61-
parenthesized(scalarIntConstantExpr))) ||
60+
"DEVICE_NUM" >> construct<AccClause>(construct<AccClause::DeviceNum>(
61+
parenthesized(scalarIntExpr))) ||
6262
"DEVICE_RESIDENT" >>
6363
construct<AccClause>(construct<AccClause::DeviceResident>(
6464
parenthesized(Parser<AccObjectList>{}))) ||
6565
("DEVICE_TYPE"_tok || "DTYPE"_tok) >>
6666
construct<AccClause>(construct<AccClause::DeviceType>(parenthesized(
67-
"*" >> construct<std::optional<std::list<Name>>>()))) ||
67+
"*" >> construct<std::optional<std::list<ScalarIntExpr>>>()))) ||
6868
("DEVICE_TYPE"_tok || "DTYPE"_tok) >>
6969
construct<AccClause>(construct<AccClause::DeviceType>(
70-
parenthesized(maybe(nonemptyList(name))))) ||
70+
parenthesized(maybe(nonemptyList(scalarIntExpr))))) ||
7171
"FINALIZE" >> construct<AccClause>(construct<AccClause::Finalize>()) ||
7272
"FIRSTPRIVATE" >> construct<AccClause>(construct<AccClause::Firstprivate>(
7373
parenthesized(Parser<AccObjectList>{}))) ||

flang/test/Semantics/acc-clause-validity.f90

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,21 @@ program openacc_clause_validity
2525
real :: reduction_r
2626
logical :: reduction_l
2727
real(8), dimension(N, N) :: aa
28+
logical :: ifCondition = .TRUE.
2829

2930
!ERROR: At least one clause is required on the DECLARE directive
3031
!$acc declare
3132
real(8), dimension(N) :: a
3233

34+
!$acc init
35+
!$acc init if(.TRUE.)
36+
!$acc init if(ifCondition)
37+
!$acc init device_num(1)
38+
!$acc init device_num(i)
39+
!$acc init device_type(i)
40+
!$acc init device_type(2, i, j)
41+
!$acc init device_num(i) device_type(i, j) if(ifCondition)
42+
3343
!ERROR: At least one of ATTACH, COPYIN, CREATE clause must appear on the ENTER DATA directive
3444
!$acc enter data
3545

llvm/include/llvm/Frontend/OpenACC/ACC.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def ACCC_Device : Clause<"device"> {
106106

107107
// 2.14.1
108108
def ACCC_DeviceNum : Clause<"device_num"> {
109-
let flangClassValue = "ScalarIntConstantExpr";
109+
let flangClassValue = "ScalarIntExpr";
110110
}
111111

112112
// 2.7.3
@@ -121,7 +121,7 @@ def ACCC_DeviceResident : Clause<"device_resident"> {
121121

122122
// 2.4
123123
def ACCC_DeviceType : Clause<"device_type"> {
124-
let flangClassValue = "Name";
124+
let flangClassValue = "ScalarIntExpr";
125125
let defaultValue = "*";
126126
let isValueOptional = 1;
127127
let isValueList = 1;

0 commit comments

Comments
 (0)