Skip to content

Commit 2c31bc7

Browse files
authored
[flang][Semantics][OpenMP] Fix ICE for unknown reduction starting with . (#94398)
In this case the union inside of the `parser::DefinedOperator` contains a string name instead of the expected `parser::DefinedOperator::IntrinsicOperator`. This led to a `std::abort`. This patch adapts the code so that if it contains a string name we emit a semantic error.
1 parent 05e1b53 commit 2c31bc7

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,9 +2321,15 @@ bool OmpStructureChecker::CheckReductionOperators(
23212321
common::visit(
23222322
common::visitors{
23232323
[&](const parser::DefinedOperator &dOpr) {
2324-
const auto &intrinsicOp{
2325-
std::get<parser::DefinedOperator::IntrinsicOperator>(dOpr.u)};
2326-
ok = CheckIntrinsicOperator(intrinsicOp);
2324+
if (const auto *intrinsicOp{
2325+
std::get_if<parser::DefinedOperator::IntrinsicOperator>(
2326+
&dOpr.u)}) {
2327+
ok = CheckIntrinsicOperator(*intrinsicOp);
2328+
} else {
2329+
context_.Say(GetContext().clauseSource,
2330+
"Invalid reduction operator in REDUCTION clause."_err_en_US,
2331+
ContextDirectiveAsFortran());
2332+
}
23272333
},
23282334
[&](const parser::ProcedureDesignator &procD) {
23292335
const parser::Name *name{std::get_if<parser::Name>(&procD.u)};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
! RUN: %python %S/../test_errors.py %s %flang_fc1 -fopenmp
2+
! OpenMP Version 4.5
3+
! 2.15.3.6 Reduction Clause
4+
program omp_reduction
5+
integer :: k
6+
! misspelling. Should be "min"
7+
!ERROR: Invalid reduction operator in REDUCTION clause.
8+
!$omp parallel reduction(.min.:k)
9+
!$omp end parallel
10+
end program omp_reduction

0 commit comments

Comments
 (0)