[flang] Attempt to work around MSVC build problem#161426
Merged
Merged
Conversation
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.
Member
|
@llvm/pr-subscribers-flang-semantics Author: Peter Klausler (klausler) ChangesMove 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. Full diff: https://github.com/llvm/llvm-project/pull/161426.diff 3 Files Affected:
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 {
|
eugeneepshteyn
approved these changes
Sep 30, 2025
mahesh-attarde
pushed a commit
to mahesh-attarde/llvm-project
that referenced
this pull request
Oct 3, 2025
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.