-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[flang] Fix compile-time infinite loop #66246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
When a COMMON block object has a derived type that is part of a set of mutually-dependent types with other members, the compiler loops. Fixes llvm#65572. Pull request: llvm#66246
@llvm/pr-subscribers-flang-semantics ChangesWhen a COMMON block object has a derived type that is part of a set of mutually-dependent types with other members, the compiler loops.Fixes #65572.Full diff: https://github.com/llvm/llvm-project/pull/66246.diff 2 Files Affected:
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp index 865c198424696a9..ec0115ba90f078c 100644 --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -1131,7 +1131,8 @@ class DeclarationVisitor : public ArraySpecVisitor, bool OkToAddComponent(const parser::Name &, const Symbol * = nullptr); ParamValue GetParamValue( const parser::TypeParamValue &, common::TypeParamAttr attr); - void CheckCommonBlockDerivedType(const SourceName &, const Symbol &); + void CheckCommonBlockDerivedType( + const SourceName &, const Symbol &, UnorderedSymbolSet &); Attrs HandleSaveName(const SourceName &, Attrs); void AddSaveName(std::set<SourceName> &, const SourceName &); bool HandleUnrestrictedSpecificIntrinsicFunction(const parser::Name &); @@ -6096,7 +6097,8 @@ void DeclarationVisitor::CheckCommonBlocks() { "Derived type '%s' in COMMON block must have the BIND or" " SEQUENCE attribute"_err_en_US); } - CheckCommonBlockDerivedType(name, typeSymbol); + UnorderedSymbolSet typeSet; + CheckCommonBlockDerivedType(name, typeSymbol, typeSet); } } } @@ -6120,8 +6122,12 @@ bool DeclarationVisitor::NameIsKnownOrIntrinsic(const parser::Name &name) { } // Check if this derived type can be in a COMMON block. -void DeclarationVisitor::CheckCommonBlockDerivedType( - const SourceName &name, const Symbol &typeSymbol) { +void DeclarationVisitor::CheckCommonBlockDerivedType(const SourceName &name, + const Symbol &typeSymbol, UnorderedSymbolSet &typeSet) { + if (auto iter{typeSet.find(SymbolRef{typeSymbol})}; iter != typeSet.end()) { + return; + } + typeSet.emplace(typeSymbol); if (const auto *scope{typeSymbol.scope()}) { for (const auto &pair : *scope) { const Symbol &component{*pair.second}; @@ -6144,13 +6150,7 @@ void DeclarationVisitor::CheckCommonBlockDerivedType( if (const auto *type{details->type()}) { if (const auto *derived{type->AsDerived()}) { const Symbol &derivedTypeSymbol{derived->typeSymbol()}; - // Don't call this member function recursively if the derived type - // symbol is the same symbol that is already being processed. - // This can happen when a component is a pointer of the same type - // as its parent component, for instance. - if (derivedTypeSymbol != typeSymbol) { - CheckCommonBlockDerivedType(name, derivedTypeSymbol); - } + CheckCommonBlockDerivedType(name, derivedTypeSymbol, typeSet); } } } diff --git a/flang/test/Semantics/equivalence01.f90 b/flang/test/Semantics/equivalence01.f90 index 66f183c489258af..7ef47fb554b5eec 100644 --- a/flang/test/Semantics/equivalence01.f90 +++ b/flang/test/Semantics/equivalence01.f90 @@ -230,3 +230,17 @@ real function f17b() equivalence (dupName, y) end function f17b end module m17 + +module m18 + ! Regression test: don't loop when checking mutually-referencing types + type t1 + sequence + type (t2), pointer :: p + end type + type t2 + sequence + type (t1), pointer :: p + end type + type(t1) x + common x +end |
clementval
approved these changes
Sep 13, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
ZijunZhaoCCK
pushed a commit
to ZijunZhaoCCK/llvm-project
that referenced
this pull request
Sep 19, 2023
When a COMMON block object has a derived type that is part of a set of mutually-dependent types with other members, the compiler loops. Fixes llvm#65572.
zahiraam
pushed a commit
to tahonermann/llvm-project
that referenced
this pull request
Oct 24, 2023
When a COMMON block object has a derived type that is part of a set of mutually-dependent types with other members, the compiler loops. Fixes llvm#65572.
zahiraam
pushed a commit
to tahonermann/llvm-project
that referenced
this pull request
Oct 24, 2023
When a COMMON block object has a derived type that is part of a set of mutually-dependent types with other members, the compiler loops. Fixes llvm#65572.
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.
When a COMMON block object has a derived type that is part of a set of mutually-dependent types with other members, the compiler loops.
Fixes #65572.