[flang] [llvm] [flang] Implement CFI_show() (PR #155631)

Eugene Epshteyn via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 2 09:51:18 PDT 2025


https://github.com/eugeneepshteyn updated https://github.com/llvm/llvm-project/pull/155631

>From a458f6c68b2f1d44120b3f4853046d198ae4fbab Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Wed, 27 Aug 2025 10:36:33 -0400
Subject: [PATCH 1/2] [flang] Implement CFI_show()

Implement in runtime and add declaration to ISO_Fortran_binding.h
---
 flang-rt/lib/runtime/ISO_Fortran_binding.cpp | 8 ++++++++
 flang/include/flang/ISO_Fortran_binding.h    | 1 +
 2 files changed, 9 insertions(+)

diff --git a/flang-rt/lib/runtime/ISO_Fortran_binding.cpp b/flang-rt/lib/runtime/ISO_Fortran_binding.cpp
index a5f8b357ae0b8..22d32155b915a 100644
--- a/flang-rt/lib/runtime/ISO_Fortran_binding.cpp
+++ b/flang-rt/lib/runtime/ISO_Fortran_binding.cpp
@@ -297,6 +297,14 @@ RT_API_ATTRS int CFI_setpointer(CFI_cdesc_t *result, const CFI_cdesc_t *source,
   return CFI_SUCCESS;
 }
 
+RT_API_ATTRS void CFI_show(void *buf, const CFI_cdesc_t *descr) {
+  FILE *f{stderr};
+  std::fprintf(f, "%p CFI_desc_t: %p\n", buf, descr);
+  if (descr) {
+    reinterpret_cast<const Fortran::runtime::Descriptor *>(descr)->Dump(f);
+  }
+}
+
 RT_EXT_API_GROUP_END
 } // extern "C"
 } // namespace Fortran::ISO
diff --git a/flang/include/flang/ISO_Fortran_binding.h b/flang/include/flang/ISO_Fortran_binding.h
index f5b8d0d2ea610..4e2575ee9a622 100644
--- a/flang/include/flang/ISO_Fortran_binding.h
+++ b/flang/include/flang/ISO_Fortran_binding.h
@@ -208,6 +208,7 @@ RT_API_ATTRS int CFI_select_part(CFI_cdesc_t *, const CFI_cdesc_t *source,
     size_t displacement, size_t elem_len);
 RT_API_ATTRS int CFI_setpointer(
     CFI_cdesc_t *, const CFI_cdesc_t *source, const CFI_index_t lower_bounds[]);
+RT_API_ATTRS void CFI_show(void *buf, const CFI_cdesc_t *descr);
 #ifdef __cplusplus
 } // extern "C"
 #endif

>From 1a11ef9b92fc6f2234cc76584b2c08043c4e241f Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Tue, 2 Sep 2025 12:46:10 -0400
Subject: [PATCH 2/2] Only pass the descriptor arg to CFI_show()

---
 flang-rt/lib/runtime/ISO_Fortran_binding.cpp | 6 ++----
 flang/include/flang/ISO_Fortran_binding.h    | 2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/flang-rt/lib/runtime/ISO_Fortran_binding.cpp b/flang-rt/lib/runtime/ISO_Fortran_binding.cpp
index 22d32155b915a..7a12453f058f9 100644
--- a/flang-rt/lib/runtime/ISO_Fortran_binding.cpp
+++ b/flang-rt/lib/runtime/ISO_Fortran_binding.cpp
@@ -297,11 +297,9 @@ RT_API_ATTRS int CFI_setpointer(CFI_cdesc_t *result, const CFI_cdesc_t *source,
   return CFI_SUCCESS;
 }
 
-RT_API_ATTRS void CFI_show(void *buf, const CFI_cdesc_t *descr) {
-  FILE *f{stderr};
-  std::fprintf(f, "%p CFI_desc_t: %p\n", buf, descr);
+RT_API_ATTRS void CFI_show(const CFI_cdesc_t *descr) {
   if (descr) {
-    reinterpret_cast<const Fortran::runtime::Descriptor *>(descr)->Dump(f);
+    reinterpret_cast<const Fortran::runtime::Descriptor *>(descr)->Dump(stderr);
   }
 }
 
diff --git a/flang/include/flang/ISO_Fortran_binding.h b/flang/include/flang/ISO_Fortran_binding.h
index 4e2575ee9a622..ec95ac7aaa7d9 100644
--- a/flang/include/flang/ISO_Fortran_binding.h
+++ b/flang/include/flang/ISO_Fortran_binding.h
@@ -208,7 +208,7 @@ RT_API_ATTRS int CFI_select_part(CFI_cdesc_t *, const CFI_cdesc_t *source,
     size_t displacement, size_t elem_len);
 RT_API_ATTRS int CFI_setpointer(
     CFI_cdesc_t *, const CFI_cdesc_t *source, const CFI_index_t lower_bounds[]);
-RT_API_ATTRS void CFI_show(void *buf, const CFI_cdesc_t *descr);
+RT_API_ATTRS void CFI_show(const CFI_cdesc_t *descr);
 #ifdef __cplusplus
 } // extern "C"
 #endif



More information about the llvm-commits mailing list