Files
clang-p2996/flang/test/Lower/module_use.f90
jeanPerier 6ffea74f7c [flang] Use BIND name, if any, when consolidating common blocks (#65613)
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.
2023-09-08 10:43:55 +02:00

44 lines
1.7 KiB
Fortran

! RUN: bbc -emit-fir %S/module_definition.f90
! RUN: bbc -emit-fir %s -o - | FileCheck %s
! Test use of module data not defined in this file.
! The modules are defined in module_definition.f90
! The first runs ensures the module file is generated.
! CHECK: fir.global common @__BLNK__(dense<0> : vector<4xi8>) : !fir.array<4xi8>
! CHECK-NEXT: fir.global common @named1_(dense<0> : vector<4xi8>) : !fir.array<4xi8>
! CHECK-NEXT: fir.global common @named2_(dense<0> : vector<4xi8>) : !fir.array<4xi8>
! CHECK-LABEL: func @_QPm1use()
real function m1use()
use m1
! CHECK-DAG: fir.address_of(@_QMm1Ex) : !fir.ref<f32>
! CHECK-DAG: fir.address_of(@_QMm1Ey) : !fir.ref<!fir.array<100xi32>>
m1use = x + y(1)
end function
! TODO: test equivalences once front-end fix in module file is pushed.
!! CHECK-LABEL func @_QPmodeq1use()
!real function modEq1use()
! use modEq1
! ! CHECK-DAG fir.address_of(@_QMmodeq1Ex1) : !fir.ref<tuple<!fir.array<36xi8>, !fir.array<40xi8>>>
! ! CHECK-DAG fir.address_of(@_QMmodeq1Ey1) : !fir.ref<tuple<!fir.array<16xi8>, !fir.array<24xi8>>>
! modEq1use = x2(1) + y1
!end function
! CHECK-DAG fir.global @_QMmodeq1Ex1 : tuple<!fir.array<36xi8>, !fir.array<40xi8>>
! CHECK-DAG fir.global @_QMmodeq1Ey1 : tuple<!fir.array<16xi8>, !fir.array<24xi8>>
! CHECK-LABEL: func @_QPmodcommon1use()
real function modCommon1Use()
use modCommonInit1
use modCommonNoInit1
! CHECK-DAG: fir.address_of(@named2_) : !fir.ref<!fir.array<4xi8>>
! CHECK-DAG: fir.address_of(@__BLNK__) : !fir.ref<!fir.array<4xi8>>
! CHECK-DAG: fir.address_of(@named1_) : !fir.ref<!fir.array<4xi8>>
modCommon1Use = x_blank + x_named1 + i_named2
end function
! CHECK-DAG: fir.global @_QMm1Ex : f32
! CHECK-DAG: fir.global @_QMm1Ey : !fir.array<100xi32>