[flang-commits] [flang] e27e9ca - [flang] Attempt to work around MSVC build problem (#161426)
via flang-commits
flang-commits at lists.llvm.org
Tue Sep 30 13:04:41 PDT 2025
Author: Peter Klausler
Date: 2025-09-30T13:04:37-07:00
New Revision: e27e9ca5d8cdf85f8c8466a792730ff1df313072
URL: https://github.com/llvm/llvm-project/commit/e27e9ca5d8cdf85f8c8466a792730ff1df313072
DIFF: https://github.com/llvm/llvm-project/commit/e27e9ca5d8cdf85f8c8466a792730ff1df313072.diff
LOG: [flang] Attempt to work around MSVC build problem (#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.
Added:
Modified:
flang/include/flang/Evaluate/tools.h
flang/lib/Evaluate/constant.cpp
flang/lib/Evaluate/tools.cpp
Removed:
################################################################################
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