Skip to content

[flang] Use BIND name, if any, when consolidating common blocks #65613

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 1 commit into from
Sep 8, 2023

Conversation

jeanPerier
Copy link
Contributor

@jeanPerier jeanPerier commented Sep 7, 2023

This patch changes how common blocks are aggregated and named in lowering in order to:

  • fix one obvious issue where BIND(C) and non BIND(C) with the same Fortran name were "merged"

  • go further and deal with a derivative where the BIND(C) C name matches the assembly name of a Fortran common block. This is a bit unspecified IMHO, but gfortran, ifort, and nvfortran "merge" the common block without complaints as a linker would have done. This required getting rid of all the common block mangling early in FIR (_QC) instead of leaving that to the phase that emits LLVM from FIR because BIND(C) common blocks did not have mangled names. Care has to be taken to deal with the underscoring option of flang-new.

See added flang/test/Lower/HLFIR/common-block-bindc-conflicts.f90 for an illustration.

Semantics is maintaining a list of common blocks appearing in the file
to allow for the extension where a common may appear with different
size.

It needs to account for BIND(C) name when matching the names. What
matters is to merge the common block with similar global name.

This patch allows merging BIND(C) and non BIND(C) common blocks that
end up having the same name in the object file (previously, this
crashed when lowering FIR to LLVM). This is not well specified, but
matches what gfortran, ifort and nvfortran are doing and what would
happen if the common block had been in different files. To support
this use case, the mangling of common blocks (_QC) has to be dropped
for all common blocks. There was no such mangling for BIND(C) common
already anyway, and the mangling did not bring a lot of valuable info
since there was no scope information (common block are common to all
scopes).

If needed, an MLIR attribute could be added instead to flag
that a fir.global is a common block (the linkage is a good hint already,
although there may be use case for using this linkage for objects that
are not user defined common block form the Fortran source).
@jeanPerier jeanPerier added the flang Flang issues not falling into any other category label Sep 7, 2023
@jeanPerier jeanPerier requested review from a team as code owners September 7, 2023 14:50
@jeanPerier jeanPerier merged commit 6ffea74 into llvm:main Sep 8, 2023
@jeanPerier jeanPerier deleted the jpr-bindc-common-test branch September 8, 2023 08:44
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.

2 participants