Skip to content
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] handle indirect module variable use in internal procedure #65324

Merged
merged 1 commit into from
Sep 6, 2023

Conversation

jeanPerier
Copy link
Contributor

When a module variable is referenced inside an internal procedure, but the use statement for the module is inside the host, semantics may not create any symbols with HostAssocDetails directly under the internal procedure scope.
So pft::getScopeVariableList, that is called in the bridge when lowering the internal procedure scope, failed to instantiate the module variables. This lead to "symbol is not mapped to any IR value" compile time errors.

This patch fixes the issue by adding the variables to the list of "captured" global variables from the host program, so that they are instantiated as part of the internalProcedureBindings in the bridge.

The rational of doing it that way instead of changing getScopeVariableList is that getScopeVariableList would have to import all the module variables used inside the host since it cannot know which ones are referenced inside the internal procedure from the semantics::Scope information. The fix in this patch only instantiates the module variables from the host that are actually referenced inside the internal procedure.

When a module variable is referenced inside an internal procedure,
but the use statement for the module is inside the host, semantics
may not create any symbols with HostAssocDetails directly under the
internal procedure scope.
So pft::getScopeVariableList, that is called in the bridge when lowering
the internal procedure scope, failed to instantiate the module variables.
This lead to "symbol is not mapped to any IR value" compile time errors.

This patch fixes the issue by adding the variables to the list of "captured"
global variables from the host program, so that they are instantiated as
part of the `internalProcedureBindings` in the bridge.

The rational of doing it that way instead of changing
getScopeVariableList is that getScopeVariableList would have to import
all the module variables used inside the host since it cannot know which
ones are used inside the internal procedure from the Scope information.
The fix in this patch only instantiates the module variables from the host that
are actually referenced inside the internal procedure.
@jeanPerier jeanPerier added the flang Flang issues not falling into any other category label Sep 5, 2023
@jeanPerier jeanPerier requested a review from a team as a code owner September 5, 2023 13:17
@vdonaldson
Copy link
Contributor

Looks good to me.

I don't see an approve button to click here.

@vdonaldson
Copy link
Contributor

I don't see an approve button to click here.

"Add your review" -> "Review changes" -> "Approve"

generates a "Looks like something went wrong" message

@vzakhari
Copy link
Contributor

vzakhari commented Sep 5, 2023

I don't see an approve button to click here.

"Add your review" -> "Review changes" -> "Approve"

generates a "Looks like something went wrong" message

I get the same error when trying to approve.

@jeanPerier jeanPerier merged commit d26c78b into llvm:main Sep 6, 2023
1 check passed
@jeanPerier jeanPerier deleted the jpr-global-internal-bug branch September 6, 2023 07:07
avillega pushed a commit to avillega/llvm-project that referenced this pull request Sep 11, 2023
…vm#65324)

When a module variable is referenced inside an internal procedure, but
the use statement for the module is inside the host, semantics may not
create any symbols with HostAssocDetails directly under the internal
procedure scope.
So pft::getScopeVariableList, that is called in the bridge when lowering
the internal procedure scope, failed to instantiate the module
variables. This lead to "symbol is not mapped to any IR value" compile
time errors.

This patch fixes the issue by adding the variables to the list of
"captured" global variables from the host program, so that they are
instantiated as part of the `internalProcedureBindings` in the bridge.

The rational of doing it that way instead of changing
`getScopeVariableList` is that `getScopeVariableList` would have to
import all the module variables used inside the host since it cannot
know which ones are referenced inside the internal procedure from the
semantics::Scope information. The fix in this patch only instantiates
the module variables from the host that are actually referenced inside
the internal procedure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants