Skip to content

Commit 97eb416

Browse files
authored
[flang][Parser][OpenMP] Fix unparser for cancellation_construct_type (#136001)
Previously the unparser would print like ``` !$OMP CANCEL CANCELLATION_CONSTRUCT_TYPE(SECTIONS) ``` This is not valid Fortran. I have fixed it to print without the clause name.
1 parent 112ffe7 commit 97eb416

File tree

6 files changed

+67
-0
lines changed

6 files changed

+67
-0
lines changed

flang/lib/Parser/unparse.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,6 +2871,10 @@ class UnparseVisitor {
28712871
Put("\n");
28722872
EndOpenMP();
28732873
}
2874+
// Clause unparsers are usually generated by tablegen in the form
2875+
// CLAUSE(VALUE). Here we only want to print VALUE so a custom unparser is
2876+
// needed.
2877+
void Unparse(const OmpClause::CancellationConstructType &x) { Walk(x.v); }
28742878
void Unparse(const OpenMPCancellationPointConstruct &x) {
28752879
BeginOpenMP();
28762880
Word("!$OMP ");

flang/test/Parser/OpenMP/cancel.f90

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
!RUN: %flang_fc1 -fdebug-unparse -fopenmp %s | FileCheck %s
2+
3+
! CHECK: SUBROUTINE parallel
4+
subroutine parallel
5+
! CHECK: !$OMP PARALLEL
6+
!$omp parallel
7+
! CHECK: !$OMP CANCEL PARALLEL
8+
!$omp cancel parallel
9+
! CHECK: !$OMP END PARALLEL
10+
!$omp end parallel
11+
! CHECK: END SUBROUTINE
12+
end subroutine
13+
14+
! CHECK: SUBROUTINE sections
15+
subroutine sections
16+
! CHECK: !$OMP PARALLEL SECTIONS
17+
!$omp parallel sections
18+
! CHECK: !$OMP CANCEL SECTIONS
19+
!$omp cancel sections
20+
! CHECK: !$OMP END PARALLEL SECTIONS
21+
!$omp end parallel sections
22+
! CHECK: END SUBROUTINE
23+
end subroutine
24+
25+
! CHECK: SUBROUTINE loop
26+
subroutine loop
27+
! CHECK: !$OMP PARALLEL DO
28+
!$omp parallel do
29+
! CHECK: DO i=1_4,10_4
30+
do i=1,10
31+
! CHECK: !$OMP CANCEL DO
32+
!$omp cancel do
33+
! CHECK: END DO
34+
enddo
35+
! CHECK: !$OMP END PARALLEL DO
36+
!$omp end parallel do
37+
! CHECK: END SUBROUTINE
38+
end subroutine
39+
40+
! CHECK: SUBROUTINE taskgroup
41+
subroutine taskgroup
42+
! CHECK: !$OMP TASKGROUP
43+
!$omp taskgroup
44+
! CHECK: !$OMP TASK
45+
!$omp task
46+
! CHECK: !$OMP CANCEL TASKGROUP
47+
!$omp cancel taskgroup
48+
! CHECK: !$OMP END TASK
49+
!$omp end task
50+
! CHECK: !$OMP END TASKGROUP
51+
!$omp end taskgroup
52+
! CHECK: END SUBROUTINE
53+
end subroutine

llvm/include/llvm/Frontend/Directive/DirectiveBase.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ class Clause<string c> {
8383
// Optional class holding value of the clause in flang AST.
8484
string flangClass = "";
8585

86+
// If set to true, don't emit flang Unparser.
87+
bit skipFlangUnparser = false;
88+
8689
// If set to true, value is optional. Not optional by default.
8790
bit isValueOptional = false;
8891

llvm/include/llvm/Frontend/OpenMP/OMP.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def OMPC_CancellationConstructType : Clause<"cancellation_construct_type"> {
106106
OMP_CANCELLATION_CONSTRUCT_None
107107
];
108108
let flangClass = "OmpCancellationConstructTypeClause";
109+
let skipFlangUnparser = true;
109110
}
110111
def OMPC_Contains : Clause<"contains"> {
111112
let clangClass = "OMPContainsClause";

llvm/include/llvm/TableGen/DirectiveEmitter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ class Clause : public BaseRecord {
257257
return Def->getValueAsListOfDefs("allowedClauseValues");
258258
}
259259

260+
bool skipFlangUnparser() const {
261+
return Def->getValueAsBit("skipFlangUnparser");
262+
}
263+
260264
bool isValueOptional() const { return Def->getValueAsBit("isValueOptional"); }
261265

262266
bool isValueList() const { return Def->getValueAsBit("isValueList"); }

llvm/utils/TableGen/Basic/DirectiveEmitter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,8 @@ static void generateFlangClauseUnparse(const DirectiveLanguage &DirLang,
960960
OS << "\n";
961961

962962
for (const Clause Clause : DirLang.getClauses()) {
963+
if (Clause.skipFlangUnparser())
964+
continue;
963965
if (!Clause.getFlangClass().empty()) {
964966
if (Clause.isValueOptional() && Clause.getDefaultValue().empty()) {
965967
OS << "void Unparse(const " << DirLang.getFlangClauseBaseClass()

0 commit comments

Comments
 (0)