Skip to content

Commit 744b131

Browse files
[flang][OpenMP]Add support for OpenMP ERROR directive
Lowering leads to a TODO, with a test to confirm. Also testing unparse.
1 parent 4639a9a commit 744b131

File tree

10 files changed

+103
-1
lines changed

10 files changed

+103
-1
lines changed

flang/include/flang/Parser/dump-parse-tree.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ class ParseTreeDumper {
488488
NODE(parser, OmpAlignment)
489489
NODE(parser, OmpAlignedClause)
490490
NODE(OmpAlignedClause, Modifier)
491+
NODE(parser, OmpAtClause)
492+
NODE(OmpAtClause, ActionTime)
493+
NODE(OmpSeverityClause, Severity)
491494
NODE(parser, OmpAtomic)
492495
NODE(parser, OmpAtomicCapture)
493496
NODE(OmpAtomicCapture, Stmt1)
@@ -564,6 +567,7 @@ class ParseTreeDumper {
564567
NODE_ENUM(OmpLinearModifier, Value)
565568
NODE(parser, OmpLoopDirective)
566569
NODE(parser, OmpMapClause)
570+
NODE(parser, OmpMessageClause)
567571
NODE(OmpMapClause, Modifier)
568572
static std::string GetNodeName(const llvm::omp::Clause &x) {
569573
return llvm::Twine(
@@ -604,6 +608,7 @@ class ParseTreeDumper {
604608
NODE(parser, OmpScheduleClause)
605609
NODE(OmpScheduleClause, Modifier)
606610
NODE_ENUM(OmpScheduleClause, Kind)
611+
NODE(parser, OmpSeverityClause)
607612
NODE(parser, OmpDeviceClause)
608613
NODE(OmpDeviceClause, Modifier)
609614
NODE(parser, OmpDeviceModifier)
@@ -652,6 +657,7 @@ class ParseTreeDumper {
652657
NODE(parser, OmpAtomicDefaultMemOrderClause)
653658
NODE_ENUM(common, OmpAtomicDefaultMemOrderType)
654659
NODE(parser, OpenMPDepobjConstruct)
660+
NODE(parser, OpenMPErrorConstruct)
655661
NODE(parser, OpenMPFlushConstruct)
656662
NODE(parser, OpenMPLoopConstruct)
657663
NODE(parser, OpenMPExecutableAllocate)

flang/include/flang/Parser/parse-tree.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3761,6 +3761,13 @@ struct OmpAllocateClause {
37613761
std::tuple<MODIFIERS(), OmpObjectList> t;
37623762
};
37633763

3764+
// Ref: [5.2:216-217 (sort of, as it's only mentioned in passing)
3765+
// AT(compilation|execution)
3766+
struct OmpAtClause {
3767+
ENUM_CLASS(ActionTime, Compilation, Execution);
3768+
WRAPPER_CLASS_BOILERPLATE(OmpAtClause, ActionTime);
3769+
};
3770+
37643771
// Ref: [5.0:60-63], [5.1:83-86], [5.2:210-213]
37653772
//
37663773
// atomic-default-mem-order-clause ->
@@ -4008,6 +4015,13 @@ struct OmpMapClause {
40084015
std::tuple<MODIFIERS(), OmpObjectList, bool> t;
40094016
};
40104017

4018+
// Ref: [5.2:217-218]
4019+
// message-clause ->
4020+
// MESSAGE("message-text")
4021+
struct OmpMessageClause {
4022+
WRAPPER_CLASS_BOILERPLATE(OmpMessageClause, std::string);
4023+
};
4024+
40114025
// Ref: [4.5:87-91], [5.0:140-146], [5.1:166-171], [5.2:270]
40124026
//
40134027
// num-tasks-clause ->
@@ -4070,6 +4084,14 @@ struct OmpScheduleClause {
40704084
std::tuple<MODIFIERS(), Kind, std::optional<ScalarIntExpr>> t;
40714085
};
40724086

4087+
// REF: [5.2:217]
4088+
// severity-clause ->
4089+
// SEVERITY(warning|fatal)
4090+
struct OmpSeverityClause {
4091+
ENUM_CLASS(Severity, Fatal, Warning);
4092+
WRAPPER_CLASS_BOILERPLATE(OmpSeverityClause, Severity);
4093+
};
4094+
40734095
// Ref: [4.5:107-109], [5.0:176-180], [5.1:205-210], [5.2:167-168]
40744096
//
40754097
// to-clause (in DECLARE TARGET) ->
@@ -4445,6 +4467,14 @@ struct OpenMPDepobjConstruct {
44454467
std::tuple<Verbatim, OmpObject, OmpClause> t;
44464468
};
44474469

4470+
// Ref: OpenMP [5.2:216-218]
4471+
// ERROR AT(compilation|execution) SEVERITY(fatal|warning) MESSAGE("msg-str)
4472+
struct OpenMPErrorConstruct {
4473+
TUPLE_CLASS_BOILERPLATE(OpenMPErrorConstruct);
4474+
CharBlock source;
4475+
std::tuple<Verbatim, OmpClauseList> t;
4476+
};
4477+
44484478
// 2.17.8 flush -> FLUSH [memory-order-clause] [(variable-name-list)]
44494479
struct OpenMPFlushConstruct {
44504480
TUPLE_CLASS_BOILERPLATE(OpenMPFlushConstruct);
@@ -4517,7 +4547,7 @@ struct OpenMPConstruct {
45174547
UNION_CLASS_BOILERPLATE(OpenMPConstruct);
45184548
std::variant<OpenMPStandaloneConstruct, OpenMPSectionsConstruct,
45194549
OpenMPSectionConstruct, OpenMPLoopConstruct, OpenMPBlockConstruct,
4520-
OpenMPAtomicConstruct, OpenMPDeclarativeAllocate,
4550+
OpenMPAtomicConstruct, OpenMPDeclarativeAllocate, OpenMPErrorConstruct,
45214551
OpenMPExecutableAllocate, OpenMPAllocatorsConstruct,
45224552
OpenMPCriticalConstruct>
45234553
u;

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2905,6 +2905,13 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
29052905
queue.begin(), name);
29062906
}
29072907

2908+
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
2909+
semantics::SemanticsContext &semaCtx,
2910+
lower::pft::Evaluation &eval,
2911+
const parser::OpenMPErrorConstruct &) {
2912+
TODO(converter.getCurrentLocation(), "OpenMPErrorConstruct");
2913+
}
2914+
29082915
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
29092916
semantics::SemanticsContext &semaCtx,
29102917
lower::pft::Evaluation &eval,

flang/lib/Parser/openmp-parsers.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,16 @@ TYPE_PARSER(construct<OmpBindClause>(
507507
"TEAMS" >> pure(OmpBindClause::Binding::Teams) ||
508508
"THREAD" >> pure(OmpBindClause::Binding::Thread)))
509509

510+
TYPE_PARSER(construct<OmpAtClause>(
511+
"EXECUTION" >> pure(OmpAtClause::ActionTime::Execution) ||
512+
"COMPILATION" >> pure(OmpAtClause::ActionTime::Compilation)))
513+
514+
TYPE_PARSER(construct<OmpSeverityClause>(
515+
"FATAL" >> pure(OmpSeverityClause::Severity::Fatal) ||
516+
"WARNING" >> pure(OmpSeverityClause::Severity::Warning)))
517+
518+
TYPE_PARSER(construct<OmpMessageClause>(charLiteralConstantWithoutKind))
519+
510520
TYPE_PARSER(
511521
"ACQUIRE" >> construct<OmpClause>(construct<OmpClause::Acquire>()) ||
512522
"ACQ_REL" >> construct<OmpClause>(construct<OmpClause::AcqRel>()) ||
@@ -518,6 +528,8 @@ TYPE_PARSER(
518528
parenthesized(Parser<OmpAllocateClause>{}))) ||
519529
"ALLOCATOR" >> construct<OmpClause>(construct<OmpClause::Allocator>(
520530
parenthesized(scalarIntExpr))) ||
531+
"AT" >> construct<OmpClause>(construct<OmpClause::At>(
532+
parenthesized(Parser<OmpAtClause>{}))) ||
521533
"ATOMIC_DEFAULT_MEM_ORDER" >>
522534
construct<OmpClause>(construct<OmpClause::AtomicDefaultMemOrder>(
523535
parenthesized(Parser<OmpAtomicDefaultMemOrderClause>{}))) ||
@@ -585,6 +597,8 @@ TYPE_PARSER(
585597
"MAP" >> construct<OmpClause>(construct<OmpClause::Map>(
586598
parenthesized(Parser<OmpMapClause>{}))) ||
587599
"MERGEABLE" >> construct<OmpClause>(construct<OmpClause::Mergeable>()) ||
600+
"MESSAGE" >> construct<OmpClause>(construct<OmpClause::Message>(
601+
parenthesized(Parser<OmpMessageClause>{}))) ||
588602
"NOGROUP" >> construct<OmpClause>(construct<OmpClause::Nogroup>()) ||
589603
"NONTEMPORAL" >> construct<OmpClause>(construct<OmpClause::Nontemporal>(
590604
parenthesized(nonemptyList(name)))) ||
@@ -627,6 +641,8 @@ TYPE_PARSER(
627641
"SCHEDULE" >> construct<OmpClause>(construct<OmpClause::Schedule>(
628642
parenthesized(Parser<OmpScheduleClause>{}))) ||
629643
"SEQ_CST" >> construct<OmpClause>(construct<OmpClause::SeqCst>()) ||
644+
"SEVERITY" >> construct<OmpClause>(construct<OmpClause::Severity>(
645+
parenthesized(Parser<OmpSeverityClause>{}))) ||
630646
"SHARED" >> construct<OmpClause>(construct<OmpClause::Shared>(
631647
parenthesized(Parser<OmpObjectList>{}))) ||
632648
"SIMD"_id >> construct<OmpClause>(construct<OmpClause::Simd>()) ||
@@ -946,6 +962,9 @@ TYPE_PARSER(sourced(construct<OmpCriticalDirective>(verbatim("CRITICAL"_tok),
946962
TYPE_PARSER(construct<OpenMPCriticalConstruct>(
947963
Parser<OmpCriticalDirective>{}, block, Parser<OmpEndCriticalDirective>{}))
948964

965+
TYPE_PARSER(sourced(construct<OpenMPErrorConstruct>(
966+
verbatim("ERROR"_tok), Parser<OmpClauseList>{})))
967+
949968
// 2.11.3 Executable Allocate directive
950969
TYPE_PARSER(
951970
sourced(construct<OpenMPExecutableAllocate>(verbatim("ALLOCATE"_tok),
@@ -1043,6 +1062,7 @@ TYPE_CONTEXT_PARSER("OpenMP construct"_en_US,
10431062
// OpenMPStandaloneConstruct to resolve !$OMP ORDERED
10441063
construct<OpenMPConstruct>(Parser<OpenMPStandaloneConstruct>{}),
10451064
construct<OpenMPConstruct>(Parser<OpenMPAtomicConstruct>{}),
1065+
construct<OpenMPConstruct>(Parser<OpenMPErrorConstruct>{}),
10461066
construct<OpenMPConstruct>(Parser<OpenMPExecutableAllocate>{}),
10471067
construct<OpenMPConstruct>(Parser<OpenMPAllocatorsConstruct>{}),
10481068
construct<OpenMPConstruct>(Parser<OpenMPDeclarativeAllocate>{}),

flang/lib/Parser/unparse.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,6 +2651,17 @@ class UnparseVisitor {
26512651
Put(")\n");
26522652
EndOpenMP();
26532653
}
2654+
bool Pre(const OmpMessageClause &x) {
2655+
Word("\"");
2656+
Walk(x.v);
2657+
Put("\"");
2658+
return false;
2659+
}
2660+
void Unparse(const OpenMPErrorConstruct &x) {
2661+
Word("!$OMP ERROR ");
2662+
Walk(x.t);
2663+
Put("\n");
2664+
}
26542665
void Unparse(const OmpSectionsDirective &x) {
26552666
switch (x.v) {
26562667
case llvm::omp::Directive::OMPD_sections:
@@ -2835,6 +2846,7 @@ class UnparseVisitor {
28352846
WALK_NESTED_ENUM(InquireSpec::LogVar, Kind)
28362847
WALK_NESTED_ENUM(ProcedureStmt, Kind) // R1506
28372848
WALK_NESTED_ENUM(UseStmt, ModuleNature) // R1410
2849+
WALK_NESTED_ENUM(OmpAtClause, ActionTime) // OMP at
28382850
WALK_NESTED_ENUM(OmpBindClause, Binding) // OMP bind
28392851
WALK_NESTED_ENUM(OmpProcBindClause, AffinityPolicy) // OMP proc_bind
28402852
WALK_NESTED_ENUM(OmpDefaultClause, DataSharingAttribute) // OMP default
@@ -2846,6 +2858,7 @@ class UnparseVisitor {
28462858
WALK_NESTED_ENUM(OmpOrderingModifier, Value) // OMP ordering-modifier
28472859
WALK_NESTED_ENUM(OmpTaskDependenceType, Value) // OMP task-dependence-type
28482860
WALK_NESTED_ENUM(OmpScheduleClause, Kind) // OMP schedule-kind
2861+
WALK_NESTED_ENUM(OmpSeverityClause, Severity) // OMP severity
28492862
WALK_NESTED_ENUM(OmpDeviceModifier, Value) // OMP device modifier
28502863
WALK_NESTED_ENUM(
28512864
OmpDeviceTypeClause, DeviceTypeDescription) // OMP device_type

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,15 @@ void OmpStructureChecker::Leave(const parser::OpenMPDeclareTargetConstruct &x) {
16621662
dirContext_.pop_back();
16631663
}
16641664

1665+
void OmpStructureChecker::Enter(const parser::OpenMPErrorConstruct &x) {
1666+
const auto &dir{std::get<parser::Verbatim>(x.t)};
1667+
PushContextAndClauseSets(dir.source, llvm::omp::Directive::OMPD_error);
1668+
}
1669+
1670+
void OmpStructureChecker::Leave(const parser::OpenMPErrorConstruct &x) {
1671+
dirContext_.pop_back();
1672+
}
1673+
16651674
void OmpStructureChecker::Enter(const parser::OpenMPExecutableAllocate &x) {
16661675
isPredefinedAllocator = true;
16671676
const auto &dir{std::get<parser::Verbatim>(x.t)};

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ class OmpStructureChecker
102102
void Enter(const parser::OmpDeclareTargetWithList &);
103103
void Enter(const parser::OmpDeclareTargetWithClause &);
104104
void Leave(const parser::OmpDeclareTargetWithClause &);
105+
void Enter(const parser::OpenMPErrorConstruct &);
106+
void Leave(const parser::OpenMPErrorConstruct &);
105107
void Enter(const parser::OpenMPExecutableAllocate &);
106108
void Leave(const parser::OpenMPExecutableAllocate &);
107109
void Enter(const parser::OpenMPAllocatorsConstruct &);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
! RUN: %not_todo_cmd %flang_fc1 -emit-fir -fopenmp -fopenmp-version=51 -o - %s 2>&1 | FileCheck %s
2+
3+
! CHECK: not yet implemented: OpenMPErrorConstruct
4+
program p
5+
integer, allocatable :: x
6+
!$omp error at(compilation) severity(warning) message("an error")
7+
end program p
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
! RUN: %flang_fc1 -fopenmp-version=51 -fopenmp -fdebug-unparse-no-sema %s 2>&1 | FileCheck %s
2+
program main
3+
!CHECK: !$OMP ERROR AT(COMPILATION) SEVERITY(WARNING) MESSAGE("some message here")
4+
!$omp error at(compilation) severity(warning) message("some message here")
5+
end program main

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def OMPC_AppendArgs : Clause<"append_args"> {
6666
}
6767
def OMPC_At : Clause<"at"> {
6868
let clangClass = "OMPAtClause";
69+
let flangClass = "OmpAtClause";
6970
}
7071
def OMPC_AtomicDefaultMemOrder : Clause<"atomic_default_mem_order"> {
7172
let clangClass = "OMPAtomicDefaultMemOrderClause";
@@ -287,6 +288,7 @@ def OMPC_Mergeable : Clause<"mergeable"> {
287288
}
288289
def OMPC_Message : Clause<"message"> {
289290
let clangClass = "OMPMessageClause";
291+
let flangClass = "OmpMessageClause";
290292
}
291293
def OMPC_NoOpenMP : Clause<"no_openmp"> {
292294
let clangClass = "OMPNoOpenMPClause";
@@ -444,6 +446,7 @@ def OMPC_SeqCst : Clause<"seq_cst"> {
444446
}
445447
def OMPC_Severity : Clause<"severity"> {
446448
let clangClass = "OMPSeverityClause";
449+
let flangClass = "OmpSeverityClause";
447450
}
448451
def OMPC_Shared : Clause<"shared"> {
449452
let clangClass = "OMPSharedClause";

0 commit comments

Comments
 (0)