[flang-commits] [flang] [flang] Avoid recursion in runtime derived type initialization (PR #102394)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Fri Aug 9 12:31:20 PDT 2024
================
@@ -0,0 +1,85 @@
+//===-- runtime/engine.cpp ------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "engine.h"
+#include "flang/Runtime/memory.h"
+
+namespace Fortran::runtime::engine {
+
+RT_API_ATTRS Engine::Work::Work(
+ Job job, const Descriptor &instance, const typeInfo::DerivedType *derived)
+ : job_{job}, u_{{instance}} {
+ auto &state{u_.commonState};
+ state.derived_ = derived;
+ state.elements_ = instance.Elements();
+ if (derived) {
+ state.componentDesc_ = &derived->component();
+ state.components_ = state.componentDesc_->Elements();
+ } else {
+ state.componentDesc_ = nullptr;
+ state.components_ = 0;
+ }
+}
+
+RT_API_ATTRS void Engine::Work::Resume(Engine &engine) {
+ switch (job_) {
+ case Job::Initialization:
+ u_.initialization.Resume(engine);
+ return;
+ }
+ engine.terminator().Crash(
+ "Work::Run: bad job_ code %d", static_cast<int>(job_));
+}
+
+RT_API_ATTRS Engine::~Engine() {
+ // deletes list owned by bottomWorkBlock_.next
+}
+
+RT_API_ATTRS int Engine::Do(
+ Job job, const Descriptor &instance, const typeInfo::DerivedType *derived) {
+ Begin(job, instance, derived);
+ while (topWorkBlock_ != &bottomWorkBlock_ && topWorkBlock_->depth > 0) {
----------------
vzakhari wrote:
Should this be `||`?
In the beginning `topWorkBlock_` is equal to `&bottomWorkBlock_`, so we will never enter this loop.
https://github.com/llvm/llvm-project/pull/102394
More information about the flang-commits
mailing list