-
Notifications
You must be signed in to change notification settings - Fork 12k
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
[Flang] Revise the fix in PR #81087 to get specific procedure from a potential generic name. #81544
Conversation
@llvm/pr-subscribers-flang-semantics Author: Daniel Chen (DanielCChen) ChangesThis PR is to revise the fix in PR #81807 to handle the case that @psteinfeld brought up. Both test cases in PR #81807 now pass with this PR. Full diff: https://github.com/llvm/llvm-project/pull/81544.diff 2 Files Affected:
diff --git a/flang/include/flang/Semantics/symbol.h b/flang/include/flang/Semantics/symbol.h
index 4535a92ce3dd8e..0577cba9587d55 100644
--- a/flang/include/flang/Semantics/symbol.h
+++ b/flang/include/flang/Semantics/symbol.h
@@ -786,6 +786,9 @@ class Symbol {
inline Symbol &GetUltimate();
inline const Symbol &GetUltimate() const;
+ // Get the specific procedure from a potential generic symbol.
+ inline const Symbol *GetUltimateGeneric() const;
+
inline DeclTypeSpec *GetType();
inline const DeclTypeSpec *GetType() const;
void SetType(const DeclTypeSpec &);
@@ -985,6 +988,16 @@ inline const Symbol &Symbol::GetUltimate() const {
}
}
+inline const Symbol *Symbol::GetUltimateGeneric() const {
+ if (this->has<GenericDetails>())
+ return this;
+ if (const auto *details{detailsIf<UseDetails>()})
+ return details->symbol().GetUltimateGeneric();
+ if (const auto *details{detailsIf<HostAssocDetails>()})
+ return details->symbol().GetUltimateGeneric();
+ return nullptr;
+}
+
inline DeclTypeSpec *Symbol::GetType() {
return const_cast<DeclTypeSpec *>(
const_cast<const Symbol *>(this)->GetType());
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 36deab969456d0..0e21f3dabb6a01 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -5644,12 +5644,14 @@ void DeclarationVisitor::Post(const parser::ProcInterface &x) {
NoteInterfaceName(*name);
}
}
+
void DeclarationVisitor::Post(const parser::ProcDecl &x) {
const auto &name{std::get<parser::Name>(x.t)};
const Symbol *procInterface{nullptr};
if (interfaceName_) {
- procInterface = interfaceName_->symbol->has<GenericDetails>()
- ? interfaceName_->symbol->get<GenericDetails>().specific()
+ const Symbol *ultimateGeneric{interfaceName_->symbol->GetUltimateGeneric()};
+ procInterface = ultimateGeneric
+ ? ultimateGeneric->get<GenericDetails>().specific()
: interfaceName_->symbol;
}
auto attrs{HandleSaveName(name.source, GetAttrs())};
|
I am afraid this might be pushing the problem further and that the issue would still occur if the renaming was done on a generic. I think we cannot easily change the procedure interface symbol in semantics without risking breaking the module file generation in case of renaming. File 1:
File 2:
Would also raise the bogus semantic errors with this patch because the generated fmod1 module file also "bypass" the renaming in its procedure statement. I think we should instead change the approach from #80738 and deal with the fact that the interface symbol may have generic details. Maybe adding a case for
I would run that through @klausler when he is back next week though to make sure there no code out there that expect Symbol::GetType to be null for generics. |
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 have verified that this change passes all of our internal tests.
Thanks! |
Thanks for the review. Sure, I added @klausler as a reviewer and will wait for his input. |
28dcfc8
to
5ac19eb
Compare
@jeanPerier Your suggestion of "adding a case for GenericDetails in Symbol::GetType() " works for all cases that have been listed in all related PRs. Thanks for the suggestion! I will update this PR to change to that. |
@jeanPerier and @klausler By glaring through symbol.h, it seems |
I've tested again with your latest changes, and all looks good. |
Thank you very much! |
Thanks for pushing the reasoning here, yes, I think you are correct, this also needs to be updated if go that path. But I am not entirely sure this is the only and best path (see next comment).
Would otherwise crash in lowering because expr.getRank() is inconsistent with the rank that is later found when lowering |
As mentioned in the previous comment, maybe there is a way to still update the interface symbol as you did in #81087 and #80738 and deal with the module file renaming issue. It seems module files may use a custom variable format to deal with this case with function calls.
The module file m looks like:
This currently trigger a bogus error "Invalid specification expression: reference to impure function 'somefunc'" when the program is compiled in its own file, so this may require some more work, but at least the renaming is not an issue in this case. @klausler, how is the |
c0e5afa
to
dc252d3
Compare
I opened another Issue #82267 that the BIND(C) attribute got lost when the generic name is present. It might affect the fix of this PR. |
This one could be related to too. Issue #82390 |
…m a potential generic name.
…erent way by adding a GenericDetails in GetTypeImpl.
dc252d3
to
37073c3
Compare
Just to confirm that PR #82837 fixed both code in #81087 and #80738. However, both @jeanPerier 's code in the PR still fail. |
@jeanPerier and @klausler , PR #82837 fixed the code in this PR. but the two cases that Jean brought up in this PR still fail. Do you prefer I close this PR and open a new one for those two failures or keep it open to track those? |
@DanielCChen, I opened issue #83836 with the reproducer, I think this PR can be closed for more clarity. |
Thanks @jeanPerier . Close this PR as suggested. |
This PR is to revise the fix in PR #81087 to handle the case that @psteinfeld brought up. Both test cases in PR #81087 now pass with this PR.