[flang-commits] [flang] [flang][cuda] Allow list-directed PRINT and WRITE stmt in device code (PR #87415)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Mon Apr 8 07:40:04 PDT 2024
================
@@ -275,9 +275,74 @@ template <bool IsCUFKernelDo> class DeviceContextChecker {
},
ec.u);
}
+ template <typename SEEK, typename A>
+ static const auto *GetIOControl(const A &stmt) {
+ for (const auto &spec : stmt.controls) {
+ if (const auto *result = std::get_if<SEEK>(&spec.u)) {
+ return result;
+ }
+ }
+ return static_cast<const SEEK *>(nullptr);
+ }
+ template <typename A> static bool IsInternalIO(const A &stmt) {
+ if (stmt.iounit.has_value()) {
+ return std::holds_alternative<Fortran::parser::Variable>(stmt.iounit->u);
+ }
+ if (auto *unit = GetIOControl<Fortran::parser::IoUnit>(stmt)) {
+ return std::holds_alternative<Fortran::parser::Variable>(unit->u);
+ }
+ return false;
+ }
+ void WarnOnIoStmt(const parser::CharBlock &source) {
+ context_.Say(
+ source, "I/O statement might not be supported on device"_warn_en_US);
+ }
+ template <typename A>
+ void WarnIfNotInternal(const A &stmt, const parser::CharBlock &source) {
+ if (!IsInternalIO(stmt)) {
+ WarnOnIoStmt(source);
+ }
+ }
void Check(const parser::ActionStmt &stmt, const parser::CharBlock &source) {
common::visit(
common::visitors{
+ [&](const common::Indirection<parser::PrintStmt> &) {},
+ [&](const common::Indirection<parser::WriteStmt> &x) {
+ if (x.value().format) { // Formatted write to '*' or '6'
+ if (std::holds_alternative<Fortran::parser::Star>(
+ x.value().format->u)) {
+ if (x.value().iounit) {
----------------
klausler wrote:
This `if` construct is not useful if the code is just going to always `return` anyway afterwards.
https://github.com/llvm/llvm-project/pull/87415
More information about the flang-commits
mailing list