-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[OpenMP][Flang] Fix semantic check and scoping for declare mappers #139593
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |||||||
| #include "flang/Semantics/type.h" | ||||||||
| #include "flang/Support/Fortran.h" | ||||||||
| #include "flang/Support/default-kinds.h" | ||||||||
| #include "llvm/ADT/SmallVector.h" | ||||||||
| #include "llvm/Support/raw_ostream.h" | ||||||||
| #include <list> | ||||||||
| #include <map> | ||||||||
|
|
@@ -1766,14 +1767,6 @@ void OmpVisitor::ProcessMapperSpecifier(const parser::OmpMapperSpecifier &spec, | |||||||
| // just following the natural flow, the map clauses gets processed before | ||||||||
| // the type has been fully processed. | ||||||||
| BeginDeclTypeSpec(); | ||||||||
| if (auto &mapperName{std::get<std::optional<parser::Name>>(spec.t)}) { | ||||||||
| mapperName->symbol = | ||||||||
| &MakeSymbol(*mapperName, MiscDetails{MiscDetails::Kind::ConstructName}); | ||||||||
| } else { | ||||||||
| const parser::CharBlock defaultName{"default", 7}; | ||||||||
| MakeSymbol( | ||||||||
| defaultName, Attrs{}, MiscDetails{MiscDetails::Kind::ConstructName}); | ||||||||
| } | ||||||||
|
|
||||||||
| PushScope(Scope::Kind::OtherConstruct, nullptr); | ||||||||
| Walk(std::get<parser::TypeSpec>(spec.t)); | ||||||||
|
|
@@ -1783,6 +1776,18 @@ void OmpVisitor::ProcessMapperSpecifier(const parser::OmpMapperSpecifier &spec, | |||||||
| Walk(clauses); | ||||||||
| EndDeclTypeSpec(); | ||||||||
| PopScope(); | ||||||||
|
|
||||||||
| if (auto &mapperName{std::get<std::optional<parser::Name>>(spec.t)}) { | ||||||||
| mapperName->symbol = | ||||||||
| &MakeSymbol(*mapperName, MiscDetails{MiscDetails::Kind::ConstructName}); | ||||||||
| } else { | ||||||||
| const auto &type = std::get<parser::TypeSpec>(spec.t); | ||||||||
| static llvm::SmallVector<std::string> defaultNames; | ||||||||
| defaultNames.emplace_back( | ||||||||
| type.declTypeSpec->derivedTypeSpec().name().ToString() + ".default"); | ||||||||
TIFitis marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| MakeSymbol(defaultNames.back(), Attrs{}, | ||||||||
| MiscDetails{MiscDetails::Kind::ConstructName}); | ||||||||
|
||||||||
| MakeSymbol(defaultNames.back(), Attrs{}, | |
| MiscDetails{MiscDetails::Kind::ConstructName}); | |
| MakeSymbol(defaultNames.back(), MiscDetails{MiscDetails::Kind::ConstructName}); |
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.
Unfortunately, the attribute-less overload uses a different type for the name parameter and thus can't be used directly. Passing a default Attrs{} seems likely a cleaner solution than changing the name to the correct type so I have went with this approach for now.
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.
[nitpick] Using a static llvm::SmallVector for defaultNames may result in unexpected persistent state across invocations. Consider using a local container or clearing the vector at the beginning of the function to ensure that state does not accumulate unintentionally.
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.
I can see this is intentionally
staticto make sure that these runtime-created strings don't get destructed while symbols are still in use, sinceCharBlockdoesn't own the data, but it doesn't seem to me like a very clean approach.Not sure if perhaps adding some generic static storage for situations like this to the
semantics::Scopeclass, something looking similar to theallSymbolsfield, would be a better idea or if there currently are any facilities to store strings not present in the original source to be used as symbols.CC: @kiranchandramohan, @tblah.
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.
Surely some string storage for symbol names already exists? If not then I agree that it would be better to have a utility for other situations like this. Even just wrapping the static vector in a well documented and named utility function would make it clearer what this is for.
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.
Hi, I encountered that even with this minor fix, some separate scoping related semantic issues would have still remained. To fix these issues altogether, I have instead taken a different approach to solving the problem.
I have changed the optional field for the mapper name to a compulsory std::string field. The parser has been updated to create a default name -
"<typeSpec>.omp.default.mapper"whenever the default name is used.Also added a new test to flang/test/Lower/OpenMP/declare-mapper.f90 for ensuring declare mapper scoping rules apply cleanly.