Skip to content

Commit 56adc94

Browse files
committed
Limit the reduction type to trivial types or derived types containing trivial ones.
1 parent 3400964 commit 56adc94

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3641,6 +3641,20 @@ processReductionCombiner(lower::AbstractConverter &converter,
36413641
return genCombinerCB;
36423642
}
36433643

3644+
// Checks that the reduction type is either a trivial type or a derived type
3645+
// of trivial types.
3646+
static bool isSimpleReductionType(mlir::Type reductionType) {
3647+
if (fir::isa_trivial(reductionType))
3648+
return true;
3649+
if (auto recordTy = mlir::dyn_cast<fir::RecordType>(reductionType)) {
3650+
for (auto [_, fieldType] : recordTy.getTypeList()) {
3651+
if (!fir::isa_trivial(fieldType))
3652+
return false;
3653+
}
3654+
}
3655+
return true;
3656+
}
3657+
36443658
// Getting the type from a symbol compared to a DeclSpec is simpler since we do
36453659
// not need to consider derived vs intrinsic types. Semantics is guaranteed to
36463660
// generate these symbols.
@@ -3658,6 +3672,11 @@ getReductionType(lower::AbstractConverter &converter,
36583672
const auto &name = std::get<parser::ObjectName>(decl.var.t);
36593673
const auto &symbol = semantics::SymbolRef(*name.symbol);
36603674
mlir::Type reductionType = converter.genType(symbol);
3675+
3676+
if (!isSimpleReductionType(reductionType))
3677+
TODO(converter.getCurrentLocation(),
3678+
"declare reduction using currently only supports trival types or "
3679+
"derived types containing trivial types");
36613680
return reductionType;
36623681
}
36633682

0 commit comments

Comments
 (0)