[flang-commits] [flang] [llvm] [Flang][Fir] Set default alignment of array globals to 64 bytes (PR #194969)

Tarun Prabhu via flang-commits flang-commits at lists.llvm.org
Wed Apr 29 15:46:36 PDT 2026


================
@@ -0,0 +1,74 @@
+! RUN: bbc -emit-fir -hlfir -o - %s | FileCheck %s
+
+module m
+  implicit none
+
+  ! Array Globals that should get alignment 64 by default.
+  integer :: int_array(10)
+  real :: real_array(5, 5)
+  complex :: complex_array(3)
+  logical :: logical_array(4)
+  character(len=10) :: char_array(2)
+
+  integer, target :: target_array(8)
+
+  ! Currently not align 64
+  integer, allocatable :: alloc_array(:)
+
+  ! Non-array and Bind(C) globals should not get alignment 
+  integer :: scalar_var
+
+  integer, bind(c, name="c_int_array") :: bind_c_int_array(10)
+  real, bind(c, name="c_real_array") :: bind_c_real_array(5)
+
+  ! BIND(C) arrays with initializers (exercises tryCreatingDenseGlobal path)
+  integer, bind(c, name="c_init_array") :: bind_c_init_array(5) = [1,2,3,4,5]
+  real, bind(c, name="c_real_init") :: bind_c_real_init(3) = [1.0, 2.0, 3.0]
+
+  integer, bind(c, name="c_scalar") :: bind_c_scalar
+end module
+
+subroutine sub_with_common()
+  implicit none
+  ! Common block (alignment from semantics, not 64)
+  integer :: cb_int(10)
+  real :: cb_real
+  common /myblock/ cb_int, cb_real
+end subroutine
+
+block data
+  implicit none
+  integer :: bd_array(5)
+  common /initblock/ bd_array
+  data bd_array /1, 2, 3, 4, 5/
+end block data
+
+! CHECK: fir.global @initblock_ {alignment = 4 : i64} : tuple<!fir.array<5xi32>>
+! CHECK-NOT: alignment = 64
----------------
tarunprabhu wrote:

I don't follow why these `CHECK` lines are here. Is there something that comes between `@initblock_` and `@myblock_` that is expected to have an alignment? Or are they intended to say that `@initblock_` and `@myblock_` are not 64-byte aligned?

If the former, there should probably be `CHECK` line here for the entity that is not 64-byte aligned. If the latter, then these are probably unnecessary since the previous line already checks for `alignment = 4`

https://github.com/llvm/llvm-project/pull/194969


More information about the flang-commits mailing list