[flang-commits] [flang] [Flang] External subprograms should be allowed as proc_target in procedure pointers. (PR #183268)

via flang-commits flang-commits at lists.llvm.org
Mon Mar 30 02:02:03 PDT 2026


https://github.com/ShashwathiNavada updated https://github.com/llvm/llvm-project/pull/183268

>From dc876977bdf7e5c7ed8639047829a8dc1e93c7e5 Mon Sep 17 00:00:00 2001
From: ShashwathiNavada <shashwathinavada at gmail.com>
Date: Wed, 25 Feb 2026 04:00:02 -0600
Subject: [PATCH 1/9] External subprograms should be allowed as proc_target in
 procedure pointers

---
 flang/lib/Lower/CallInterface.cpp   | 15 +++++++++++++++
 flang/test/Semantics/extrn_subp.f90 | 20 ++++++++++++++++++++
 2 files changed, 35 insertions(+)
 create mode 100644 flang/test/Semantics/extrn_subp.f90

diff --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp
index f5ae2de5cad8b..65cac0466d5ea 100644
--- a/flang/lib/Lower/CallInterface.cpp
+++ b/flang/lib/Lower/CallInterface.cpp
@@ -695,6 +695,21 @@ void Fortran::lower::CallInterface<T>::declare() {
     mlir::ModuleOp module = converter.getModuleOp();
     mlir::SymbolTable *symbolTable = converter.getMLIRSymbolTable();
     func = fir::FirOpBuilder::getNamedFunction(module, symbolTable, name);
+    if (func) {
+      if constexpr (std::is_same_v<T, Fortran::lower::CalleeInterface>) {
+        mlir::FunctionType ty = genFunctionType();
+        if (!func.getBlocks().empty())
+          fir::emitFatalError(
+              func.getLoc(),
+              "conflicting procedure definition with mismatched signature");
+        if (func.getFunctionType() != ty) {
+          func.setType(ty);
+          for (const auto &placeHolder : llvm::enumerate(inputs))
+            func.setArgAttrs(placeHolder.index(),
+                             placeHolder.value().attributes);
+        }
+      }
+    }
     if (!func) {
       mlir::Location loc = side().getCalleeLocation();
       mlir::MLIRContext &mlirContext = converter.getMLIRContext();
diff --git a/flang/test/Semantics/extrn_subp.f90 b/flang/test/Semantics/extrn_subp.f90
new file mode 100644
index 0000000000000..67b3b02a85363
--- /dev/null
+++ b/flang/test/Semantics/extrn_subp.f90
@@ -0,0 +1,20 @@
+! RUN: flang %s
+
+Module m1
+  external::sub
+  type ty
+    procedure(),pointer,nopass :: ptr5=>sub
+  end type
+  procedure(),pointer:: ptr6=>sub
+end module
+ 
+use m1
+  integer::jj =4
+  call ptr6(10)
+  print*,"Pass"
+end
+ 
+subroutine sub(a)
+  integer::a
+  print*,"sub"
+end subroutine
\ No newline at end of file

>From 2fe4d47094b0e5bc9cbc9271f95f2833a3966774 Mon Sep 17 00:00:00 2001
From: ShashwathiNavada <shashwathinavada at gmail.com>
Date: Wed, 25 Feb 2026 06:31:09 -0600
Subject: [PATCH 2/9] Simple changes

---
 flang/test/Semantics/extrn_subp.f90 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/flang/test/Semantics/extrn_subp.f90 b/flang/test/Semantics/extrn_subp.f90
index 67b3b02a85363..5336daf22d248 100644
--- a/flang/test/Semantics/extrn_subp.f90
+++ b/flang/test/Semantics/extrn_subp.f90
@@ -1,4 +1,4 @@
-! RUN: flang %s
+! RUN: %python %S/test_errors.py %s %flang_fc1
 
 Module m1
   external::sub

>From 2bf192fff0669703fb080bbf1f032a199eb3be63 Mon Sep 17 00:00:00 2001
From: ShashwathiNavada <shashwathinavada at gmail.com>
Date: Thu, 12 Mar 2026 10:21:33 -0500
Subject: [PATCH 3/9] Suggested change

---
 flang/lib/Lower/Bridge.cpp          | 19 +++++++++++++++++-
 flang/lib/Lower/CallInterface.cpp   | 15 ---------------
 flang/test/Lower/extrn_subp.f90     | 30 +++++++++++++++++++++++++++++
 flang/test/Semantics/extrn_subp.f90 |  2 +-
 4 files changed, 49 insertions(+), 17 deletions(-)
 create mode 100644 flang/test/Lower/extrn_subp.f90

diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 687c2f0f4a42a..10999e38883ba 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -507,7 +507,6 @@ class FirConverter : public Fortran::lower::AbstractConverter {
                     globalOmpRequiresSymbol = f.getScope().symbol();
                 },
                 [&](Fortran::lower::pft::ModuleLikeUnit &m) {
-                  lowerModuleDeclScope(m);
                   for (Fortran::lower::pft::ContainedUnit &unit :
                        m.containedUnitList)
                     if (auto *f =
@@ -526,6 +525,24 @@ class FirConverter : public Fortran::lower::AbstractConverter {
       }
     });
 
+    // Lower module declaration scopes now that all function
+    // declarations are available with their final signatures.
+    createBuilderOutsideOfFuncOpAndDo([&]() {
+      for (Fortran::lower::pft::Program::Units &u : pft.getUnits()) {
+        Fortran::common::visit(
+            Fortran::common::visitors{
+                [&](Fortran::lower::pft::FunctionLikeUnit &f) {},
+                [&](Fortran::lower::pft::ModuleLikeUnit &m) {
+                  lowerModuleDeclScope(m);
+                },
+                [&](Fortran::lower::pft::BlockDataUnit &b) {},
+                [&](Fortran::lower::pft::CompilerDirectiveUnit &d) {},
+                [&](Fortran::lower::pft::OpenACCDirectiveUnit &d) {},
+            },
+            u);
+      }
+    });
+
     // Ensure imported OpenMP declare mappers are materialized at module
     // scope before lowering any constructs that may reference them.
     createBuilderOutsideOfFuncOpAndDo([&]() {
diff --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp
index 65cac0466d5ea..f5ae2de5cad8b 100644
--- a/flang/lib/Lower/CallInterface.cpp
+++ b/flang/lib/Lower/CallInterface.cpp
@@ -695,21 +695,6 @@ void Fortran::lower::CallInterface<T>::declare() {
     mlir::ModuleOp module = converter.getModuleOp();
     mlir::SymbolTable *symbolTable = converter.getMLIRSymbolTable();
     func = fir::FirOpBuilder::getNamedFunction(module, symbolTable, name);
-    if (func) {
-      if constexpr (std::is_same_v<T, Fortran::lower::CalleeInterface>) {
-        mlir::FunctionType ty = genFunctionType();
-        if (!func.getBlocks().empty())
-          fir::emitFatalError(
-              func.getLoc(),
-              "conflicting procedure definition with mismatched signature");
-        if (func.getFunctionType() != ty) {
-          func.setType(ty);
-          for (const auto &placeHolder : llvm::enumerate(inputs))
-            func.setArgAttrs(placeHolder.index(),
-                             placeHolder.value().attributes);
-        }
-      }
-    }
     if (!func) {
       mlir::Location loc = side().getCalleeLocation();
       mlir::MLIRContext &mlirContext = converter.getMLIRContext();
diff --git a/flang/test/Lower/extrn_subp.f90 b/flang/test/Lower/extrn_subp.f90
new file mode 100644
index 0000000000000..c43f65a72d766
--- /dev/null
+++ b/flang/test/Lower/extrn_subp.f90
@@ -0,0 +1,30 @@
+! RUN: bbc -emit-hlfir -o - %s | FileCheck %s
+
+module m1
+  external :: sub
+  type ty
+    procedure(), pointer, nopass :: ptr5 => sub
+  end type
+  procedure(), pointer :: ptr6 => sub
+end module
+
+use m1
+integer :: jj = 4
+call ptr6(10)
+print *, "Pass"
+end
+
+subroutine sub(a)
+  integer :: a
+  print *, "sub"
+end subroutine
+
+! CHECK-LABEL: func.func @_QQmain() {
+! CHECK:         %[[PTR6_ADDR:.*]] = fir.address_of(@_QMm1Eptr6) : !fir.ref<!fir.boxproc<() -> ()>>
+! CHECK:         %[[PTR6:.*]]:2 = hlfir.declare %[[PTR6_ADDR]] {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QMm1Eptr6"}
+! CHECK:         %[[C10:.*]] = arith.constant 10 : i32
+! CHECK:         %[[TMP:.*]]:3 = hlfir.associate %[[C10]] {adapt.valuebyref} : (i32) -> (!fir.ref<i32>, !fir.ref<i32>, i1)
+! CHECK:         %[[P:.*]] = fir.load %[[PTR6]]#0 : !fir.ref<!fir.boxproc<() -> ()>>
+! CHECK:         %[[F:.*]] = fir.box_addr %[[P]] : (!fir.boxproc<() -> ()>) -> ((!fir.ref<i32>) -> ())
+! CHECK:         fir.call %[[F]](%[[TMP]]#0) fastmath<contract> : (!fir.ref<i32>) -> ()
+! CHECK:         hlfir.end_associate %[[TMP]]#1, %[[TMP]]#2 : !fir.ref<i32>, i1
\ No newline at end of file
diff --git a/flang/test/Semantics/extrn_subp.f90 b/flang/test/Semantics/extrn_subp.f90
index 5336daf22d248..2624fa4cb3a90 100644
--- a/flang/test/Semantics/extrn_subp.f90
+++ b/flang/test/Semantics/extrn_subp.f90
@@ -17,4 +17,4 @@ Module m1
 subroutine sub(a)
   integer::a
   print*,"sub"
-end subroutine
\ No newline at end of file
+end subroutine

>From 52f87dd24e72d025132a89c6ec437ea3b576e8ae Mon Sep 17 00:00:00 2001
From: ShashwathiNavada <shashwathinavada at gmail.com>
Date: Thu, 12 Mar 2026 10:27:37 -0500
Subject: [PATCH 4/9] Format change

---
 flang/test/Lower/extrn_subp.f90     |  2 +-
 flang/test/Semantics/extrn_subp.f90 | 20 --------------------
 2 files changed, 1 insertion(+), 21 deletions(-)
 delete mode 100644 flang/test/Semantics/extrn_subp.f90

diff --git a/flang/test/Lower/extrn_subp.f90 b/flang/test/Lower/extrn_subp.f90
index c43f65a72d766..3d1d80b30a16f 100644
--- a/flang/test/Lower/extrn_subp.f90
+++ b/flang/test/Lower/extrn_subp.f90
@@ -27,4 +27,4 @@ subroutine sub(a)
 ! CHECK:         %[[P:.*]] = fir.load %[[PTR6]]#0 : !fir.ref<!fir.boxproc<() -> ()>>
 ! CHECK:         %[[F:.*]] = fir.box_addr %[[P]] : (!fir.boxproc<() -> ()>) -> ((!fir.ref<i32>) -> ())
 ! CHECK:         fir.call %[[F]](%[[TMP]]#0) fastmath<contract> : (!fir.ref<i32>) -> ()
-! CHECK:         hlfir.end_associate %[[TMP]]#1, %[[TMP]]#2 : !fir.ref<i32>, i1
\ No newline at end of file
+! CHECK:         hlfir.end_associate %[[TMP]]#1, %[[TMP]]#2 : !fir.ref<i32>, i1
diff --git a/flang/test/Semantics/extrn_subp.f90 b/flang/test/Semantics/extrn_subp.f90
deleted file mode 100644
index 2624fa4cb3a90..0000000000000
--- a/flang/test/Semantics/extrn_subp.f90
+++ /dev/null
@@ -1,20 +0,0 @@
-! RUN: %python %S/test_errors.py %s %flang_fc1
-
-Module m1
-  external::sub
-  type ty
-    procedure(),pointer,nopass :: ptr5=>sub
-  end type
-  procedure(),pointer:: ptr6=>sub
-end module
- 
-use m1
-  integer::jj =4
-  call ptr6(10)
-  print*,"Pass"
-end
- 
-subroutine sub(a)
-  integer::a
-  print*,"sub"
-end subroutine

>From fb45cdf7191a44a5ed64fada59ecab49e7552d1b Mon Sep 17 00:00:00 2001
From: ShashwathiNavada <shashwathinavada at gmail.com>
Date: Mon, 23 Mar 2026 10:35:27 -0500
Subject: [PATCH 5/9] fixed testcases

---
 flang/lib/Lower/Bridge.cpp                    |  3 +-
 flang/test/Fir/dispatch.f90                   | 22 ++++++-----
 .../Lower/CUDA/cuda-allocatable-device.cuf    | 18 ++++-----
 flang/test/Lower/CUDA/cuda-allocatable.cuf    | 16 ++++----
 flang/test/Lower/CUDA/cuda-data-attribute.cuf | 20 +++++-----
 flang/test/Lower/CUDA/cuda-gpu-managed.cuf    | 13 ++++---
 flang/test/Lower/CUDA/cuda-mod.cuf            |  2 +-
 flang/test/Lower/CUDA/cuda-pointer-sync.cuf   |  2 +-
 .../HLFIR/procedure-pointer-in-generics.f90   |  8 ++--
 flang/test/Lower/OpenACC/acc-declare.f90      | 15 ++++---
 flang/test/Lower/OpenMP/cray-pointers01.f90   |  6 ++-
 .../test/Lower/OpenMP/threadprivate-hlfir.f90 |  2 +-
 ...ivate-real-logical-complex-derivedtype.f90 |  9 ++---
 .../threadprivate-use-association-2-hlfir.f90 |  3 +-
 .../OpenMP/threadprivate-use-association.f90  |  3 +-
 flang/test/Lower/allocatable-globals.f90      | 12 +++---
 .../array-elemental-calls-char-dynamic.f90    | 13 +++----
 flang/test/Lower/c-interoperability.f90       | 22 +++++------
 flang/test/Lower/dense-attributed-array.f90   |  2 +-
 flang/test/Lower/dispatch.f90                 | 20 +++++-----
 flang/test/Lower/extrn_subp.f90               |  2 +-
 flang/test/Lower/pointer-default-init.f90     | 39 ++++++++++---------
 flang/test/Lower/polymorphic.f90              | 16 ++++----
 23 files changed, 133 insertions(+), 135 deletions(-)

diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index f2f955719a091..19921f4dc9c7b 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -491,8 +491,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
 
     // - Declare all functions that have definitions so that definition
     //   signatures prevail over call site signatures.
-    // - Define module variables and OpenMP/OpenACC declarative constructs so
-    //   they are available before lowering any function that may use them.
+    // - Module variables are lowered once all the function declarations are available.
     bool hasMainProgram = false;
     const Fortran::semantics::Symbol *globalOmpRequiresSymbol = nullptr;
     createBuilderOutsideOfFuncOpAndDo([&]() {
diff --git a/flang/test/Fir/dispatch.f90 b/flang/test/Fir/dispatch.f90
index 741099706981f..72fc82fb717a5 100644
--- a/flang/test/Fir/dispatch.f90
+++ b/flang/test/Fir/dispatch.f90
@@ -299,8 +299,6 @@ program test_type_to_class
 ! Check the layout of the binding table. This is easier to do in FIR than in
 ! LLVM IR.
 
-! BT-LABEL: fir.type_info @_QMdispatch1Tty_kindK10K20
-! BT-LABEL: fir.type_info @_QMdispatch1Tty_kind_exK10K20 {{.*}}extends !fir.type<_QMdispatch1Tty_kindK10K20{{.*}}>
 
 ! BT-LABEL: fir.type_info @_QMdispatch1Tp1
 ! BT: fir.dt_entry "aproc", @_QMdispatch1Paproc
@@ -313,14 +311,6 @@ program test_type_to_class
 ! BT: fir.dt_entry "z_proc_nopass_bindc", @proc_nopass_bindc_p1
 ! BT: }
 
-! BT-LABEL: fir.type_info @_QMdispatch1Ta1
-! BT: fir.dt_entry "a1_proc", @_QMdispatch1Pa1_proc
-! BT: }
-
-! BT-LABEL: fir.type_info @_QMdispatch1Ta2 {{.*}}extends !fir.type<_QMdispatch1Ta1{{.*}}>
-! BT:  fir.dt_entry "a1_proc", @_QMdispatch1Pa2_proc
-! BT: }
-
 ! BT-LABEL: fir.type_info @_QMdispatch1Tp2 {{.*}}extends !fir.type<_QMdispatch1Tp1{{.*}}>
 ! BT:  fir.dt_entry "aproc", @_QMdispatch1Paproc
 ! BT:  fir.dt_entry "display1", @_QMdispatch1Pdisplay1_p2
@@ -332,3 +322,15 @@ program test_type_to_class
 ! BT:  fir.dt_entry "z_proc_nopass_bindc", @proc_nopass_bindc_p2
 ! BT:  fir.dt_entry "display3", @_QMdispatch1Pdisplay3
 ! BT: }
+
+! BT-LABEL: fir.type_info @_QMdispatch1Ta1
+! BT: fir.dt_entry "a1_proc", @_QMdispatch1Pa1_proc
+! BT: }
+
+! BT-LABEL: fir.type_info @_QMdispatch1Ta2 {{.*}}extends !fir.type<_QMdispatch1Ta1{{.*}}>
+! BT:  fir.dt_entry "a1_proc", @_QMdispatch1Pa2_proc
+! BT: }
+! BT-LABEL: fir.type_info @_QMdispatch1Tty_kindK10K20
+! BT-LABEL: fir.type_info @_QMdispatch1Tty_kind_exK10K20 {{.*}}extends !fir.type<_QMdispatch1Tty_kindK10K20{{.*}}>
+
+
diff --git a/flang/test/Lower/CUDA/cuda-allocatable-device.cuf b/flang/test/Lower/CUDA/cuda-allocatable-device.cuf
index 9c293872d1017..a27becc32c0f6 100644
--- a/flang/test/Lower/CUDA/cuda-allocatable-device.cuf
+++ b/flang/test/Lower/CUDA/cuda-allocatable-device.cuf
@@ -32,15 +32,6 @@ module m
   type(unified_array), allocatable :: ua(:)
 end module
 
-! CHECK-LABEL: fir.global linkonce_odr @_QMmE.c.device_array
-! CHECK: fir.insert_value %{{.*}}, %c1{{.*}}, ["memoryspace"
-
-! CHECK-LABEL: fir.global linkonce_odr @_QMmE.c.managed_array
-! CHECK: fir.insert_value %{{.*}}, %c2{{.*}}, ["memoryspace"
-
-! CHECK-LABEL: fir.global linkonce_odr @_QMmE.c.unified_array
-! CHECK: fir.insert_value %{{.*}}, %c3{{.*}}, ["memoryspace"
-
 program main
   use m
   type(device_array) :: local
@@ -50,3 +41,12 @@ end
 
 ! CHECK-LABEL: func.func @_QQmain()
 ! CHECK-COUNT-3: fir.call @_FortranAInitialize
+! CHECK-LABEL: fir.global linkonce_odr @_QMmE.c.device_array
+! CHECK: fir.insert_value %{{.*}}, %c1{{.*}}, ["memoryspace"
+
+! CHECK-LABEL: fir.global linkonce_odr @_QMmE.c.managed_array
+! CHECK: fir.insert_value %{{.*}}, %c2{{.*}}, ["memoryspace"
+
+! CHECK-LABEL: fir.global linkonce_odr @_QMmE.c.unified_array
+! CHECK: fir.insert_value %{{.*}}, %c3{{.*}}, ["memoryspace"
+
diff --git a/flang/test/Lower/CUDA/cuda-allocatable.cuf b/flang/test/Lower/CUDA/cuda-allocatable.cuf
index 52303d126b8dc..5954bd5c2cbf6 100644
--- a/flang/test/Lower/CUDA/cuda-allocatable.cuf
+++ b/flang/test/Lower/CUDA/cuda-allocatable.cuf
@@ -12,14 +12,6 @@ module globals
   end type
 end module
 
-! CHECK-LABEL: fir.global @_QMglobalsEa_device {data_attr = #cuf.cuda<device>} : !fir.box<!fir.heap<!fir.array<?xf32>>>
-! CHECK: %{{.*}} = fir.embox %{{.*}}(%{{.*}}) {allocator_idx = 2 : i32} : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.heap<!fir.array<?xf32>>>
-
-! CHECK-LABEL: fir.global @_QMglobalsEa_managed {data_attr = #cuf.cuda<managed>} : !fir.box<!fir.heap<!fir.array<?xf32>>>
-! CHECK: %{{.*}} = fir.embox %{{.*}}(%{{.*}}) {allocator_idx = 3 : i32} : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.heap<!fir.array<?xf32>>>
-
-! CHECK-LABEL: fir.global @_QMglobalsEa_pinned {data_attr = #cuf.cuda<pinned>} : !fir.box<!fir.heap<!fir.array<?xf32>>>
-! CHECK: %{{.*}} = fir.embox %{{.*}}(%{{.*}}) {allocator_idx = 1 : i32} : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.heap<!fir.array<?xf32>>>
 
 subroutine sub1()
   real, allocatable, device :: a(:)
@@ -270,3 +262,11 @@ end subroutine
 
 ! CHECK-LABEL: func.func @_QPfrom_device_source()
 ! CHECK: cuf.allocate{{.*}}device_source
+! CHECK-LABEL: fir.global @_QMglobalsEa_device {data_attr = #cuf.cuda<device>} : !fir.box<!fir.heap<!fir.array<?xf32>>>
+! CHECK: %{{.*}} = fir.embox %{{.*}}(%{{.*}}) {allocator_idx = 2 : i32} : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.heap<!fir.array<?xf32>>>
+
+! CHECK-LABEL: fir.global @_QMglobalsEa_managed {data_attr = #cuf.cuda<managed>} : !fir.box<!fir.heap<!fir.array<?xf32>>>
+! CHECK: %{{.*}} = fir.embox %{{.*}}(%{{.*}}) {allocator_idx = 3 : i32} : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.heap<!fir.array<?xf32>>>
+
+! CHECK-LABEL: fir.global @_QMglobalsEa_pinned {data_attr = #cuf.cuda<pinned>} : !fir.box<!fir.heap<!fir.array<?xf32>>>
+! CHECK: %{{.*}} = fir.embox %{{.*}}(%{{.*}}) {allocator_idx = 1 : i32} : (!fir.heap<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.heap<!fir.array<?xf32>>>
diff --git a/flang/test/Lower/CUDA/cuda-data-attribute.cuf b/flang/test/Lower/CUDA/cuda-data-attribute.cuf
index 17bdce975c3d0..d0fe58a07410a 100644
--- a/flang/test/Lower/CUDA/cuda-data-attribute.cuf
+++ b/flang/test/Lower/CUDA/cuda-data-attribute.cuf
@@ -10,23 +10,12 @@ module cuda_var
   end type
 
   real, constant :: mod_a_rc
-! CHECK: fir.global @_QMcuda_varEmod_a_rc {data_attr = #cuf.cuda<constant>} : f32 
   real, device :: mod_b_ra
-! CHECK: fir.global @_QMcuda_varEmod_b_ra {data_attr = #cuf.cuda<device>} : f32
   real, allocatable, managed :: mod_c_rm
-! CHECK: fir.global @_QMcuda_varEmod_c_rm {data_attr = #cuf.cuda<managed>} : !fir.box<!fir.heap<f32>>
-  
   integer, device, dimension(10) :: mod_d_i_init = (/ (i, i = 1, 10) /)
-! CHECK: fir.global @_QMcuda_varEmod_d_i_init(dense<[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]> : tensor<10xi32>) {data_attr = #cuf.cuda<device>} : !fir.array<10xi32>
-
   real, device, dimension(10) :: mod_d_rinit = (/ (i, i = 1, 10) /)
-! CHECK: fir.global @_QMcuda_varEmod_d_rinit(dense<[{{.*}}]> : tensor<10xf32>) {data_attr = #cuf.cuda<device>} : !fir.array<10xf32>
-
   real, allocatable, pinned :: mod_d_rp
-! CHECK: fir.global @_QMcuda_varEmod_d_rp {data_attr = #cuf.cuda<pinned>} : !fir.box<!fir.heap<f32>>
-
   type(t1), device :: mod_d_t(2)
-! CHECK: fir.global @_QMcuda_varEmod_d_t {data_attr = #cuf.cuda<device>} : !fir.array<2x!fir.type<_QMcuda_varTt1{a:i32}>>
 
 contains
 
@@ -115,3 +104,12 @@ end
 
 ! CHECK-LABEL: func.func @_QPcraypointer()
 ! CHECK: %{{.*}} = cuf.alloc !fir.box<!fir.ptr<!fir.array<?xf32>>> {data_attr = #cuf.cuda<device>} -> !fir.ref<!fir.box<!fir.ptr<!fir.array<?xf32>>>>
+   ! CHECK: fir.global @_QMcuda_varEmod_a_rc {data_attr = #cuf.cuda<constant>} : f32 
+
+! CHECK: fir.global @_QMcuda_varEmod_b_ra {data_attr = #cuf.cuda<device>} : f32
+! CHECK: fir.global @_QMcuda_varEmod_c_rm {data_attr = #cuf.cuda<managed>} : !fir.box<!fir.heap<f32>>
+
+! CHECK: fir.global @_QMcuda_varEmod_d_i_init(dense<[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]> : tensor<10xi32>) {data_attr = #cuf.cuda<device>} : !fir.array<10xi32>
+! CHECK: fir.global @_QMcuda_varEmod_d_rinit(dense<[{{.*}}]> : tensor<10xf32>) {data_attr = #cuf.cuda<device>} : !fir.array<10xf32>
+! CHECK: fir.global @_QMcuda_varEmod_d_rp {data_attr = #cuf.cuda<pinned>} : !fir.box<!fir.heap<f32>>
+! CHECK: fir.global @_QMcuda_varEmod_d_t {data_attr = #cuf.cuda<device>} : !fir.array<2x!fir.type<_QMcuda_varTt1{a:i32}>>
diff --git a/flang/test/Lower/CUDA/cuda-gpu-managed.cuf b/flang/test/Lower/CUDA/cuda-gpu-managed.cuf
index 6c69f4d71674c..a9ae310978e19 100644
--- a/flang/test/Lower/CUDA/cuda-gpu-managed.cuf
+++ b/flang/test/Lower/CUDA/cuda-gpu-managed.cuf
@@ -147,12 +147,6 @@ module mod_globals
   real, allocatable, device :: global_device(:)
 end module
 
-! CHECK: fir.global @_QMmod_globalsEglobal_arr {data_attr = #cuf.cuda<managed>} : !fir.box<!fir.heap<!fir.array<?xf32>>>
-! CHECK: fir.embox {{.*}} {allocator_idx = 3 : i32}
-
-! CHECK: fir.global @_QMmod_globalsEglobal_device {data_attr = #cuf.cuda<device>} : !fir.box<!fir.heap<!fir.array<?xf32>>>
-! CHECK: fir.embox {{.*}} {allocator_idx = 2 : i32}
-
 subroutine test_module_var()
   use mod_globals
   allocate(global_arr(50))
@@ -164,3 +158,10 @@ end subroutine
 ! CHECK-LABEL: func.func @_QPtest_module_var()
 ! CHECK: cuf.allocate {{.*}} {data_attr = #cuf.cuda<managed>, hasDoubleDescriptor}
 ! CHECK: cuf.allocate {{.*}} {data_attr = #cuf.cuda<device>, hasDoubleDescriptor}
+
+! CHECK: fir.global @_QMmod_globalsEglobal_arr {data_attr = #cuf.cuda<managed>} : !fir.box<!fir.heap<!fir.array<?xf32>>>
+! CHECK: fir.embox {{.*}} {allocator_idx = 3 : i32}
+
+! CHECK: fir.global @_QMmod_globalsEglobal_device {data_attr = #cuf.cuda<device>} : !fir.box<!fir.heap<!fir.array<?xf32>>>
+! CHECK: fir.embox {{.*}} {allocator_idx = 2 : i32}
+
diff --git a/flang/test/Lower/CUDA/cuda-mod.cuf b/flang/test/Lower/CUDA/cuda-mod.cuf
index f03e72e94780f..cb1a6d8ad28ec 100644
--- a/flang/test/Lower/CUDA/cuda-mod.cuf
+++ b/flang/test/Lower/CUDA/cuda-mod.cuf
@@ -10,6 +10,6 @@ contains
   end
 end module
 
+! CHECK: func.func @_QMcuf_modPdevsub() attributes {cuf.proc_attr = #cuf.cuda_proc<device>}
 ! CHECK: fir.global @_QMcuf_modEmd {data_attr = #cuf.cuda<device>} : f32
 
-! CHECK: func.func @_QMcuf_modPdevsub() attributes {cuf.proc_attr = #cuf.cuda_proc<device>}
diff --git a/flang/test/Lower/CUDA/cuda-pointer-sync.cuf b/flang/test/Lower/CUDA/cuda-pointer-sync.cuf
index 4c64f4bd34aa0..b2d489be649eb 100644
--- a/flang/test/Lower/CUDA/cuda-pointer-sync.cuf
+++ b/flang/test/Lower/CUDA/cuda-pointer-sync.cuf
@@ -14,8 +14,8 @@ dev_ptr => null()
 nullify(dev_ptr)
 end
 
-! CHECK: fir.global @_QMdevptrEdev_ptr {data_attr = #cuf.cuda<device>} : !fir.box<!fir.ptr<!fir.array<?xf32>>>
 ! CHECK-LABEL: func.func @_QQmain()
 ! CHECK: fir.embox
 ! CHECK: fir.store
 ! CHECK-COUNT-3: cuf.sync_descriptor @_QMdevptrEdev_ptr
+! CHECK: fir.global @_QMdevptrEdev_ptr {data_attr = #cuf.cuda<device>} : !fir.box<!fir.ptr<!fir.array<?xf32>>>
diff --git a/flang/test/Lower/HLFIR/procedure-pointer-in-generics.f90 b/flang/test/Lower/HLFIR/procedure-pointer-in-generics.f90
index ff447d31b1af1..d03e657133d48 100644
--- a/flang/test/Lower/HLFIR/procedure-pointer-in-generics.f90
+++ b/flang/test/Lower/HLFIR/procedure-pointer-in-generics.f90
@@ -12,10 +12,6 @@ real function func(x)
     end function
   end interface
 end
-!CHECK-LABEL:   fir.global @_QMm_genEfoo : !fir.boxproc<(!fir.ref<f32>) -> f32> {
-!CHECK:           %[[VAL_0:.*]] = fir.zero_bits (!fir.ref<f32>) -> f32
-!CHECK:           %[[VAL_1:.*]] = fir.emboxproc %[[VAL_0]] : ((!fir.ref<f32>) -> f32) -> !fir.boxproc<(!fir.ref<f32>) -> f32>
-!CHECK:           fir.has_value %[[VAL_1]] : !fir.boxproc<(!fir.ref<f32>) -> f32>
 
 subroutine test1()
   use m_gen
@@ -44,3 +40,7 @@ subroutine test_local()
 !CHECK:           %[[VAL_5:.*]] = fir.emboxproc %[[VAL_4]] : ((!fir.ref<f32>) -> f32) -> !fir.boxproc<() -> ()>
 !CHECK:           %[[VAL_6:.*]] = fir.convert %[[VAL_5]] : (!fir.boxproc<() -> ()>) -> !fir.boxproc<(!fir.ref<f32>) -> f32>
 !CHECK:           fir.store %[[VAL_6]] to %[[VAL_3]]#0 : !fir.ref<!fir.boxproc<(!fir.ref<f32>) -> f32>>
+!CHECK-LABEL:   fir.global @_QMm_genEfoo : !fir.boxproc<(!fir.ref<f32>) -> f32> {
+!CHECK:           %[[VAL_0:.*]] = fir.zero_bits (!fir.ref<f32>) -> f32
+!CHECK:           %[[VAL_1:.*]] = fir.emboxproc %[[VAL_0]] : ((!fir.ref<f32>) -> f32) -> !fir.boxproc<(!fir.ref<f32>) -> f32>
+!CHECK:           fir.has_value %[[VAL_1]] : !fir.boxproc<(!fir.ref<f32>) -> f32>
diff --git a/flang/test/Lower/OpenACC/acc-declare.f90 b/flang/test/Lower/OpenACC/acc-declare.f90
index 12c32c58f86b9..b72f00a69b40b 100644
--- a/flang/test/Lower/OpenACC/acc-declare.f90
+++ b/flang/test/Lower/OpenACC/acc-declare.f90
@@ -320,6 +320,13 @@ module acc_declare_allocatable_test
  integer, allocatable :: data1(:)
  !$acc declare create(data1)
 end module
+! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action<postAlloc = @_QMacc_declare_allocatable_testEdata1_acc_declare_post_alloc>} : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
+! CHECK: %{{.*}} = fir.box_addr %{{.*}} {acc.declare_action = #acc.declare_action<preDealloc = @_QMacc_declare_allocatable_testEdata1_acc_declare_pre_dealloc>} : (!fir.box<!fir.heap<!fir.array<?xi32>>>) -> !fir.heap<!fir.array<?xi32>>
+! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action<postDealloc = @_QMacc_declare_allocatable_testEdata1_acc_declare_post_dealloc>} : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
+! CHECK-LABEL: func.func @_QMacc_declare_post_action_statPinit()
+! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath<contract> {acc.declare_action = #acc.declare_action<postAlloc = @_QMacc_declare_post_action_statEx_acc_declare_post_alloc>} : (!fir.ref<!fir.box<none>>, !fir.ref<i64>, i1, !fir.box<none>, !fir.ref<i8>, i32, {{.*}}) -> i32
+! CHECK: fir.if
+! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath<contract> {acc.declare_action = #acc.declare_action<postAlloc = @_QMacc_declare_post_action_statEy_acc_declare_post_alloc>} : (!fir.ref<!fir.box<none>>, !fir.ref<i64>, i1, !fir.box<none>, !fir.ref<i8>, i32, {{.*}}) -> i32
 
 ! CHECK-LABEL: acc.global_ctor @_QMacc_declare_allocatable_testEdata1_acc_ctor {
 ! CHECK:         %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_allocatable_testEdata1) {acc.declare = #acc.declare<dataClause =  acc_create>} : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
@@ -401,14 +408,11 @@ module acc_declare_allocatable_test2
   subroutine init()
     use acc_declare_allocatable_test
     allocate(data1(100))
-! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action<postAlloc = @_QMacc_declare_allocatable_testEdata1_acc_declare_post_alloc>} : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
   end subroutine
 
   subroutine finalize()
     use acc_declare_allocatable_test
     deallocate(data1)
-! CHECK: %{{.*}} = fir.box_addr %{{.*}} {acc.declare_action = #acc.declare_action<preDealloc = @_QMacc_declare_allocatable_testEdata1_acc_declare_pre_dealloc>} : (!fir.box<!fir.heap<!fir.array<?xi32>>>) -> !fir.heap<!fir.array<?xi32>>
-! CHECK: fir.store %{{.*}} to %{{.*}} {acc.declare_action = #acc.declare_action<postDealloc = @_QMacc_declare_allocatable_testEdata1_acc_declare_post_dealloc>} : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
   end subroutine
 end module
 
@@ -432,8 +436,3 @@ subroutine init()
     allocate(x(10), y(10), stat=stat)
   end subroutine
 end module
-
-! CHECK-LABEL: func.func @_QMacc_declare_post_action_statPinit()
-! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath<contract> {acc.declare_action = #acc.declare_action<postAlloc = @_QMacc_declare_post_action_statEx_acc_declare_post_alloc>} : (!fir.ref<!fir.box<none>>, !fir.ref<i64>, i1, !fir.box<none>, !fir.ref<i8>, i32, {{.*}}) -> i32
-! CHECK: fir.if
-! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath<contract> {acc.declare_action = #acc.declare_action<postAlloc = @_QMacc_declare_post_action_statEy_acc_declare_post_alloc>} : (!fir.ref<!fir.box<none>>, !fir.ref<i64>, i1, !fir.box<none>, !fir.ref<i8>, i32, {{.*}}) -> i32
diff --git a/flang/test/Lower/OpenMP/cray-pointers01.f90 b/flang/test/Lower/OpenMP/cray-pointers01.f90
index 8fcddbcdcb0f8..01fa4af3282b1 100644
--- a/flang/test/Lower/OpenMP/cray-pointers01.f90
+++ b/flang/test/Lower/OpenMP/cray-pointers01.f90
@@ -2,9 +2,7 @@
 ! RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - 2>&1 | FileCheck %s
 
 module test_host_assoc_cray_pointer
-  ! CHECK-LABEL: fir.global @_QMtest_host_assoc_cray_pointerEivar : i64
   real*8 var(*)
-  ! CHECK-LABEL: fir.global  @_QMtest_host_assoc_cray_pointerEvar : !fir.array<?xf64>
   pointer(ivar,var)
 
 contains
@@ -57,5 +55,9 @@ program test_cray_pointers_01
     print *, var(1)
     ! CHECK:   omp.terminator
     ! CHECK: }
+    ! CHECK-LABEL: fir.global @_QMtest_host_assoc_cray_pointerEivar : i64
+    ! CHECK-LABEL: fir.global  @_QMtest_host_assoc_cray_pointerEvar : !fir.array<?xf64>
+
+
   !$omp end parallel
 end program test_cray_pointers_01
diff --git a/flang/test/Lower/OpenMP/threadprivate-hlfir.f90 b/flang/test/Lower/OpenMP/threadprivate-hlfir.f90
index 986815bb1ccc3..92e341aed1bf9 100644
--- a/flang/test/Lower/OpenMP/threadprivate-hlfir.f90
+++ b/flang/test/Lower/OpenMP/threadprivate-hlfir.f90
@@ -55,7 +55,6 @@ subroutine sub_03()
 
 module mod_01
   integer, save :: a
-  !CHECK: fir.global @_QMmod_01Ea : i32
   !$omp threadprivate(a)
 end module
 
@@ -71,6 +70,7 @@ subroutine sub_05()
   !$omp end parallel
 end subroutine
 
+!CHECK: fir.global @_QMmod_01Ea : i32
 
 !CHECK:  fir.global internal @_QFsubEa : i32
 
diff --git a/flang/test/Lower/OpenMP/threadprivate-real-logical-complex-derivedtype.f90 b/flang/test/Lower/OpenMP/threadprivate-real-logical-complex-derivedtype.f90
index b89d5470a79ed..68ca0d0510a72 100644
--- a/flang/test/Lower/OpenMP/threadprivate-real-logical-complex-derivedtype.f90
+++ b/flang/test/Lower/OpenMP/threadprivate-real-logical-complex-derivedtype.f90
@@ -15,11 +15,6 @@ module test
 
   !$omp threadprivate(x, y, z, t)
 
-!CHECK-DAG: fir.global @_QMtestEt : !fir.type<_QMtestTmy_type{t_i:i32,t_arr:!fir.array<5xf32>}> {
-!CHECK-DAG: fir.global @_QMtestEx : f32 {
-!CHECK-DAG: fir.global @_QMtestEy : complex<f32> {
-!CHECK-DAG: fir.global @_QMtestEz : !fir.logical<4> {
-
 contains
 !CHECK-LABEL: func.func @_QMtestPsub
   subroutine sub()
@@ -64,6 +59,10 @@ subroutine sub()
 !CHECK-DAG:  %{{.*}} = fir.load %[[OMP_Y_DECL]]#0 : !fir.ref<complex<f32>>
 !CHECK-DAG:  %{{.*}} = fir.load %[[OMP_Z_DECL]]#0 : !fir.ref<!fir.logical<4>>
 !CHECK-DAG:  %{{.*}} = hlfir.designate %[[OMP_T_DECL]]#0{"t_i"}   : (!fir.ref<!fir.type<_QMtestTmy_type{t_i:i32,t_arr:!fir.array<5xf32>}>>) -> !fir.ref<i32>
+!CHECK-DAG: fir.global @_QMtestEt : !fir.type<_QMtestTmy_type{t_i:i32,t_arr:!fir.array<5xf32>}> {
+!CHECK-DAG: fir.global @_QMtestEx : f32 {
+!CHECK-DAG: fir.global @_QMtestEy : complex<f32> {
+!CHECK-DAG: fir.global @_QMtestEz : !fir.logical<4> {
     print *, x, y, z, t%t_i
 
   end
diff --git a/flang/test/Lower/OpenMP/threadprivate-use-association-2-hlfir.f90 b/flang/test/Lower/OpenMP/threadprivate-use-association-2-hlfir.f90
index f9e97e5905140..5e870f2c17b6a 100644
--- a/flang/test/Lower/OpenMP/threadprivate-use-association-2-hlfir.f90
+++ b/flang/test/Lower/OpenMP/threadprivate-use-association-2-hlfir.f90
@@ -4,7 +4,6 @@
 !RUN: %flang_fc1 -emit-hlfir -flang-experimental-hlfir -fopenmp %s -o - | FileCheck %s
 !RUN: bbc -emit-hlfir -fopenmp %s -o - | FileCheck %s
 
-! CHECK-LABEL: fir.global @_QMmEx : i32
 module m
   integer :: x
   !$omp threadprivate(x)
@@ -27,6 +26,8 @@ module m
 ! CHECK:         fir.call @_QPbar(%[[VAL_3]]#0) {{.*}}: (!fir.ref<i32>) -> ()
 ! CHECK:         return
 ! CHECK:       }
+! CHECK-LABEL: fir.global @_QMmEx : i32
+
 
 module m2
   use m
diff --git a/flang/test/Lower/OpenMP/threadprivate-use-association.f90 b/flang/test/Lower/OpenMP/threadprivate-use-association.f90
index e60f5158cd3ff..5daf87783acf9 100644
--- a/flang/test/Lower/OpenMP/threadprivate-use-association.f90
+++ b/flang/test/Lower/OpenMP/threadprivate-use-association.f90
@@ -4,7 +4,6 @@
 !RUN: %flang_fc1 -emit-hlfir -fopenmp %s -o - | FileCheck %s
 
 !CHECK-DAG: fir.global common @blk_(dense<0> : vector<24xi8>) {alignment = 4 : i64} : !fir.array<24xi8>
-!CHECK-DAG: fir.global @_QMtestEy : f32 {
 
 module test
   integer :: x
@@ -72,6 +71,8 @@ program main
 !CHECK-DAG:    %{{.*}} = fir.load %[[DECX1]]#0 : !fir.ref<i32>
 !CHECK-DAG:    %{{.*}} = fir.load %[[DECY]]#0 : !fir.ref<f32>
 !CHECK-DAG:    %{{.*}} = fir.embox %[[DECZ1]]#0(%{{.*}}) : (!fir.ref<!fir.array<5xf32>>, !fir.shape<1>) -> !fir.box<!fir.array<5xf32>>
+!CHECK-DAG: fir.global @_QMtestEy : f32 {
+
     print *, x1, y, z1
   !$omp end parallel
 
diff --git a/flang/test/Lower/allocatable-globals.f90 b/flang/test/Lower/allocatable-globals.f90
index 8b7420ab32391..98fbdfaa2a5f8 100644
--- a/flang/test/Lower/allocatable-globals.f90
+++ b/flang/test/Lower/allocatable-globals.f90
@@ -3,12 +3,6 @@
 
 ! Test global allocatable definition lowering
 
-! CHECK-LABEL: fir.global @_QMmod_allocatablesEc : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>> {
-  ! CHECK-DAG: %[[modcNullAddr:.*]] = fir.zero_bits !fir.heap<!fir.array<?x!fir.char<1,10>>>
-  ! CHECK-DAG: %[[modcShape:.*]] = fir.shape %c0{{.*}} : (index) -> !fir.shape<1>
-  ! CHECK: %[[modcInitBox:.*]] = fir.embox %[[modcNullAddr]](%[[modcShape]]) : (!fir.heap<!fir.array<?x!fir.char<1,10>>>, !fir.shape<1>) -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>
-  ! CHECK: fir.has_value %[[modcInitBox]] : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>
-
 module mod_allocatables
   character(10), allocatable :: c(:)
 end module
@@ -37,6 +31,11 @@ subroutine test_globals()
   allocate(gx, gy(20, 30), gc3, gc4(40, 50))
   allocate(character(15):: gc1, gc2(60, 70))
 end subroutine
+  ! CHECK-LABEL: fir.global @_QMmod_allocatablesEc : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>> {
+  ! CHECK-DAG: %[[modcNullAddr:.*]] = fir.zero_bits !fir.heap<!fir.array<?x!fir.char<1,10>>>
+  ! CHECK-DAG: %[[modcShape:.*]] = fir.shape %c0{{.*}} : (index) -> !fir.shape<1>
+  ! CHECK: %[[modcInitBox:.*]] = fir.embox %[[modcNullAddr]](%[[modcShape]]) : (!fir.heap<!fir.array<?x!fir.char<1,10>>>, !fir.shape<1>) -> !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>
+  ! CHECK: fir.has_value %[[modcInitBox]] : !fir.box<!fir.heap<!fir.array<?x!fir.char<1,10>>>>
 
 ! CHECK-LABEL: fir.global internal @_QFtest_globalsEgc1 : !fir.box<!fir.heap<!fir.char<1,?>>>
   ! CHECK-DAG: %[[gc1NullAddr:.*]] = fir.zero_bits !fir.heap<!fir.char<1,?>>
@@ -70,3 +69,4 @@ subroutine test_globals()
   ! CHECK-DAG: %[[gyShape:.*]] = fir.shape %c0{{.*}}, %c0{{.*}} : (index, index) -> !fir.shape<2>
   ! CHECK: %[[gyInitBox:.*]] = fir.embox %[[gyNullAddr]](%[[gyShape]]) : (!fir.heap<!fir.array<?x?xi32>>, !fir.shape<2>) -> !fir.box<!fir.heap<!fir.array<?x?xi32>>>
   ! CHECK: fir.has_value %[[gyInitBox]] : !fir.box<!fir.heap<!fir.array<?x?xi32>>>
+
diff --git a/flang/test/Lower/array-elemental-calls-char-dynamic.f90 b/flang/test/Lower/array-elemental-calls-char-dynamic.f90
index 34baea2e9f3b2..93bb0d5f07c28 100644
--- a/flang/test/Lower/array-elemental-calls-char-dynamic.f90
+++ b/flang/test/Lower/array-elemental-calls-char-dynamic.f90
@@ -50,14 +50,6 @@ elemental function bug_145151_1(c_dummy)
 ! CHECK:           return
 ! CHECK:         }
 
-! CHECK-LABEL:   fir.global @_QMm_bug_145151_2Ei : i64 {
-! CHECK:           %[[VAL_0:.*]] = fir.zero_bits i64
-! CHECK:           fir.has_value %[[VAL_0]] : i64
-! CHECK:         }
-
-
-
-
 module m_bug_145151_2
   integer(8) :: i
 end module
@@ -289,3 +281,8 @@ elemental function f_value(c_dummy)
 ! CHECK:           hlfir.destroy %[[VAL_14]] : !hlfir.expr<?x!fir.char<1,?>>
 ! CHECK:           return
 ! CHECK:         }
+
+! CHECK-LABEL:   fir.global @_QMm_bug_145151_2Ei : i64 {
+! CHECK:           %[[VAL_0:.*]] = fir.zero_bits i64
+! CHECK:           fir.has_value %[[VAL_0]] : i64
+! CHECK:         }
\ No newline at end of file
diff --git a/flang/test/Lower/c-interoperability.f90 b/flang/test/Lower/c-interoperability.f90
index 64ffd8b0994d7..724763027763a 100644
--- a/flang/test/Lower/c-interoperability.f90
+++ b/flang/test/Lower/c-interoperability.f90
@@ -1,16 +1,5 @@
 ! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s
 
-! CHECK-LABEL: fir.global @_QMc_interoperability_testEthis_thing : !fir.type<_QMc_interoperability_testTthing_with_pointer{cptr:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}> {
-! CHECK:         %[[VAL_0:.*]] = fir.undefined !fir.type<_QMc_interoperability_testTthing_with_pointer{cptr:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}>
-! CHECK:         %[[VAL_1:.*]] = fir.undefined !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>
-! CHECK:         %[[VAL_2:.*]] = fir.field_index __address, !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>
-! CHECK:         %[[VAL_3:.*]] = arith.constant 0 : i64
-! CHECK:         %[[VAL_4:.*]] = fir.insert_value %[[VAL_1]], %[[VAL_3]], ["__address", !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>] : (!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>, i64) -> !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>
-! CHECK:         %[[VAL_5:.*]] = fir.field_index cptr, !fir.type<_QMc_interoperability_testTthing_with_pointer{cptr:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}>
-! CHECK:         %[[VAL_6:.*]] = fir.insert_value %[[VAL_0]], %[[VAL_4]], ["cptr", !fir.type<_QMc_interoperability_testTthing_with_pointer{cptr:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}>] : (!fir.type<_QMc_interoperability_testTthing_with_pointer{cptr:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}>, !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>) -> !fir.type<_QMc_interoperability_testTthing_with_pointer{cptr:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}>
-! CHECK:         fir.has_value %[[VAL_6]] : !fir.type<_QMc_interoperability_testTthing_with_pointer{cptr:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}>
-! CHECK:       }
-
 ! CHECK-LABEL: func @_QMc_interoperability_testPget_a_thing() -> !fir.type<_QMc_interoperability_testTthing_with_pointer{cptr:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}> {
 ! CHECK:         %[[VAL_0:.*]] = fir.dummy_scope : !fir.dscope
 ! CHECK:         %[[VAL_1:.*]] = fir.address_of(@_QM__fortran_builtinsEC__builtin_c_null_ptr) : !fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>
@@ -25,7 +14,16 @@
 ! CHECK:         %[[VAL_8:.*]] = fir.load %[[VAL_6]]#0 : !fir.ref<!fir.type<_QMc_interoperability_testTthing_with_pointer{cptr:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}>>
 ! CHECK:         return %[[VAL_8]] : !fir.type<_QMc_interoperability_testTthing_with_pointer{cptr:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}>
 ! CHECK:       }
-
+! CHECK-LABEL: fir.global @_QMc_interoperability_testEthis_thing : !fir.type<_QMc_interoperability_testTthing_with_pointer{cptr:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}> {
+! CHECK:         %[[VAL_0:.*]] = fir.undefined !fir.type<_QMc_interoperability_testTthing_with_pointer{cptr:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}>
+! CHECK:         %[[VAL_1:.*]] = fir.undefined !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>
+! CHECK:         %[[VAL_2:.*]] = fir.field_index __address, !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>
+! CHECK:         %[[VAL_3:.*]] = arith.constant 0 : i64
+! CHECK:         %[[VAL_4:.*]] = fir.insert_value %[[VAL_1]], %[[VAL_3]], ["__address", !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>] : (!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>, i64) -> !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>
+! CHECK:         %[[VAL_5:.*]] = fir.field_index cptr, !fir.type<_QMc_interoperability_testTthing_with_pointer{cptr:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}>
+! CHECK:         %[[VAL_6:.*]] = fir.insert_value %[[VAL_0]], %[[VAL_4]], ["cptr", !fir.type<_QMc_interoperability_testTthing_with_pointer{cptr:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}>] : (!fir.type<_QMc_interoperability_testTthing_with_pointer{cptr:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}>, !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>) -> !fir.type<_QMc_interoperability_testTthing_with_pointer{cptr:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}>
+! CHECK:         fir.has_value %[[VAL_6]] : !fir.type<_QMc_interoperability_testTthing_with_pointer{cptr:!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>}>
+! CHECK:       }
 module c_interoperability_test
   use iso_c_binding, only: c_ptr, c_null_ptr
 
diff --git a/flang/test/Lower/dense-attributed-array.f90 b/flang/test/Lower/dense-attributed-array.f90
index 604576a323c25..2b97436a6cf32 100644
--- a/flang/test/Lower/dense-attributed-array.f90
+++ b/flang/test/Lower/dense-attributed-array.f90
@@ -13,11 +13,11 @@ subroutine ss
 !CHECK-NOT: %{{.*}} = arith.constant %{{.*}} : index
 !CHECK-NOT: %{{.*}} = arith.constant %{{.*}} : i32
 !CHECK-NOT: %{{.*}} = fir.insert_value %{{.*}}, %{{.*}}, [%{{.*}} : index] : (!fir.array<3xi32>, i32) -> !fir.array<3xi32>
-!CHECK: fir.global @_QMmmECqq(dense<[51, 52, 53]> : tensor<3xi32>) constant : !fir.array<3xi32>
 !CHECK: func.func @_QPss() {
 !CHECK:  %[[a0:.*]] = fir.alloca i32 {bindc_name = "n", uniq_name = "_QFssEn"}
 !CHECK:  %[[d0:.*]]:2 = hlfir.declare %[[a0]] {uniq_name = "_QFssEn"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
 !CHECK:  %[[c0:.*]] = arith.constant 53 : i32
 !CHECK:  hlfir.assign %[[c0]] to %[[d0]]#0 : i32, !fir.ref<i32>
 !CHECK:  return
+!CHECK: fir.global @_QMmmECqq(dense<[51, 52, 53]> : tensor<3xi32>) constant : !fir.array<3xi32>
 !CHECK: }
diff --git a/flang/test/Lower/dispatch.f90 b/flang/test/Lower/dispatch.f90
index 863a26c685f7f..7692bd31d4533 100644
--- a/flang/test/Lower/dispatch.f90
+++ b/flang/test/Lower/dispatch.f90
@@ -68,26 +68,26 @@ function p1_fct2(p)
       real :: p1_fct2
       class(p1) :: p
     end function
-    ! CHECK-LABEL: func.func @_QMcall_dispatchPp1_fct2(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> f32
+    ! CHECK-LABEL: func.func @_QMcall_dispatchPp1_fct2(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> {fir.bindc_name = "p"}) -> f32
 
     function p1_fct3_arg0(this)
       real :: p1_fct2
       class(p1) :: this
     end function
-    ! CHECK-LABEL: func.func @_QMcall_dispatchPp1_fct3_arg0(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> f32
+    ! CHECK-LABEL: func.func @_QMcall_dispatchPp1_fct3_arg0(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> {fir.bindc_name = "this"}) -> f32
 
     function p1_fct4_arg1(i, this)
       real :: p1_fct2
       integer :: i
       class(p1) :: this
     end function
-    ! CHECK-LABEL: func.func @_QMcall_dispatchPp1_fct4_arg1(%{{.*}}: !fir.ref<i32>, %{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) -> f32
+    ! CHECK-LABEL: func.func @_QMcall_dispatchPp1_fct4_arg1(%{{.*}}: !fir.ref<i32> {fir.bindc_name = "i"}, %{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> {fir.bindc_name = "this"}) -> f32
 
     subroutine pass_with_class_arg(this, other)
       class(p1) :: this
       class(p1) :: other
     end subroutine
-    ! CHECK-LABEL: func.func @_QMcall_dispatchPpass_with_class_arg(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>, %{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>) {
+    ! CHECK-LABEL: func.func @_QMcall_dispatchPpass_with_class_arg(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> {fir.bindc_name = "this"}, %{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>  {fir.bindc_name = "other"}) {
 
     subroutine p1_proc1_nopass()
     end subroutine
@@ -96,18 +96,18 @@ subroutine p1_proc1_nopass()
     subroutine p1_proc2(p)
       class(p1) :: p
     end subroutine
-    ! CHECK-LABEL: func.func @_QMcall_dispatchPp1_proc2(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>)
+    ! CHECK-LABEL: func.func @_QMcall_dispatchPp1_proc2(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> {fir.bindc_name = "p"})
 
     subroutine p1_proc3_arg0(this)
       class(p1) :: this
     end subroutine
-    ! CHECK-LABEL: func.func @_QMcall_dispatchPp1_proc3_arg0(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>)
+    ! CHECK-LABEL: func.func @_QMcall_dispatchPp1_proc3_arg0(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> {fir.bindc_name = "this"})
 
     subroutine p1_proc4_arg1(i, this)
       integer, intent(in) :: i
       class(p1) :: this
     end subroutine
-    ! CHECK-LABEL: func.func @_QMcall_dispatchPp1_proc4_arg1(%{{.*}}: !fir.ref<i32>, %{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>)
+    ! CHECK-LABEL: func.func @_QMcall_dispatchPp1_proc4_arg1(%{{.*}}: !fir.ref<i32> {fir.bindc_name = "i"}, %{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> {fir.bindc_name = "this"})
 
     subroutine tbp_nopass()
     end subroutine
@@ -116,18 +116,18 @@ subroutine tbp_nopass()
     subroutine tbp_pass(t)
       class(p1) :: t
     end subroutine
-    ! CHECK-LABEL: func.func @_QMcall_dispatchPtbp_pass(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>)
+    ! CHECK-LABEL: func.func @_QMcall_dispatchPtbp_pass(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> {fir.bindc_name = "t"})
 
     subroutine tbp_pass_arg0(this)
       class(p1) :: this
     end subroutine
-    ! CHECK-LABEL: func.func @_QMcall_dispatchPtbp_pass_arg0(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>)
+    ! CHECK-LABEL: func.func @_QMcall_dispatchPtbp_pass_arg0(%{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> {fir.bindc_name = "this"})
 
     subroutine tbp_pass_arg1(i, this)
       integer, intent(in) :: i
       class(p1) :: this
     end subroutine
-    ! CHECK-LABEL: func.func @_QMcall_dispatchPtbp_pass_arg1(%{{.*}}: !fir.ref<i32>, %{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>>)
+    ! CHECK-LABEL: func.func @_QMcall_dispatchPtbp_pass_arg1(%{{.*}}: !fir.ref<i32> {fir.bindc_name = "i"}, %{{.*}}: !fir.class<!fir.type<_QMcall_dispatchTp1{a:i32,b:i32}>> {fir.bindc_name = "this"})
 
     subroutine check_dispatch(p)
       class(p1) :: p
diff --git a/flang/test/Lower/extrn_subp.f90 b/flang/test/Lower/extrn_subp.f90
index 3d1d80b30a16f..da6f36d61d2c8 100644
--- a/flang/test/Lower/extrn_subp.f90
+++ b/flang/test/Lower/extrn_subp.f90
@@ -1,4 +1,4 @@
-! RUN: bbc -emit-hlfir -o - %s | FileCheck %s
+! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck %s
 
 module m1
   external :: sub
diff --git a/flang/test/Lower/pointer-default-init.f90 b/flang/test/Lower/pointer-default-init.f90
index dd9c7539b4f05..ebdbfdf4bd9d3 100644
--- a/flang/test/Lower/pointer-default-init.f90
+++ b/flang/test/Lower/pointer-default-init.f90
@@ -11,26 +11,7 @@ module test
   end type
 
   real, pointer :: test_module_pointer(:)
-! CHECK-LABEL:   fir.global @_QMtestEtest_module_pointer : !fir.box<!fir.ptr<!fir.array<?xf32>>> {
-! CHECK:  %[[VAL_0:.*]] = fir.zero_bits !fir.ptr<!fir.array<?xf32>>
-! CHECK:  %[[VAL_1:.*]] = arith.constant 0 : index
-! CHECK:  %[[VAL_2:.*]] = fir.shape %[[VAL_1]] : (index) -> !fir.shape<1>
-! CHECK:  %[[VAL_3:.*]] = fir.embox %[[VAL_0]](%[[VAL_2]]) : (!fir.ptr<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.ptr<!fir.array<?xf32>>>
-! CHECK:  fir.has_value %[[VAL_3]] : !fir.box<!fir.ptr<!fir.array<?xf32>>>
-
   type(t) :: test_module_var
-! CHECK-LABEL:   fir.global @_QMtestEtest_module_var : !fir.type<_QMtestTt{i:i32,x:!fir.box<!fir.ptr<!fir.array<?xf32>>>}> {
-! CHECK:  %[[VAL_0:.*]] = fir.undefined !fir.type<_QMtestTt{i:i32,x:!fir.box<!fir.ptr<!fir.array<?xf32>>>}>
-! CHECK:  %[[VAL_1:.*]] = fir.zero_bits i32
-! CHECK:  %[[VAL_2:.*]] = fir.field_index i
-! CHECK:  %[[VAL_3:.*]] = fir.insert_value %[[VAL_0]], %[[VAL_1]]
-! CHECK:  %[[VAL_4:.*]] = fir.zero_bits !fir.ptr<!fir.array<?xf32>>
-! CHECK:  %[[VAL_5:.*]] = arith.constant 0 : index
-! CHECK:  %[[VAL_6:.*]] = fir.shape %[[VAL_5]] : (index) -> !fir.shape<1>
-! CHECK:  %[[VAL_7:.*]] = fir.embox %[[VAL_4]](%[[VAL_6]]) : (!fir.ptr<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.ptr<!fir.array<?xf32>>>
-! CHECK:  %[[VAL_8:.*]] = fir.field_index x
-! CHECK:  %[[VAL_9:.*]] = fir.insert_value %[[VAL_3]], %[[VAL_7]]
-! CHECK:  fir.has_value %[[VAL_9]]
 end module
 
 subroutine test_local()
@@ -95,6 +76,26 @@ subroutine test_local_pointer()
 subroutine test_saved_pointer()
   real, pointer, save :: x(:)
 end subroutine
+! CHECK-LABEL:   fir.global @_QMtestEtest_module_pointer : !fir.box<!fir.ptr<!fir.array<?xf32>>> {
+! CHECK:  %[[VAL_0:.*]] = fir.zero_bits !fir.ptr<!fir.array<?xf32>>
+! CHECK:  %[[VAL_1:.*]] = arith.constant 0 : index
+! CHECK:  %[[VAL_2:.*]] = fir.shape %[[VAL_1]] : (index) -> !fir.shape<1>
+! CHECK:  %[[VAL_3:.*]] = fir.embox %[[VAL_0]](%[[VAL_2]]) : (!fir.ptr<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.ptr<!fir.array<?xf32>>>
+! CHECK:  fir.has_value %[[VAL_3]] : !fir.box<!fir.ptr<!fir.array<?xf32>>>
+
+! CHECK-LABEL:   fir.global @_QMtestEtest_module_var : !fir.type<_QMtestTt{i:i32,x:!fir.box<!fir.ptr<!fir.array<?xf32>>>}> {
+! CHECK:  %[[VAL_0:.*]] = fir.undefined !fir.type<_QMtestTt{i:i32,x:!fir.box<!fir.ptr<!fir.array<?xf32>>>}>
+! CHECK:  %[[VAL_1:.*]] = fir.zero_bits i32
+! CHECK:  %[[VAL_2:.*]] = fir.field_index i
+! CHECK:  %[[VAL_3:.*]] = fir.insert_value %[[VAL_0]], %[[VAL_1]]
+! CHECK:  %[[VAL_4:.*]] = fir.zero_bits !fir.ptr<!fir.array<?xf32>>
+! CHECK:  %[[VAL_5:.*]] = arith.constant 0 : index
+! CHECK:  %[[VAL_6:.*]] = fir.shape %[[VAL_5]] : (index) -> !fir.shape<1>
+! CHECK:  %[[VAL_7:.*]] = fir.embox %[[VAL_4]](%[[VAL_6]]) : (!fir.ptr<!fir.array<?xf32>>, !fir.shape<1>) -> !fir.box<!fir.ptr<!fir.array<?xf32>>>
+! CHECK:  %[[VAL_8:.*]] = fir.field_index x
+! CHECK:  %[[VAL_9:.*]] = fir.insert_value %[[VAL_3]], %[[VAL_7]]
+! CHECK:  fir.has_value %[[VAL_9]]
+
 ! See check for fir.global internal @_QFtest_saved_pointerEx below.
 
 ! CHECK-LABEL:   fir.global internal @_QFtest_savedEx : !fir.type<_QMtestTt{i:i32,x:!fir.box<!fir.ptr<!fir.array<?xf32>>>}> {
diff --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90
index d8e800771c433..73bd0a858ab6b 100644
--- a/flang/test/Lower/polymorphic.f90
+++ b/flang/test/Lower/polymorphic.f90
@@ -66,14 +66,6 @@ elemental subroutine assign_p1_int(lhs, rhs)
     lhs%b = rhs
   End Subroutine
 
-! CHECK-LABEL: func.func @_QMpolymorphic_testPhost_assoc(
-! CHECK-SAME: %[[THIS:.*]]: !fir.class<!fir.type<_QMpolymorphic_testTp1{{(,sequence)?}}{a:i32,b:i32}>>) {
-! CHECK: %[[TUPLE:.*]] = fir.alloca tuple<!fir.class<!fir.type<_QMpolymorphic_testTp1{{(,sequence)?}}{a:i32,b:i32}>>>
-! CHECK: %[[POS_IN_TUPLE:.*]] = arith.constant 0 : i32
-! CHECK: %[[COORD_OF_CLASS:.*]] = fir.coordinate_of %[[TUPLE]], %[[POS_IN_TUPLE]] : (!fir.ref<tuple<!fir.class<!fir.type<_QMpolymorphic_testTp1{{(,sequence)?}}{a:i32,b:i32}>>>>, i32) -> !fir.ref<!fir.class<!fir.type<_QMpolymorphic_testTp1{{(,sequence)?}}{a:i32,b:i32}>>>
-! CHECK: fir.store %[[THIS]] to %[[COORD_OF_CLASS]] : !fir.ref<!fir.class<!fir.type<_QMpolymorphic_testTp1{{(,sequence)?}}{a:i32,b:i32}>>>
-! CHECK: fir.call @_QMpolymorphic_testFhost_assocPinternal(%[[TUPLE]]) {{.*}} : (!fir.ref<tuple<!fir.class<!fir.type<_QMpolymorphic_testTp1{{(,sequence)?}}{a:i32,b:i32}>>>>) -> ()
-
   elemental integer function elemental_fct(this)
     class(p1), intent(in) :: this
     elemental_fct = this%a
@@ -515,6 +507,14 @@ subroutine test_elemental_assign()
 ! CHECK: fir.array_merge_store %[[LOAD_PA]], %[[DO_RES]] to %[[PA]] : !fir.array<3x!fir.type<_QMpolymorphic_testTp1{{(,sequence)?}}{a:i32,b:i32}>>, !fir.array<3x!fir.type<_QMpolymorphic_testTp1{{(,sequence)?}}{a:i32,b:i32}>>, !fir.ref<!fir.array<3x!fir.type<_QMpolymorphic_testTp1{{(,sequence)?}}{a:i32,b:i32}>>>
 ! CHECK: return
 
+! CHECK-LABEL: func.func @_QMpolymorphic_testPhost_assoc(
+! CHECK-SAME: %[[THIS:.*]]: !fir.class<!fir.type<_QMpolymorphic_testTp1{{(,sequence)?}}{a:i32,b:i32}>> {fir.bindc_name = "this"}) {
+! CHECK: %[[TUPLE:.*]] = fir.alloca tuple<!fir.class<!fir.type<_QMpolymorphic_testTp1{{(,sequence)?}}{a:i32,b:i32}>>>
+! CHECK: %[[POS_IN_TUPLE:.*]] = arith.constant 0 : i32
+! CHECK: %[[COORD_OF_CLASS:.*]] = fir.coordinate_of %[[TUPLE]], %[[POS_IN_TUPLE]] : (!fir.ref<tuple<!fir.class<!fir.type<_QMpolymorphic_testTp1{{(,sequence)?}}{a:i32,b:i32}>>>>, i32) -> !fir.ref<!fir.class<!fir.type<_QMpolymorphic_testTp1{{(,sequence)?}}{a:i32,b:i32}>>>
+! CHECK: fir.store %[[THIS]] to %[[COORD_OF_CLASS]] : !fir.ref<!fir.class<!fir.type<_QMpolymorphic_testTp1{{(,sequence)?}}{a:i32,b:i32}>>>
+! CHECK: fir.call @_QMpolymorphic_testFhost_assocPinternal(%[[TUPLE]]) {{.*}} : (!fir.ref<tuple<!fir.class<!fir.type<_QMpolymorphic_testTp1{{(,sequence)?}}{a:i32,b:i32}>>>>) -> ()
+
   subroutine host_assoc(this)
     class(p1) :: this
 

>From c75b696c614723067397cdd3dbc8c5e0b272adbd Mon Sep 17 00:00:00 2001
From: ShashwathiNavada <shashwathinavada at gmail.com>
Date: Mon, 23 Mar 2026 10:43:56 -0500
Subject: [PATCH 6/9] simple change

---
 flang/lib/Lower/Bridge.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 19921f4dc9c7b..4d74cf04b06b5 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -491,7 +491,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
 
     // - Declare all functions that have definitions so that definition
     //   signatures prevail over call site signatures.
-    // - Module variables are lowered once all the function declarations are available.
+    // - Module variables are lowered once all the function declarations are
+    // available.
     bool hasMainProgram = false;
     const Fortran::semantics::Symbol *globalOmpRequiresSymbol = nullptr;
     createBuilderOutsideOfFuncOpAndDo([&]() {

>From cb7335884fa62ba785eb8bbfbfe1484a6633c6ac Mon Sep 17 00:00:00 2001
From: ShashwathiNavada <shashwathinavada at gmail.com>
Date: Mon, 23 Mar 2026 21:14:38 +0530
Subject: [PATCH 7/9] Update flang/lib/Lower/Bridge.cpp

Co-authored-by: jeanPerier <jean.perier.polytechnique at gmail.com>
---
 flang/lib/Lower/Bridge.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index 4d74cf04b06b5..db51f830208fd 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -539,7 +539,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
                 [&](Fortran::lower::pft::CompilerDirectiveUnit &d) {},
                 [&](Fortran::lower::pft::OpenACCDirectiveUnit &d) {},
             },
-            u);
+       if (auto m = u.getIf<(Fortran::lower::pft::ModuleLikeUnit>())
+          lowerModuleDeclScope(*m);
       }
     });
 

>From d8ec8c5c057503ac8a2756bbe5a88d7036ecc151 Mon Sep 17 00:00:00 2001
From: ShashwathiNavada <shashwathinavada at gmail.com>
Date: Mon, 23 Mar 2026 10:50:58 -0500
Subject: [PATCH 8/9] Simple change

---
 flang/lib/Lower/Bridge.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index db51f830208fd..4d74cf04b06b5 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -539,8 +539,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
                 [&](Fortran::lower::pft::CompilerDirectiveUnit &d) {},
                 [&](Fortran::lower::pft::OpenACCDirectiveUnit &d) {},
             },
-       if (auto m = u.getIf<(Fortran::lower::pft::ModuleLikeUnit>())
-          lowerModuleDeclScope(*m);
+            u);
       }
     });
 

>From ed2cab9934017158188a6c9e2499b8d0cc834320 Mon Sep 17 00:00:00 2001
From: ShashwathiNavada <shashwathinavada at gmail.com>
Date: Thu, 26 Mar 2026 01:49:14 -0500
Subject: [PATCH 9/9] Fixed the testcases

---
 flang/test/Lower/OpenACC/acc-declare.f90           | 14 +++++---------
 .../block-use-predetermined-privatization.f90      |  6 +++---
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/flang/test/Lower/OpenACC/acc-declare.f90 b/flang/test/Lower/OpenACC/acc-declare.f90
index 29b0b0a721677..0d6a949dc5f4b 100644
--- a/flang/test/Lower/OpenACC/acc-declare.f90
+++ b/flang/test/Lower/OpenACC/acc-declare.f90
@@ -327,6 +327,11 @@ module acc_declare_allocatable_test
 ! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath<contract> {acc.declare_action = #acc.declare_action<postAlloc = @_QMacc_declare_post_action_statEx_acc_declare_post_alloc>} : (!fir.ref<!fir.box<none>>, !fir.ref<i64>, i1, !fir.box<none>, !fir.ref<i8>, i32, {{.*}}) -> i32
 ! CHECK: fir.if
 ! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath<contract> {acc.declare_action = #acc.declare_action<postAlloc = @_QMacc_declare_post_action_statEy_acc_declare_post_alloc>} : (!fir.ref<!fir.box<none>>, !fir.ref<i64>, i1, !fir.box<none>, !fir.ref<i8>, i32, {{.*}}) -> i32
+! CHECK-LABEL: func.func @_QMacc_declare_post_action_statPinit_in_data(
+! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath<contract> {acc.declare_action = #acc.declare_action<postAlloc = @_QMacc_declare_post_action_statEx_acc_declare_post_alloc>}
+! CHECK: fir.call @_FortranAAllocatableDeallocate({{.*}}) fastmath<contract> {acc.declare_action = #acc.declare_action<preDealloc = @_QMacc_declare_post_action_statEx_acc_declare_pre_dealloc, postDealloc = @_QMacc_declare_post_action_statEx_acc_declare_post_dealloc>}
+! CHECK-NOT: acc.terminator {acc.declare_action =
+
 
 ! CHECK-LABEL: acc.global_ctor @_QMacc_declare_allocatable_testEdata1_acc_ctor {
 ! CHECK:         %[[GLOBAL_ADDR:.*]] = fir.address_of(@_QMacc_declare_allocatable_testEdata1) {acc.declare = #acc.declare<dataClause =  acc_create>} : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>
@@ -446,12 +451,3 @@ subroutine init_in_data(e)
     !$acc end data
   end subroutine
 end module
-
-! CHECK-LABEL: func.func @_QMacc_declare_post_action_statPinit()
-! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath<contract> {acc.declare_action = #acc.declare_action<postAlloc = @_QMacc_declare_post_action_statEx_acc_declare_post_alloc>} : (!fir.ref<!fir.box<none>>, !fir.ref<i64>, i1, !fir.box<none>, !fir.ref<i8>, i32, {{.*}}) -> i32
-! CHECK: fir.if
-! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath<contract> {acc.declare_action = #acc.declare_action<postAlloc = @_QMacc_declare_post_action_statEy_acc_declare_post_alloc>} : (!fir.ref<!fir.box<none>>, !fir.ref<i64>, i1, !fir.box<none>, !fir.ref<i8>, i32, {{.*}}) -> i32
-! CHECK-LABEL: func.func @_QMacc_declare_post_action_statPinit_in_data(
-! CHECK: fir.call @_FortranAAllocatableAllocate({{.*}}) fastmath<contract> {acc.declare_action = #acc.declare_action<postAlloc = @_QMacc_declare_post_action_statEx_acc_declare_post_alloc>}
-! CHECK: fir.call @_FortranAAllocatableDeallocate({{.*}}) fastmath<contract> {acc.declare_action = #acc.declare_action<preDealloc = @_QMacc_declare_post_action_statEx_acc_declare_pre_dealloc, postDealloc = @_QMacc_declare_post_action_statEx_acc_declare_post_dealloc>}
-! CHECK-NOT: acc.terminator {acc.declare_action =
diff --git a/flang/test/Lower/OpenMP/block-use-predetermined-privatization.f90 b/flang/test/Lower/OpenMP/block-use-predetermined-privatization.f90
index 4509b98c344ab..6697b2a36b841 100644
--- a/flang/test/Lower/OpenMP/block-use-predetermined-privatization.f90
+++ b/flang/test/Lower/OpenMP/block-use-predetermined-privatization.f90
@@ -21,9 +21,6 @@ end program p
 ! CHECK: omp.private {type = private} @[[N_PRIV:.*QMmEn_private.*]] : i32
 ! CHECK: omp.private {type = private} @[[I_PRIV:.*Ei_private.*]] : i32
 
-! Verify the module global exists.
-! CHECK: fir.global @_QMmEn : i32
-
 ! CHECK-LABEL: func.func @_QQmain()
 ! CHECK:         %[[I_ALLOC:.*]] = fir.alloca i32 {bindc_name = "i"
 ! CHECK:         %[[I_DECL:.*]]:2 = hlfir.declare %[[I_ALLOC]] {uniq_name = "_QFEi"}
@@ -41,3 +38,6 @@ end program p
 ! CHECK:           }
 ! CHECK:           omp.terminator
 ! CHECK:         }
+
+! Verify the module global exists.
+! CHECK: fir.global @_QMmEn : i32



More information about the flang-commits mailing list