[llvm] [flang] __fortran_builtins: Update __builtin_team_type to meet PRIF specification (PR #202450)
Dan Bonachea via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 8 15:46:51 PDT 2026
https://github.com/bonachea created https://github.com/llvm/llvm-project/pull/202450
The representation of `TEAM_TYPE` in the `ISO_FORTRAN_ENV` module is opaque to the compiler, but the size (and alignment) needs to match the PRIF specification for `prif_team_type` to ensure ABI compatibility with the multi-image runtime library.
Flang's old definition as a derived type containing only an `integer(int64)` component was leading to an 8-byte `TEAM_TYPE`. However PRIF specifies the `prif_team_type` component as a `pointer` to an opaque scalar type, which flang compiles to a 40-byte representation.
This mismatch was leading to incorrect behavior at runtime for programs compiled with `-fcoarray` and using `TEAM_TYPE`, where `TEAM_TYPE` values returned by PRIF were being silently truncated by the compiler.
Change the declaration of `__builtin_team_type` to match the PRIF specification, thus ensuring the representation of `TEAM_TYPE` has the required size.
>From 2f6c411872c966fc6719155e67e16f98809b9abc Mon Sep 17 00:00:00 2001
From: Dan Bonachea <dobonachea at lbl.gov>
Date: Thu, 4 Jun 2026 12:02:23 -0700
Subject: [PATCH] __fortran_builtins: Update __builtin_team_type to meet PRIF
specification
The representation of `TEAM_TYPE` in the `ISO_FORTRAN_ENV` module is opaque to
the compiler, but the size (and alignment) needs to match the PRIF
specification for `prif_team_type` to ensure ABI compatibility with the
multi-image runtime library.
Flang's old definition as a derived type containing only an
`integer(int64)` component was leading to an 8-byte `TEAM_TYPE`.
However PRIF specifies the `prif_team_type` component as a `pointer` to an
opaque scalar type, which flang compiles to a 40-byte representation.
This mismatch was leading to incorrect behavior at runtime for programs
compiled with `-fcoarray` and using `TEAM_TYPE`, where `TEAM_TYPE` values
returned by PRIF were being silently truncated by the compiler.
Change the declaration of `__builtin_team_type` to match the PRIF
specification, thus ensuring the representation of `TEAM_TYPE` has the required
size.
---
flang-rt/lib/runtime/__fortran_builtins.f90 | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/flang-rt/lib/runtime/__fortran_builtins.f90 b/flang-rt/lib/runtime/__fortran_builtins.f90
index 4f9874a9bef29..303f2737a8e72 100644
--- a/flang-rt/lib/runtime/__fortran_builtins.f90
+++ b/flang-rt/lib/runtime/__fortran_builtins.f90
@@ -99,8 +99,12 @@
__builtin_ieee_other = &
__builtin_ieee_round_type(_FORTRAN_RUNTIME_IEEE_OTHER)
+ type, private :: __builtin_dummy_team_descriptor_type
+ ! this type is a placeholder for the opaque PRIF type
+ end type
+
type, public :: __builtin_team_type
- integer(kind=int64), private :: __id = -1
+ type(__builtin_dummy_team_descriptor_type), pointer, private :: info => null()
end type
integer, parameter, public :: __builtin_atomic_int_kind = selected_int_kind(18)
More information about the llvm-commits
mailing list