[flang-commits] [flang] [flang] Attempt to work around MSVC build problem (PR #161426)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Tue Sep 30 12:36:23 PDT 2025
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/161426
Move a function that seems to be running into an MSVC problem from the source file where I created it to another one (tools.cpp) that is already known to be able to access the semantics::Scope type.
>From c8146670534f3f48e07f4f6cf9b95d5226e5e437 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Tue, 30 Sep 2025 12:31:58 -0700
Subject: [PATCH] [flang] Attempt to work around MSVC build problem
Move a function that seems to be running into an MSVC problem
from the source file where I created it to another one (tools.cpp)
that is already known to be able to access the semantics::Scope type.
---
flang/include/flang/Evaluate/tools.h | 3 +++
flang/lib/Evaluate/constant.cpp | 28 ----------------------------
flang/lib/Evaluate/tools.cpp | 27 +++++++++++++++++++++++++++
3 files changed, 30 insertions(+), 28 deletions(-)
diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index 5f2f199e778c7..f9d74db1df03b 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -1521,6 +1521,9 @@ bool IsVarSubexpressionOf(
// it returns std::nullopt.
std::optional<Expr<SomeType>> GetConvertInput(const Expr<SomeType> &x);
+// How many ancestors does have a derived type have?
+std::optional<int> DerivedTypeDepth(const semantics::Scope &);
+
} // namespace Fortran::evaluate
namespace Fortran::semantics {
diff --git a/flang/lib/Evaluate/constant.cpp b/flang/lib/Evaluate/constant.cpp
index 8923ab114c737..f57dd825a7a7c 100644
--- a/flang/lib/Evaluate/constant.cpp
+++ b/flang/lib/Evaluate/constant.cpp
@@ -10,7 +10,6 @@
#include "flang/Evaluate/expression.h"
#include "flang/Evaluate/shape.h"
#include "flang/Evaluate/type.h"
-#include "flang/Semantics/scope.h"
#include <string>
namespace Fortran::evaluate {
@@ -390,33 +389,6 @@ std::size_t Constant<SomeDerived>::CopyFrom(const Constant<SomeDerived> &source,
return Base::CopyFrom(source, count, resultSubscripts, dimOrder);
}
-static std::optional<int> DerivedTypeDepth(const semantics::Scope &scope) {
- if (scope.IsDerivedType()) {
- for (auto iter{scope.cbegin()}; iter != scope.cend(); ++iter) {
- const Symbol &symbol{*iter->second};
- if (symbol.test(Symbol::Flag::ParentComp)) {
- if (const semantics::DeclTypeSpec *type{symbol.GetType()}) {
- if (const semantics::DerivedTypeSpec *derived{type->AsDerived()}) {
- const semantics::Scope *parent{derived->scope()};
- if (!parent) {
- parent = derived->typeSymbol().scope();
- }
- if (parent) {
- if (auto parentDepth{DerivedTypeDepth(*parent)}) {
- return 1 + *parentDepth;
- }
- }
- }
- }
- return std::nullopt; // error recovery
- }
- }
- return 0;
- } else {
- return std::nullopt; // error recovery
- }
-}
-
bool ComponentCompare::operator()(SymbolRef x, SymbolRef y) const {
if (&x->owner() != &y->owner()) {
// Not components of the same derived type; put ancestors' components first.
diff --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp
index 1f3cbbf6a0c36..6d0da63ead07a 100644
--- a/flang/lib/Evaluate/tools.cpp
+++ b/flang/lib/Evaluate/tools.cpp
@@ -1950,6 +1950,33 @@ bool IsVarSubexpressionOf(
return VariableFinder{sub}(super);
}
+std::optional<int> DerivedTypeDepth(const semantics::Scope &scope) {
+ if (scope.IsDerivedType()) {
+ for (auto iter{scope.cbegin()}; iter != scope.cend(); ++iter) {
+ const Symbol &symbol{*iter->second};
+ if (symbol.test(Symbol::Flag::ParentComp)) {
+ if (const semantics::DeclTypeSpec *type{symbol.GetType()}) {
+ if (const semantics::DerivedTypeSpec *derived{type->AsDerived()}) {
+ const semantics::Scope *parent{derived->scope()};
+ if (!parent) {
+ parent = derived->typeSymbol().scope();
+ }
+ if (parent) {
+ if (auto parentDepth{DerivedTypeDepth(*parent)}) {
+ return 1 + *parentDepth;
+ }
+ }
+ }
+ }
+ return std::nullopt; // error recovery
+ }
+ }
+ return 0;
+ } else {
+ return std::nullopt; // error recovery
+ }
+}
+
} // namespace Fortran::evaluate
namespace Fortran::semantics {
More information about the flang-commits
mailing list