Skip to content

Conversation

klausler
Copy link
Contributor

Revert "[flang][runtime] Another try to fix build failure"

This reverts commit 13869ca.

Revert "[flang][runtime] Fix build bot flang-runtime-cuda-gcc errors (#143650)"

This reverts commit d75e284.

Revert "[flang][runtime] Replace recursion with iterative work queue (#137727)"

This reverts commit 163c67a.

This reverts commit 13869ca.

Revert "[flang][runtime] Fix build bot flang-runtime-cuda-gcc errors (llvm#143650)"

This reverts commit d75e284.

Revert "[flang][runtime] Replace recursion with iterative work queue (llvm#137727)"

This reverts commit 163c67a.
@klausler klausler requested a review from jeanPerier June 11, 2025 14:41
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir flang:semantics labels Jun 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 11, 2025

@llvm/pr-subscribers-flang-semantics

@llvm/pr-subscribers-flang-fir-hlfir

Author: Peter Klausler (klausler)

Changes

Revert "[flang][runtime] Another try to fix build failure"

This reverts commit 13869ca.

Revert "[flang][runtime] Fix build bot flang-runtime-cuda-gcc errors (#143650)"

This reverts commit d75e284.

Revert "[flang][runtime] Replace recursion with iterative work queue (#137727)"

This reverts commit 163c67a.


Patch is 216.55 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/143713.diff

31 Files Affected:

  • (modified) flang-rt/include/flang-rt/runtime/environment.h (-3)
  • (modified) flang-rt/include/flang-rt/runtime/stat.h (+3-7)
  • (modified) flang-rt/include/flang-rt/runtime/type-info.h (-2)
  • (removed) flang-rt/include/flang-rt/runtime/work-queue.h (-552)
  • (modified) flang-rt/lib/runtime/CMakeLists.txt (-2)
  • (modified) flang-rt/lib/runtime/assign.cpp (+224-399)
  • (modified) flang-rt/lib/runtime/derived.cpp (+239-278)
  • (modified) flang-rt/lib/runtime/descriptor-io.cpp (+4-647)
  • (modified) flang-rt/lib/runtime/descriptor-io.h (+606-14)
  • (modified) flang-rt/lib/runtime/environment.cpp (-4)
  • (modified) flang-rt/lib/runtime/namelist.cpp (-1)
  • (modified) flang-rt/lib/runtime/tools.cpp (+2-2)
  • (modified) flang-rt/lib/runtime/type-info.cpp (+3-3)
  • (removed) flang-rt/lib/runtime/work-queue.cpp (-161)
  • (modified) flang-rt/unittests/Runtime/ExternalIOTest.cpp (+1-1)
  • (modified) flang/docs/Extensions.md (-10)
  • (modified) flang/include/flang/Runtime/assign.h (+1-1)
  • (modified) flang/include/flang/Semantics/tools.h (+2-5)
  • (modified) flang/lib/Semantics/runtime-type-info.cpp (-4)
  • (modified) flang/lib/Semantics/tools.cpp (-32)
  • (modified) flang/module/__fortran_type_info.f90 (+1-2)
  • (modified) flang/test/Lower/volatile-openmp.f90 (+4-4)
  • (modified) flang/test/Semantics/typeinfo01.f90 (+15-15)
  • (modified) flang/test/Semantics/typeinfo03.f90 (+1-1)
  • (modified) flang/test/Semantics/typeinfo04.f90 (+4-4)
  • (modified) flang/test/Semantics/typeinfo05.f90 (+2-2)
  • (modified) flang/test/Semantics/typeinfo06.f90 (+2-2)
  • (modified) flang/test/Semantics/typeinfo07.f90 (+4-4)
  • (modified) flang/test/Semantics/typeinfo08.f90 (+1-1)
  • (modified) flang/test/Semantics/typeinfo11.f90 (+1-1)
  • (removed) flang/test/Semantics/typeinfo12.f90 (-67)
diff --git a/flang-rt/include/flang-rt/runtime/environment.h b/flang-rt/include/flang-rt/runtime/environment.h
index e579f6012ce86..16258b3bbba9b 100644
--- a/flang-rt/include/flang-rt/runtime/environment.h
+++ b/flang-rt/include/flang-rt/runtime/environment.h
@@ -64,9 +64,6 @@ struct ExecutionEnvironment {
   bool defaultUTF8{false}; // DEFAULT_UTF8
   bool checkPointerDeallocation{true}; // FORT_CHECK_POINTER_DEALLOCATION
 
-  enum InternalDebugging { WorkQueue = 1 };
-  int internalDebugging{0}; // FLANG_RT_DEBUG
-
   // CUDA related variables
   std::size_t cudaStackLimit{0}; // ACC_OFFLOAD_STACK_SIZE
   bool cudaDeviceIsManaged{false}; // NV_CUDAFOR_DEVICE_IS_MANAGED
diff --git a/flang-rt/include/flang-rt/runtime/stat.h b/flang-rt/include/flang-rt/runtime/stat.h
index dc372de53506a..070d0bf8673fb 100644
--- a/flang-rt/include/flang-rt/runtime/stat.h
+++ b/flang-rt/include/flang-rt/runtime/stat.h
@@ -24,7 +24,7 @@ class Terminator;
 enum Stat {
   StatOk = 0, // required to be zero by Fortran
 
-  // Interoperable STAT= codes (>= 11)
+  // Interoperable STAT= codes
   StatBaseNull = CFI_ERROR_BASE_ADDR_NULL,
   StatBaseNotNull = CFI_ERROR_BASE_ADDR_NOT_NULL,
   StatInvalidElemLen = CFI_INVALID_ELEM_LEN,
@@ -36,7 +36,7 @@ enum Stat {
   StatMemAllocation = CFI_ERROR_MEM_ALLOCATION,
   StatOutOfBounds = CFI_ERROR_OUT_OF_BOUNDS,
 
-  // Standard STAT= values (>= 101)
+  // Standard STAT= values
   StatFailedImage = FORTRAN_RUNTIME_STAT_FAILED_IMAGE,
   StatLocked = FORTRAN_RUNTIME_STAT_LOCKED,
   StatLockedOtherImage = FORTRAN_RUNTIME_STAT_LOCKED_OTHER_IMAGE,
@@ -49,14 +49,10 @@ enum Stat {
   // Additional "processor-defined" STAT= values
   StatInvalidArgumentNumber = FORTRAN_RUNTIME_STAT_INVALID_ARG_NUMBER,
   StatMissingArgument = FORTRAN_RUNTIME_STAT_MISSING_ARG,
-  StatValueTooShort = FORTRAN_RUNTIME_STAT_VALUE_TOO_SHORT, // -1
+  StatValueTooShort = FORTRAN_RUNTIME_STAT_VALUE_TOO_SHORT,
   StatMoveAllocSameAllocatable =
       FORTRAN_RUNTIME_STAT_MOVE_ALLOC_SAME_ALLOCATABLE,
   StatBadPointerDeallocation = FORTRAN_RUNTIME_STAT_BAD_POINTER_DEALLOCATION,
-
-  // Dummy status for work queue continuation, declared here to perhaps
-  // avoid collisions
-  StatContinue = 201
 };
 
 RT_API_ATTRS const char *StatErrorString(int);
diff --git a/flang-rt/include/flang-rt/runtime/type-info.h b/flang-rt/include/flang-rt/runtime/type-info.h
index 9bde3adba87f5..5e79efde164f2 100644
--- a/flang-rt/include/flang-rt/runtime/type-info.h
+++ b/flang-rt/include/flang-rt/runtime/type-info.h
@@ -240,7 +240,6 @@ class DerivedType {
   RT_API_ATTRS bool noFinalizationNeeded() const {
     return noFinalizationNeeded_;
   }
-  RT_API_ATTRS bool noDefinedAssignment() const { return noDefinedAssignment_; }
 
   RT_API_ATTRS std::size_t LenParameters() const {
     return lenParameterKind().Elements();
@@ -323,7 +322,6 @@ class DerivedType {
   bool noInitializationNeeded_{false};
   bool noDestructionNeeded_{false};
   bool noFinalizationNeeded_{false};
-  bool noDefinedAssignment_{false};
 };
 
 } // namespace Fortran::runtime::typeInfo
diff --git a/flang-rt/include/flang-rt/runtime/work-queue.h b/flang-rt/include/flang-rt/runtime/work-queue.h
deleted file mode 100644
index f8cc820c06ca1..0000000000000
--- a/flang-rt/include/flang-rt/runtime/work-queue.h
+++ /dev/null
@@ -1,552 +0,0 @@
-//===-- include/flang-rt/runtime/work-queue.h -------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// Internal runtime utilities for work queues that replace the use of recursion
-// for better GPU device support.
-//
-// A work queue comprises a list of tickets.  Each ticket class has a Begin()
-// member function, which is called once, and a Continue() member function
-// that can be called zero or more times.  A ticket's execution terminates
-// when either of these member functions returns a status other than
-// StatContinue.  When that status is not StatOk, then the whole queue
-// is shut down.
-//
-// By returning StatContinue from its Continue() member function,
-// a ticket suspends its execution so that any nested tickets that it
-// may have created can be run to completion.  It is the reponsibility
-// of each ticket class to maintain resumption information in its state
-// and manage its own progress.  Most ticket classes inherit from
-// class ComponentsOverElements, which implements an outer loop over all
-// components of a derived type, and an inner loop over all elements
-// of a descriptor, possibly with multiple phases of execution per element.
-//
-// Tickets are created by WorkQueue::Begin...() member functions.
-// There is one of these for each "top level" recursive function in the
-// Fortran runtime support library that has been restructured into this
-// ticket framework.
-//
-// When the work queue is running tickets, it always selects the last ticket
-// on the list for execution -- "work stack" might have been a more accurate
-// name for this framework.  This ticket may, while doing its job, create
-// new tickets, and since those are pushed after the active one, the first
-// such nested ticket will be the next one executed to completion -- i.e.,
-// the order of nested WorkQueue::Begin...() calls is respected.
-// Note that a ticket's Continue() member function won't be called again
-// until all nested tickets have run to completion and it is once again
-// the last ticket on the queue.
-//
-// Example for an assignment to a derived type:
-// 1. Assign() is called, and its work queue is created.  It calls
-//    WorkQueue::BeginAssign() and then WorkQueue::Run().
-// 2. Run calls AssignTicket::Begin(), which pushes a tickets via
-//    BeginFinalize() and returns StatContinue.
-// 3. FinalizeTicket::Begin() and FinalizeTicket::Continue() are called
-//    until one of them returns StatOk, which ends the finalization ticket.
-// 4. AssignTicket::Continue() is then called; it creates a DerivedAssignTicket
-//    and then returns StatOk, which ends the ticket.
-// 5. At this point, only one ticket remains.  DerivedAssignTicket::Begin()
-//    and ::Continue() are called until they are done (not StatContinue).
-//    Along the way, it may create nested AssignTickets for components,
-//    and suspend itself so that they may each run to completion.
-
-#ifndef FLANG_RT_RUNTIME_WORK_QUEUE_H_
-#define FLANG_RT_RUNTIME_WORK_QUEUE_H_
-
-#include "flang-rt/runtime/connection.h"
-#include "flang-rt/runtime/descriptor.h"
-#include "flang-rt/runtime/stat.h"
-#include "flang-rt/runtime/type-info.h"
-#include "flang/Common/api-attrs.h"
-#include "flang/Runtime/freestanding-tools.h"
-#include <flang/Common/variant.h>
-
-namespace Fortran::runtime::io {
-class IoStatementState;
-struct NonTbpDefinedIoTable;
-} // namespace Fortran::runtime::io
-
-namespace Fortran::runtime {
-class Terminator;
-class WorkQueue;
-
-// Ticket worker base classes
-
-template <typename TICKET> class ImmediateTicketRunner {
-public:
-  RT_API_ATTRS explicit ImmediateTicketRunner(TICKET &ticket)
-      : ticket_{ticket} {}
-  RT_API_ATTRS int Run(WorkQueue &workQueue) {
-    int status{ticket_.Begin(workQueue)};
-    while (status == StatContinue) {
-      status = ticket_.Continue(workQueue);
-    }
-    return status;
-  }
-
-private:
-  TICKET &ticket_;
-};
-
-// Base class for ticket workers that operate elementwise over descriptors
-class Elementwise {
-public:
-  RT_API_ATTRS Elementwise(
-      const Descriptor &instance, const Descriptor *from = nullptr)
-      : instance_{instance}, from_{from} {
-    instance_.GetLowerBounds(subscripts_);
-    if (from_) {
-      from_->GetLowerBounds(fromSubscripts_);
-    }
-  }
-  RT_API_ATTRS bool IsComplete() const { return elementAt_ >= elements_; }
-  RT_API_ATTRS void Advance() {
-    ++elementAt_;
-    instance_.IncrementSubscripts(subscripts_);
-    if (from_) {
-      from_->IncrementSubscripts(fromSubscripts_);
-    }
-  }
-  RT_API_ATTRS void SkipToEnd() { elementAt_ = elements_; }
-  RT_API_ATTRS void Reset() {
-    elementAt_ = 0;
-    instance_.GetLowerBounds(subscripts_);
-    if (from_) {
-      from_->GetLowerBounds(fromSubscripts_);
-    }
-  }
-
-protected:
-  const Descriptor &instance_, *from_{nullptr};
-  std::size_t elements_{instance_.Elements()};
-  std::size_t elementAt_{0};
-  SubscriptValue subscripts_[common::maxRank];
-  SubscriptValue fromSubscripts_[common::maxRank];
-};
-
-// Base class for ticket workers that operate over derived type components.
-class Componentwise {
-public:
-  RT_API_ATTRS Componentwise(const typeInfo::DerivedType &);
-  RT_API_ATTRS bool IsComplete() const { return componentAt_ >= components_; }
-  RT_API_ATTRS void Advance() {
-    ++componentAt_;
-    GetComponent();
-  }
-  RT_API_ATTRS void SkipToEnd() {
-    component_ = nullptr;
-    componentAt_ = components_;
-  }
-  RT_API_ATTRS void Reset() {
-    component_ = nullptr;
-    componentAt_ = 0;
-    GetComponent();
-  }
-  RT_API_ATTRS void GetComponent();
-
-protected:
-  const typeInfo::DerivedType &derived_;
-  std::size_t components_{0}, componentAt_{0};
-  const typeInfo::Component *component_{nullptr};
-  StaticDescriptor<common::maxRank, true, 0> componentDescriptor_;
-};
-
-// Base class for ticket workers that operate over derived type components
-// in an outer loop, and elements in an inner loop.
-class ComponentsOverElements : public Componentwise, public Elementwise {
-public:
-  RT_API_ATTRS ComponentsOverElements(const Descriptor &instance,
-      const typeInfo::DerivedType &derived, const Descriptor *from = nullptr)
-      : Componentwise{derived}, Elementwise{instance, from} {
-    if (Elementwise::IsComplete()) {
-      Componentwise::SkipToEnd();
-    }
-  }
-  RT_API_ATTRS bool IsComplete() const { return Componentwise::IsComplete(); }
-  RT_API_ATTRS void Advance() {
-    SkipToNextElement();
-    if (Elementwise::IsComplete()) {
-      Elementwise::Reset();
-      Componentwise::Advance();
-    }
-  }
-  RT_API_ATTRS void SkipToNextElement() {
-    phase_ = 0;
-    Elementwise::Advance();
-  }
-  RT_API_ATTRS void SkipToNextComponent() {
-    phase_ = 0;
-    Elementwise::Reset();
-    Componentwise::Advance();
-  }
-  RT_API_ATTRS void Reset() {
-    phase_ = 0;
-    Elementwise::Reset();
-    Componentwise::Reset();
-  }
-
-protected:
-  int phase_{0};
-};
-
-// Base class for ticket workers that operate over elements in an outer loop,
-// type components in an inner loop.
-class ElementsOverComponents : public Elementwise, public Componentwise {
-public:
-  RT_API_ATTRS ElementsOverComponents(const Descriptor &instance,
-      const typeInfo::DerivedType &derived, const Descriptor *from = nullptr)
-      : Elementwise{instance, from}, Componentwise{derived} {
-    if (Componentwise::IsComplete()) {
-      Elementwise::SkipToEnd();
-    }
-  }
-  RT_API_ATTRS bool IsComplete() const { return Elementwise::IsComplete(); }
-  RT_API_ATTRS void Advance() {
-    SkipToNextComponent();
-    if (Componentwise::IsComplete()) {
-      Componentwise::Reset();
-      Elementwise::Advance();
-    }
-  }
-  RT_API_ATTRS void SkipToNextComponent() {
-    phase_ = 0;
-    Componentwise::Advance();
-  }
-  RT_API_ATTRS void SkipToNextElement() {
-    phase_ = 0;
-    Componentwise::Reset();
-    Elementwise::Advance();
-  }
-
-protected:
-  int phase_{0};
-};
-
-// Ticket worker classes
-
-// Implements derived type instance initialization
-class InitializeTicket : public ImmediateTicketRunner<InitializeTicket>,
-                         private ComponentsOverElements {
-public:
-  RT_API_ATTRS InitializeTicket(
-      const Descriptor &instance, const typeInfo::DerivedType &derived)
-      : ImmediateTicketRunner<InitializeTicket>{*this},
-        ComponentsOverElements{instance, derived} {}
-  RT_API_ATTRS int Begin(WorkQueue &);
-  RT_API_ATTRS int Continue(WorkQueue &);
-};
-
-// Initializes one derived type instance from the value of another
-class InitializeCloneTicket
-    : public ImmediateTicketRunner<InitializeCloneTicket>,
-      private ComponentsOverElements {
-public:
-  RT_API_ATTRS InitializeCloneTicket(const Descriptor &clone,
-      const Descriptor &original, const typeInfo::DerivedType &derived,
-      bool hasStat, const Descriptor *errMsg)
-      : ImmediateTicketRunner<InitializeCloneTicket>{*this},
-        ComponentsOverElements{original, derived}, clone_{clone},
-        hasStat_{hasStat}, errMsg_{errMsg} {}
-  RT_API_ATTRS int Begin(WorkQueue &) { return StatContinue; }
-  RT_API_ATTRS int Continue(WorkQueue &);
-
-private:
-  const Descriptor &clone_;
-  bool hasStat_{false};
-  const Descriptor *errMsg_{nullptr};
-  StaticDescriptor<common::maxRank, true, 0> cloneComponentDescriptor_;
-};
-
-// Implements derived type instance finalization
-class FinalizeTicket : public ImmediateTicketRunner<FinalizeTicket>,
-                       private ComponentsOverElements {
-public:
-  RT_API_ATTRS FinalizeTicket(
-      const Descriptor &instance, const typeInfo::DerivedType &derived)
-      : ImmediateTicketRunner<FinalizeTicket>{*this},
-        ComponentsOverElements{instance, derived} {}
-  RT_API_ATTRS int Begin(WorkQueue &);
-  RT_API_ATTRS int Continue(WorkQueue &);
-
-private:
-  const typeInfo::DerivedType *finalizableParentType_{nullptr};
-};
-
-// Implements derived type instance destruction
-class DestroyTicket : public ImmediateTicketRunner<DestroyTicket>,
-                      private ComponentsOverElements {
-public:
-  RT_API_ATTRS DestroyTicket(const Descriptor &instance,
-      const typeInfo::DerivedType &derived, bool finalize)
-      : ImmediateTicketRunner<DestroyTicket>{*this},
-        ComponentsOverElements{instance, derived}, finalize_{finalize} {}
-  RT_API_ATTRS int Begin(WorkQueue &);
-  RT_API_ATTRS int Continue(WorkQueue &);
-
-private:
-  bool finalize_{false};
-};
-
-// Implements general intrinsic assignment
-class AssignTicket : public ImmediateTicketRunner<AssignTicket> {
-public:
-  RT_API_ATTRS AssignTicket(
-      Descriptor &to, const Descriptor &from, int flags, MemmoveFct memmoveFct)
-      : ImmediateTicketRunner<AssignTicket>{*this}, to_{to}, from_{&from},
-        flags_{flags}, memmoveFct_{memmoveFct} {}
-  RT_API_ATTRS int Begin(WorkQueue &);
-  RT_API_ATTRS int Continue(WorkQueue &);
-
-private:
-  RT_API_ATTRS bool IsSimpleMemmove() const {
-    return !toDerived_ && to_.rank() == from_->rank() && to_.IsContiguous() &&
-        from_->IsContiguous() && to_.ElementBytes() == from_->ElementBytes();
-  }
-  RT_API_ATTRS Descriptor &GetTempDescriptor();
-
-  Descriptor &to_;
-  const Descriptor *from_{nullptr};
-  int flags_{0}; // enum AssignFlags
-  MemmoveFct memmoveFct_{nullptr};
-  StaticDescriptor<common::maxRank, true, 0> tempDescriptor_;
-  const typeInfo::DerivedType *toDerived_{nullptr};
-  Descriptor *toDeallocate_{nullptr};
-  bool persist_{false};
-  bool done_{false};
-};
-
-// Implements derived type intrinsic assignment.
-template <bool IS_COMPONENTWISE>
-class DerivedAssignTicket
-    : public ImmediateTicketRunner<DerivedAssignTicket<IS_COMPONENTWISE>>,
-      private std::conditional_t<IS_COMPONENTWISE, ComponentsOverElements,
-          ElementsOverComponents> {
-public:
-  using Base = std::conditional_t<IS_COMPONENTWISE, ComponentsOverElements,
-      ElementsOverComponents>;
-  RT_API_ATTRS DerivedAssignTicket(const Descriptor &to, const Descriptor &from,
-      const typeInfo::DerivedType &derived, int flags, MemmoveFct memmoveFct,
-      Descriptor *deallocateAfter)
-      : ImmediateTicketRunner<DerivedAssignTicket>{*this},
-        Base{to, derived, &from}, flags_{flags}, memmoveFct_{memmoveFct},
-        deallocateAfter_{deallocateAfter} {}
-  RT_API_ATTRS int Begin(WorkQueue &);
-  RT_API_ATTRS int Continue(WorkQueue &);
-
-private:
-  static constexpr bool isComponentwise_{IS_COMPONENTWISE};
-  bool toIsContiguous_{this->instance_.IsContiguous()};
-  bool fromIsContiguous_{this->from_->IsContiguous()};
-  int flags_{0};
-  MemmoveFct memmoveFct_{nullptr};
-  Descriptor *deallocateAfter_{nullptr};
-  StaticDescriptor<common::maxRank, true, 0> fromComponentDescriptor_;
-};
-
-namespace io::descr {
-
-template <io::Direction DIR>
-class DescriptorIoTicket
-    : public ImmediateTicketRunner<DescriptorIoTicket<DIR>>,
-      private Elementwise {
-public:
-  RT_API_ATTRS DescriptorIoTicket(io::IoStatementState &io,
-      const Descriptor &descriptor, const io::NonTbpDefinedIoTable *table,
-      bool &anyIoTookPlace)
-      : ImmediateTicketRunner<DescriptorIoTicket>(*this),
-        Elementwise{descriptor}, io_{io}, table_{table},
-        anyIoTookPlace_{anyIoTookPlace} {}
-  RT_API_ATTRS int Begin(WorkQueue &);
-  RT_API_ATTRS int Continue(WorkQueue &);
-  RT_API_ATTRS bool &anyIoTookPlace() { return anyIoTookPlace_; }
-
-private:
-  io::IoStatementState &io_;
-  const io::NonTbpDefinedIoTable *table_{nullptr};
-  bool &anyIoTookPlace_;
-  common::optional<typeInfo::SpecialBinding> nonTbpSpecial_;
-  const typeInfo::DerivedType *derived_{nullptr};
-  const typeInfo::SpecialBinding *special_{nullptr};
-  StaticDescriptor<common::maxRank, true, 0> elementDescriptor_;
-};
-
-template <io::Direction DIR>
-class DerivedIoTicket : public ImmediateTicketRunner<DerivedIoTicket<DIR>>,
-                        private ElementsOverComponents {
-public:
-  RT_API_ATTRS DerivedIoTicket(io::IoStatementState &io,
-      const Descriptor &descriptor, const typeInfo::DerivedType &derived,
-      const io::NonTbpDefinedIoTable *table, bool &anyIoTookPlace)
-      : ImmediateTicketRunner<DerivedIoTicket>(*this),
-        ElementsOverComponents{descriptor, derived}, io_{io}, table_{table},
-        anyIoTookPlace_{anyIoTookPlace} {}
-  RT_API_ATTRS int Begin(WorkQueue &) { return StatContinue; }
-  RT_API_ATTRS int Continue(WorkQueue &);
-
-private:
-  io::IoStatementState &io_;
-  const io::NonTbpDefinedIoTable *table_{nullptr};
-  bool &anyIoTookPlace_;
-};
-
-} // namespace io::descr
-
-struct NullTicket {
-  RT_API_ATTRS int Begin(WorkQueue &) const { return StatOk; }
-  RT_API_ATTRS int Continue(WorkQueue &) const { return StatOk; }
-};
-
-struct Ticket {
-  RT_API_ATTRS int Continue(WorkQueue &);
-  bool begun{false};
-  std::variant<NullTicket, InitializeTicket, InitializeCloneTicket,
-      FinalizeTicket, DestroyTicket, AssignTicket, DerivedAssignTicket<false>,
-      DerivedAssignTicket<true>,
-      io::descr::DescriptorIoTicket<io::Direction::Output>,
-      io::descr::DescriptorIoTicket<io::Direction::Input>,
-      io::descr::DerivedIoTicket<io::Direction::Output>,
-      io::descr::DerivedIoTicket<io::Direction::Input>>
-      u;
-};
-
-class WorkQueue {
-public:
-  RT_API_ATTRS explicit WorkQueue(Terminator &terminator)
-      : terminator_{terminator} {
-    for (int j{1}; j < numStatic_; ++j) {
-      static_[j].previous = &static_[j - 1];
-      static_[j - 1].next = &static_[j];
-    }
-  }
-  RT_API_ATTRS ~WorkQueue();
-  RT_API_ATTRS Terminator &terminator() { return terminator_; };
-
-  // APIs for particular tasks.  These can return StatOk if the work is
-  // completed immediately.
-  RT_API_ATTRS int BeginInitialize(
-      const Descriptor &descriptor, const typeInfo::DerivedType &derived) {
-    if (runTicketsImmediately_) {
-      return InitializeTicket{descriptor, derived}.Run(*this);
-    } else {
-      StartTicket().u.emplace<InitializeTicket>(descriptor, derived);
-      return StatContinue;
-    }
-  }
-  RT_API_ATTRS int BeginInitializeClone(const Descriptor &clone,
-      const Descriptor &original, const typeInfo::DerivedType &derived,
-      bool hasStat, const Descriptor *errMsg) {
-    if (runTicketsImmediately_) {
-      return InitializeCloneTicket{clone, original, derived, hasStat, errMsg}
-          .Run(*this);
-    } else {
-      StartTicket().u.emplace<InitializeCloneTicket>(
-          clone, original, derived, hasStat, errMsg);
-      return StatContinue;
-    }
-  }
-  RT_API_ATTRS int BeginFinalize(
-      const Descriptor &descriptor, const typeInfo::DerivedType &derived) {
-    if (runTicketsImmediately_) {
-      return FinalizeTicket{descriptor, derived}.Run(*this);
-    } else {
-      StartTicket().u.emplace<FinalizeTicket>(descriptor, derived);
-    ...
[truncated]

Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- flang-rt/include/flang-rt/runtime/environment.h flang-rt/include/flang-rt/runtime/stat.h flang-rt/include/flang-rt/runtime/type-info.h flang-rt/lib/runtime/assign.cpp flang-rt/lib/runtime/derived.cpp flang-rt/lib/runtime/descriptor-io.cpp flang-rt/lib/runtime/descriptor-io.h flang-rt/lib/runtime/environment.cpp flang-rt/lib/runtime/namelist.cpp flang-rt/lib/runtime/tools.cpp flang-rt/lib/runtime/type-info.cpp flang-rt/unittests/Runtime/ExternalIOTest.cpp flang/include/flang/Runtime/assign.h flang/include/flang/Semantics/tools.h flang/lib/Semantics/runtime-type-info.cpp flang/lib/Semantics/tools.cpp
View the diff from clang-format here.
diff --git a/flang-rt/lib/runtime/assign.cpp b/flang-rt/lib/runtime/assign.cpp
index bf67b5dc8..bddb48336 100644
--- a/flang-rt/lib/runtime/assign.cpp
+++ b/flang-rt/lib/runtime/assign.cpp
@@ -376,8 +376,8 @@ RT_API_ATTRS void Assign(Descriptor &to, const Descriptor &from,
                      "bytes != from %zd bytes)",
         toElementBytes, fromElementBytes);
   }
-  if (const typeInfo::DerivedType *
-      updatedToDerived{toAddendum ? toAddendum->derivedType() : nullptr}) {
+  if (const typeInfo::DerivedType *updatedToDerived{
+          toAddendum ? toAddendum->derivedType() : nullptr}) {
     // Derived type intrinsic assignment, which is componentwise and elementwise
     // for all components, including parent components (10.2.1.2-3).
     // The target is first finalized if still necessary (7.5.6.3(1))
@@ -390,7 +390,7 @@ RT_API_ATTRS void Assign(Descriptor &to, const Descriptor &from,
     const Descriptor &componentDesc{updatedToDerived->component()};
     std::size_t numComponents{componentDesc.Elements()};
     for (std::size_t j{0}; j < toElements;
-         ++j, to.IncrementSubscripts(toAt), from.IncrementSubscripts(fromAt)) {
+        ++j, to.IncrementSubscripts(toAt), from.IncrementSubscripts(fromAt)) {
       for (std::size_t k{0}; k < numComponents; ++k) {
         const auto &comp{
             *componentDesc.ZeroBasedIndexedElement<typeInfo::Component>(
diff --git a/flang-rt/lib/runtime/derived.cpp b/flang-rt/lib/runtime/derived.cpp
index 35037036f..b22fd1b16 100644
--- a/flang-rt/lib/runtime/derived.cpp
+++ b/flang-rt/lib/runtime/derived.cpp
@@ -54,7 +54,7 @@ RT_API_ATTRS int Initialize(const Descriptor &instance,
           stat = ReturnError(
               terminator, allocDesc.Allocate(kNoAsyncObject), errMsg, hasStat);
           if (stat == StatOk) {
-            if (const DescriptorAddendum * addendum{allocDesc.Addendum()}) {
+            if (const DescriptorAddendum *addendum{allocDesc.Addendum()}) {
               if (const auto *derived{addendum->derivedType()}) {
                 if (!derived->noInitializationNeeded()) {
                   stat = Initialize(
@@ -155,9 +155,9 @@ RT_API_ATTRS int InitializeClone(const Descriptor &clone,
           stat = ReturnError(
               terminator, cloneDesc.Allocate(kNoAsyncObject), errMsg, hasStat);
           if (stat == StatOk) {
-            if (const DescriptorAddendum * addendum{cloneDesc.Addendum()}) {
-              if (const typeInfo::DerivedType *
-                  derived{addendum->derivedType()}) {
+            if (const DescriptorAddendum *addendum{cloneDesc.Addendum()}) {
+              if (const typeInfo::DerivedType *derived{
+                      addendum->derivedType()}) {
                 if (!derived->noInitializationNeeded()) {
                   // Perform default initialization for the allocated element.
                   stat = Initialize(
@@ -302,7 +302,7 @@ RT_API_ATTRS void Finalize(const Descriptor &descriptor,
   for (auto k{recurse ? std::size_t{1}
                       /* skip first component, it's the parent */
                       : 0};
-       k < myComponents; ++k) {
+      k < myComponents; ++k) {
     const auto &comp{
         *componentDesc.ZeroBasedIndexedElement<typeInfo::Component>(k)};
     SubscriptValue at[maxRank];
@@ -312,13 +312,13 @@ RT_API_ATTRS void Finalize(const Descriptor &descriptor,
       // Component may be polymorphic or unlimited polymorphic. Need to use the
       // dynamic type to check whether finalization is needed.
       for (std::size_t j{0}; j++ < elements;
-           descriptor.IncrementSubscripts(at)) {
+          descriptor.IncrementSubscripts(at)) {
         const Descriptor &compDesc{
             *descriptor.ElementComponent<Descriptor>(at, comp.offset())};
         if (compDesc.IsAllocated()) {
-          if (const DescriptorAddendum * addendum{compDesc.Addendum()}) {
-            if (const typeInfo::DerivedType *
-                compDynamicType{addendum->derivedType()}) {
+          if (const DescriptorAddendum *addendum{compDesc.Addendum()}) {
+            if (const typeInfo::DerivedType *compDynamicType{
+                    addendum->derivedType()}) {
               if (!compDynamicType->noFinalizationNeeded()) {
                 Finalize(compDesc, *compDynamicType, terminator);
               }
@@ -328,10 +328,10 @@ RT_API_ATTRS void Finalize(const Descriptor &descriptor,
       }
     } else if (comp.genre() == typeInfo::Component::Genre::Allocatable ||
         comp.genre() == typeInfo::Component::Genre::Automatic) {
-      if (const typeInfo::DerivedType * compType{comp.derivedType()}) {
+      if (const typeInfo::DerivedType *compType{comp.derivedType()}) {
         if (!compType->noFinalizationNeeded()) {
           for (std::size_t j{0}; j++ < elements;
-               descriptor.IncrementSubscripts(at)) {
+              descriptor.IncrementSubscripts(at)) {
             const Descriptor &compDesc{
                 *descriptor.ElementComponent<Descriptor>(at, comp.offset())};
             if (compDesc.IsAllocated()) {
@@ -348,7 +348,7 @@ RT_API_ATTRS void Finalize(const Descriptor &descriptor,
       Descriptor &compDesc{staticDescriptor.descriptor()};
       const typeInfo::DerivedType &compType{*comp.derivedType()};
       for (std::size_t j{0}; j++ < elements;
-           descriptor.IncrementSubscripts(at)) {
+          descriptor.IncrementSubscripts(at)) {
         compDesc.Establish(compType,
             descriptor.ElementComponent<char>(at, comp.offset()), comp.rank(),
             extents);
@@ -410,7 +410,7 @@ RT_API_ATTRS void Destroy(const Descriptor &descriptor, bool finalize,
       Descriptor &compDesc{staticDescriptor.descriptor()};
       const typeInfo::DerivedType &compType{*comp.derivedType()};
       for (std::size_t j{0}; j++ < elements;
-           descriptor.IncrementSubscripts(at)) {
+          descriptor.IncrementSubscripts(at)) {
         compDesc.Establish(compType,
             descriptor.ElementComponent<char>(at, comp.offset()), comp.rank(),
             extents);
diff --git a/flang-rt/lib/runtime/descriptor-io.h b/flang-rt/lib/runtime/descriptor-io.h
index eb60f106c..4be15acb0 100644
--- a/flang-rt/lib/runtime/descriptor-io.h
+++ b/flang-rt/lib/runtime/descriptor-io.h
@@ -282,7 +282,7 @@ static RT_API_ATTRS bool DefaultComponentwiseFormattedIO(IoStatementState &io,
   SubscriptValue at[maxRank];
   compArray.GetLowerBounds(at);
   for (std::size_t k{0}; k < numComponents;
-       ++k, compArray.IncrementSubscripts(at)) {
+      ++k, compArray.IncrementSubscripts(at)) {
     const typeInfo::Component &component{
         *compArray.Element<typeInfo::Component>(at)};
     if (!DefaultComponentIO<DIR>(
@@ -309,11 +309,11 @@ static RT_API_ATTRS bool DefaultComponentwiseUnformattedIO(IoStatementState &io,
   SubscriptValue subscripts[maxRank];
   descriptor.GetLowerBounds(subscripts);
   for (std::size_t j{0}; j < numElements;
-       ++j, descriptor.IncrementSubscripts(subscripts)) {
+      ++j, descriptor.IncrementSubscripts(subscripts)) {
     SubscriptValue at[maxRank];
     compArray.GetLowerBounds(at);
     for (std::size_t k{0}; k < numComponents;
-         ++k, compArray.IncrementSubscripts(at)) {
+        ++k, compArray.IncrementSubscripts(at)) {
       const typeInfo::Component &component{
           *compArray.Element<typeInfo::Component>(at)};
       if (!DefaultComponentIO<DIR>(
@@ -355,10 +355,10 @@ static RT_API_ATTRS bool FormattedDerivedTypeIO(IoStatementState &io,
     }
   }
   if (!special) {
-    if (const typeInfo::SpecialBinding *
-        binding{type->FindSpecialBinding(DIR == Direction::Input
-                ? typeInfo::SpecialBinding::Which::ReadFormatted
-                : typeInfo::SpecialBinding::Which::WriteFormatted)}) {
+    if (const typeInfo::SpecialBinding *binding{
+            type->FindSpecialBinding(DIR == Direction::Input
+                    ? typeInfo::SpecialBinding::Which::ReadFormatted
+                    : typeInfo::SpecialBinding::Which::WriteFormatted)}) {
       if (!table || !table->ignoreNonTbpEntries || binding->isTypeBound()) {
         special = binding;
       }
@@ -368,7 +368,7 @@ static RT_API_ATTRS bool FormattedDerivedTypeIO(IoStatementState &io,
   descriptor.GetLowerBounds(subscripts);
   std::size_t numElements{descriptor.Elements()};
   for (std::size_t j{0}; j < numElements;
-       ++j, descriptor.IncrementSubscripts(subscripts)) {
+      ++j, descriptor.IncrementSubscripts(subscripts)) {
     Fortran::common::optional<bool> result;
     if (special) {
       result = DefinedFormattedIo(io, descriptor, *type, *special, subscripts);
@@ -397,8 +397,8 @@ static RT_API_ATTRS bool UnformattedDescriptorIO(IoStatementState &io,
     const Descriptor &descriptor, const NonTbpDefinedIoTable *table = nullptr) {
   IoErrorHandler &handler{io.GetIoErrorHandler()};
   const DescriptorAddendum *addendum{descriptor.Addendum()};
-  if (const typeInfo::DerivedType *
-      type{addendum ? addendum->derivedType() : nullptr}) {
+  if (const typeInfo::DerivedType *type{
+          addendum ? addendum->derivedType() : nullptr}) {
     // derived type unformatted I/O
     if (table) {
       if (const auto *definedIo{table->Find(*type,
@@ -420,10 +420,10 @@ static RT_API_ATTRS bool UnformattedDescriptorIO(IoStatementState &io,
         }
       }
     }
-    if (const typeInfo::SpecialBinding *
-        special{type->FindSpecialBinding(DIR == Direction::Input
-                ? typeInfo::SpecialBinding::Which::ReadUnformatted
-                : typeInfo::SpecialBinding::Which::WriteUnformatted)}) {
+    if (const typeInfo::SpecialBinding *special{
+            type->FindSpecialBinding(DIR == Direction::Input
+                    ? typeInfo::SpecialBinding::Which::ReadUnformatted
+                    : typeInfo::SpecialBinding::Which::WriteUnformatted)}) {
       if (!table || !table->ignoreNonTbpEntries || special->isTypeBound()) {
         // defined derived type unformatted I/O
         return DefinedUnformattedIo(io, descriptor, *type, *special);

@klausler
Copy link
Contributor Author

The code formatting complaints are due to the original code not being in compliance with the LLVM 20 version of clang-format.

@klausler klausler merged commit 10f512f into llvm:main Jun 11, 2025
10 of 12 checks passed
@klausler klausler deleted the reversion branch June 11, 2025 14:55
tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
…tigation (llvm#143713)

Revert "[flang][runtime] Another try to fix build failure"

This reverts commit 13869ca.

Revert "[flang][runtime] Fix build bot flang-runtime-cuda-gcc errors
(llvm#143650)"

This reverts commit d75e284.

Revert "[flang][runtime] Replace recursion with iterative work queue
(llvm#137727)"

This reverts commit 163c67a.
akuhlens pushed a commit to akuhlens/llvm-project that referenced this pull request Jun 24, 2025
…tigation (llvm#143713)

Revert "[flang][runtime] Another try to fix build failure"

This reverts commit 13869ca.

Revert "[flang][runtime] Fix build bot flang-runtime-cuda-gcc errors
(llvm#143650)"

This reverts commit d75e284.

Revert "[flang][runtime] Replace recursion with iterative work queue
(llvm#137727)"

This reverts commit 163c67a.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants