[flang-commits] [flang] [flang] Do not leak intrinsics used by ISO_C_BINDING and ISO_FORTRAN_ENV (PR #79006)

Michael Klemm via flang-commits flang-commits at lists.llvm.org
Mon Jan 22 08:48:34 PST 2024


https://github.com/mjklemm created https://github.com/llvm/llvm-project/pull/79006

This resolves bug #78953.  Intrinsics used by the MODULE definition are being declared PRIVATE, so that they do not leak into the namespace of the code that USEs the modules.

>From f85e4e216d6b7cb693150354977181a2cd61a13e Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Mon, 22 Jan 2024 17:40:29 +0100
Subject: [PATCH 1/2] Do not leak intrinsics used in the MODULE

---
 flang/module/iso_c_binding.f90   |  4 ++++
 flang/module/iso_fortran_env.f90 | 11 ++++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/flang/module/iso_c_binding.f90 b/flang/module/iso_c_binding.f90
index a34c1d84afbf14..b2cfe0908b7aa5 100644
--- a/flang/module/iso_c_binding.f90
+++ b/flang/module/iso_c_binding.f90
@@ -22,6 +22,10 @@ module iso_c_binding
     c_sizeof => sizeof, &
     operator(==), operator(/=)
 
+  ! Do not leak these intrinsics into the USEing code.
+  private :: kind
+  private :: achar
+
   ! Table 18.2 (in clause 18.3.1)
   ! TODO: Specialize (via macros?) for alternative targets
   integer, parameter :: &
diff --git a/flang/module/iso_fortran_env.f90 b/flang/module/iso_fortran_env.f90
index cd3c06f8c75660..038abc41706af6 100644
--- a/flang/module/iso_fortran_env.f90
+++ b/flang/module/iso_fortran_env.f90
@@ -24,7 +24,16 @@ module iso_fortran_env
     compiler_version => __builtin_compiler_version
 
   implicit none
-  private count
+
+  ! Do not leak these intrinsics into the USEing code.
+  private :: count
+  private :: selected_char_kind
+  private :: selected_int_kind
+  private :: merge
+  private :: digits
+  private :: int
+  private :: selected_real_kind
+  private :: real
 
   ! TODO: Use PACK([x],test) in place of the array constructor idiom
   ! [(x, integer::j=1,COUNT([test]))] below once PACK() can be folded.

>From e30f351b3dfb82dd4db5f1692095346b0dda25ac Mon Sep 17 00:00:00 2001
From: Michael Klemm <michael.klemm at amd.com>
Date: Mon, 22 Jan 2024 17:40:45 +0100
Subject: [PATCH 2/2] Add "implicit none"

---
 flang/module/iso_c_binding.f90 | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/flang/module/iso_c_binding.f90 b/flang/module/iso_c_binding.f90
index b2cfe0908b7aa5..39d64b23c30a3f 100644
--- a/flang/module/iso_c_binding.f90
+++ b/flang/module/iso_c_binding.f90
@@ -22,6 +22,8 @@ module iso_c_binding
     c_sizeof => sizeof, &
     operator(==), operator(/=)
 
+  implicit none
+
   ! Do not leak these intrinsics into the USEing code.
   private :: kind
   private :: achar



More information about the flang-commits mailing list