llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-flang-driver

Author: Michael Kruse (Meinersbur)

<details>
<summary>Changes</summary>

The intrinsic modules `iso_c_binding` and `iso_fortran_env` allow Fortran 
programs to inspect properties of type kinds. Since #<!-- -->171515 these can 
be different for each target triple due to using per-triple modules files. 
However, the available types are also affected by compile-time switches such as 
`-fdisable-integer-N` and `-fdisable-real-N`. So far the intrinsic modules just 
assumed that all of them are available, with the exception of `REAL(16)` which 
assumes availability of `REAL(16)` based on where Flang has been compiled 
[sic!].

There is a precedent of the value of a constant depending on compiler flags 
which is `numeric_storage_size` (#<!-- -->87566) in `iso_fortran_env.mod`. This 
PR is replicating this design. That is:
1. Introduce `__builtin_selected_int_kind`, `__builtin_selected_unsigned_kind`, 
and `__builtin_selected_real_kind` as deferred-folding variants of 
`selected_int_kind`, `selected_unsigned_kind`, and `selected_real_kind`.
2. These builtins are not folded to a constant immediately, but only when used 
in a non-intrinsic module/program. That is, the presence of  
`-fdisable-integer-N`/`-fdisable-real-N` is treated as "undetermined".
3. Remove `iso_fortran_env_impl.cpp`. There are no kind constants in the object 
files anymore. They cannot since the value of these constants conceptually 
unknown when compiling Flang-RT. This solves the dreaded "Use Clang for things 
that only Flang can reliably know" problem (#<!-- -->197687).

After this change, `iso_fortran_env_impl.f90` could be re-merged into 
`iso_fortran_env_impl.f90` without requiring Flang to build the shared/static 
Flang-RT library (#<!-- -->169525). It also should make #<!-- -->221907 easier 
as one use of the `FLANG_RUNTIME_F128_MATH_LIB` configure-time option is 
already gone.


Implementation notes:

* This also introduces `-fdisable-real-16`

* The intrinsic module `ieee_arithmetic.mod` needs to be usable even if it 
contains kinds that are currently disabled. Flang hard-codes a exception for 
this.

* `selected_int_kind`, `selected_unsigned_kind`, and `selected_real_kind` are 
still available but in contrast to the `__builtin_` variants never deferred. I 
considered defining them in terms of the builtins like `numeric_storage_size` 
and `ieee_selected_real_kind` already do. However, the AI convinced me against 
doing that as there are apparently more special than simple symbols.

* In a user module, there is a difference between aliasing the intrinsic symbol 
and using it:
```
module m
  use iso_c_binding, only: my_long_double =&gt; c_long_double
  use iso_fortran_env, only: my_nss =&gt; numeric_storage_size
  integer, parameter :: copied_long_double = my_long_double
  integer, parameter :: copied_nss = my_nss
end module
```
For users of `m.mod`, the alias is still sensitive to `-fdisable-real-N` while 
the copied parameter is not. This is already the case for 
`numeric_storage_size` and I did not change that.

* This changes `c_uintmax_t` to constant `c_uint64_t`. It already is the the 
case for `c_intmax_t` [sic!!]. Clang/gcc never define `uintmax_t` to anything 
else than `long long`, they consider  `__int128` a compiler extension. 
Redefining `uintmax_t` would cause [ABI compatibility 
issues](https://thephd.dev/intmax_t-hell-c++-c).

 * Changed `int64` and `__builtin_atomic_int_kind` to literal constants. These 
cannot depend on any dynamic kind selection.

Assisted-by AI

---

Patch is 55.49 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/246686.diff


26 Files Affected:

- (modified) clang/include/clang/Options/FlangOptions.td (+2) 
- (modified) clang/lib/Driver/ToolChains/Flang.cpp (+5) 
- (modified) flang-rt/CMakeLists.txt (-3) 
- (modified) flang-rt/cmake/modules/AddFlangRT.cmake (-4) 
- (modified) flang-rt/lib/runtime/CMakeLists.txt (-1) 
- (modified) flang-rt/lib/runtime/__fortran_builtins.f90 (+2-3) 
- (modified) flang-rt/lib/runtime/__fortran_type_info.f90 (+1-1) 
- (modified) flang-rt/lib/runtime/ieee_arithmetic.f90 (+4-55) 
- (modified) flang-rt/lib/runtime/iso_c_binding.f90 (+11-9) 
- (removed) flang-rt/lib/runtime/iso_fortran_env_impl.cpp (-253) 
- (modified) flang-rt/lib/runtime/iso_fortran_env_impl.f90 (+70-61) 
- (removed) flang-rt/test/Driver/compare_iso_fortran_env_symbols.f90 (-14) 
- (removed) flang-rt/test/Driver/iso_fortran_env_impl.f90 (-25) 
- (modified) flang/docs/ReleaseNotes.md (+5) 
- (modified) flang/include/flang/Evaluate/check-expression.h (+10) 
- (modified) flang/lib/Evaluate/check-expression.cpp (+55-6) 
- (modified) flang/lib/Evaluate/fold-integer.cpp (+6-2) 
- (modified) flang/lib/Evaluate/intrinsics.cpp (+24) 
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+3) 
- (modified) flang/lib/Lower/Bridge.cpp (+11-13) 
- (modified) flang/lib/Semantics/expression.cpp (+8-2) 
- (modified) flang/test/Semantics/bug2236.f90 (+1) 
- (added) flang/test/Semantics/deferred-folding-builtins.f90 (+15) 
- (added) flang/test/Semantics/disabled-integer-kinds.f90 (+70) 
- (added) flang/test/Semantics/disabled-real-kinds.f90 (+69) 
- (added) flang/test/Semantics/modfile-deferred-folding.f90 (+22) 


``````````diff
diff --git a/clang/include/clang/Options/FlangOptions.td 
b/clang/include/clang/Options/FlangOptions.td
index ad39d052bee6af..d3f27bd89bb1c3 100644
--- a/clang/include/clang/Options/FlangOptions.td
+++ b/clang/include/clang/Options/FlangOptions.td
@@ -162,6 +162,8 @@ def fdisable_real_3 : Flag<["-"],"fdisable-real-3">, 
Group<f_Group>,
    HelpText<"Disable real(KIND=3) from TargetCharacteristics">, 
Flags<[HelpHidden]>;
 def fdisable_real_10 : Flag<["-"],"fdisable-real-10">, Group<f_Group>,
   HelpText<"Disable real(KIND=10) from TargetCharacteristics">, 
Flags<[HelpHidden]>;
+def fdisable_real_16 : Flag<["-"],"fdisable-real-16">, Group<f_Group>,
+  HelpText<"Disable real(KIND=16) from TargetCharacteristics">, 
Flags<[HelpHidden]>;
 def fdisable_integer_2 : Flag<["-"],"fdisable-integer-2">, Group<f_Group>,
   HelpText<"Disable integer(KIND=2) from TargetCharacteristics">, 
Flags<[HelpHidden]>;
 def fdisable_integer_16 : Flag<["-"],"fdisable-integer-16">, Group<f_Group>,
diff --git a/clang/lib/Driver/ToolChains/Flang.cpp 
b/clang/lib/Driver/ToolChains/Flang.cpp
index 6a464323c6c225..47bbb9bf245c66 100644
--- a/clang/lib/Driver/ToolChains/Flang.cpp
+++ b/clang/lib/Driver/ToolChains/Flang.cpp
@@ -153,6 +153,11 @@ void Flang::addFortranDialectOptions(const ArgList &Args,
                    options::OPT_fdefault_real_8,
                    options::OPT_fdefault_integer_8,
                    options::OPT_fdefault_double_8,
+                   options::OPT_fdisable_real_3,
+                   options::OPT_fdisable_real_10,
+                   options::OPT_fdisable_real_16,
+                   options::OPT_fdisable_integer_2,
+                   options::OPT_fdisable_integer_16,
                    options::OPT_flarge_sizes,
                    options::OPT_fno_automatic,
                    options::OPT_fhermetic_module_files,
diff --git a/flang-rt/CMakeLists.txt b/flang-rt/CMakeLists.txt
index 8f5dd2a8a0dfb2..47c612b18fa402 100644
--- a/flang-rt/CMakeLists.txt
+++ b/flang-rt/CMakeLists.txt
@@ -182,9 +182,6 @@ if (UNIX AND CMAKE_SYSTEM_NAME MATCHES "AIX")
   add_compile_definitions(_LARGE_FILE_API)
 endif ()
 
-# Indicates REAL(16) support via an external library (e.g. libquadmath).
-add_compile_definitions(FLANG_RT_SUPPORTS_REAL16=$<BOOL:${FORTRAN_SUPPORTS_REAL16}>)
-
 # Check whether the compiler can undefine a macro using the "-Wp,-U" flag.
 # Aternatively, we could use
 #   CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "GNU"
diff --git a/flang-rt/cmake/modules/AddFlangRT.cmake 
b/flang-rt/cmake/modules/AddFlangRT.cmake
index c033efa46100c3..a2c7b2e29691d1 100644
--- a/flang-rt/cmake/modules/AddFlangRT.cmake
+++ b/flang-rt/cmake/modules/AddFlangRT.cmake
@@ -257,10 +257,6 @@ function (add_flangrt_library name)
       target_compile_options(${tgtname} PRIVATE -fno-lto)
     endif ()
 
-    if (FORTRAN_SUPPORTS_REAL16)
-      target_compile_definitions(${tgtname} PRIVATE FLANG_SUPPORT_R16=1)
-    endif ()
-
     # Use compiler-specific options to disable exceptions and RTTI.
     if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
       target_compile_options(${tgtname} PRIVATE
diff --git a/flang-rt/lib/runtime/CMakeLists.txt 
b/flang-rt/lib/runtime/CMakeLists.txt
index 41ad231a32b3ac..e3f5208c4c8a64 100644
--- a/flang-rt/lib/runtime/CMakeLists.txt
+++ b/flang-rt/lib/runtime/CMakeLists.txt
@@ -113,7 +113,6 @@ set(supported_sources
 
 # List of source not used for GPU offloading.
 set(host_sources
-  iso_fortran_env_impl.cpp
   command.cpp
   complex-powi.cpp
   complex-reduction.c
diff --git a/flang-rt/lib/runtime/__fortran_builtins.f90 
b/flang-rt/lib/runtime/__fortran_builtins.f90
index 773b5679cfd714..97e544af56a2a4 100644
--- a/flang-rt/lib/runtime/__fortran_builtins.f90
+++ b/flang-rt/lib/runtime/__fortran_builtins.f90
@@ -40,8 +40,7 @@
   intrinsic :: sizeof ! extension
   public :: sizeof
 
-  intrinsic :: selected_int_kind
-  integer, parameter :: int64 = selected_int_kind(18)
+  integer, parameter :: int64 = 8
 
   type, bind(c), public :: __builtin_c_ptr
     integer(kind=int64), private :: __address
@@ -114,7 +113,7 @@
     type(__builtin_c_ptr), private :: info
   end type
 
-  integer, parameter, public :: __builtin_atomic_int_kind = 
selected_int_kind(18)
+  integer, parameter, public :: __builtin_atomic_int_kind = int64
   integer, parameter, public :: &
     __builtin_atomic_logical_kind = __builtin_atomic_int_kind
 
diff --git a/flang-rt/lib/runtime/__fortran_type_info.f90 
b/flang-rt/lib/runtime/__fortran_type_info.f90
index d8cf385b8665ed..abec4f7085513a 100644
--- a/flang-rt/lib/runtime/__fortran_type_info.f90
+++ b/flang-rt/lib/runtime/__fortran_type_info.f90
@@ -21,7 +21,7 @@
   ! to be exported by this MODULE.
   private
 
-  integer, parameter :: int64 = selected_int_kind(18)
+  integer, parameter :: int64 = 8
 
   type :: DerivedType
     ! "TBP" bindings appear first.  Inherited bindings, with overrides already
diff --git a/flang-rt/lib/runtime/ieee_arithmetic.f90 
b/flang-rt/lib/runtime/ieee_arithmetic.f90
index 0277e3b74d4ab3..b838ff49f13be2 100644
--- a/flang-rt/lib/runtime/ieee_arithmetic.f90
+++ b/flang-rt/lib/runtime/ieee_arithmetic.f90
@@ -171,7 +171,10 @@ end function ieee_round_ne
 #define SPECIFICS_L(G) \
   G(1) G(2) G(4) G(8)
 
-#if FLANG_SUPPORT_R16
+! Note that a REAL kind can be disabled using -fdisable-real-N even though the
+! platform supports it. The intrinsic module must make the definitions
+! available if enabled but also not error it disabled. Flang has an exception
+! for this ieee_arithmetic that ignores the error for disabled kinds.
 #if __x86_64__
 #define SPECIFICS_R(G) \
   G(2) G(3) G(4) G(8) G(10) G(16)
@@ -179,15 +182,6 @@ end function ieee_round_ne
 #define SPECIFICS_R(G) \
   G(2) G(3) G(4) G(8) G(16)
 #endif
-#else
-#if __x86_64__
-#define SPECIFICS_R(G) \
-  G(2) G(3) G(4) G(8) G(10)
-#else
-#define SPECIFICS_R(G) \
-  G(2) G(3) G(4) G(8)
-#endif
-#endif
 
 #define SPECIFICS_II(G) \
   G(1,1) G(1,2) G(1,4) G(1,8) G(1,16) \
@@ -196,7 +190,6 @@ end function ieee_round_ne
   G(8,1) G(8,2) G(8,4) G(8,8) G(8,16) \
   G(16,1) G(16,2) G(16,4) G(16,8) G(16,16)
 
-#if FLANG_SUPPORT_R16
 #if __x86_64__
 #define SPECIFICS_RI(G) \
   G(2,1) G(2,2) G(2,4) G(2,8) G(2,16) \
@@ -213,24 +206,7 @@ end function ieee_round_ne
   G(8,1) G(8,2) G(8,4) G(8,8) G(8,16) \
   G(16,1) G(16,2) G(16,4) G(16,8) G(16,16)
 #endif
-#else
-#if __x86_64__
-#define SPECIFICS_RI(G) \
-  G(2,1) G(2,2) G(2,4) G(2,8) \
-  G(3,1) G(3,2) G(3,4) G(3,8) \
-  G(4,1) G(4,2) G(4,4) G(4,8) \
-  G(8,1) G(8,2) G(8,4) G(8,8) \
-  G(10,1) G(10,2) G(10,4) G(10,8)
-#else
-#define SPECIFICS_RI(G) \
-  G(2,1) G(2,2) G(2,4) G(2,8) \
-  G(3,1) G(3,2) G(3,4) G(3,8) \
-  G(4,1) G(4,2) G(4,4) G(4,8) \
-  G(8,1) G(8,2) G(8,4) G(8,8)
-#endif
-#endif
 
-#if FLANG_SUPPORT_R16
 #if __x86_64__
 #define SPECIFICS_RR(G) \
   G(2,2) G(2,3) G(2,4) G(2,8) G(2,10) G(2,16) \
@@ -260,33 +236,6 @@ end function ieee_round_ne
   G(8,8,2) G(8,8,3) G(8,8,4) G(8,8,8) G(16,8,16) \
   G(16,16,2) G(16,16,3) G(16,16,4) G(16,16,8) G(16,16,16)
 #endif
-#else
-#if __x86_64__
-#define SPECIFICS_RR(G) \
-  G(2,2) G(2,3) G(2,4) G(2,8) G(2,10) \
-  G(3,2) G(3,3) G(3,4) G(3,8) G(3,10) \
-  G(4,2) G(4,3) G(4,4) G(4,8) G(4,10) \
-  G(8,2) G(8,3) G(8,4) G(8,8) G(8,10) \
-  G(10,2) G(10,3) G(10,4) G(10,8) G(10,10)
-#define SPECIFICS_rRR(G) \
-  G(2,2,2) G(2,2,3) G(4,2,4) G(8,2,8) G(10,2,10) \
-  G(2,3,2) G(3,3,3) G(4,3,4) G(8,3,8) G(10,3,10) \
-  G(4,4,2) G(4,4,3) G(4,4,4) G(8,4,8) G(10,4,10) \
-  G(8,8,2) G(8,8,3) G(8,8,4) G(8,8,8) G(10,8,10) \
-  G(10,10,2) G(10,10,3) G(10,10,4) G(10,10,8) G(10,10,10)
-#else
-#define SPECIFICS_RR(G) \
-  G(2,2) G(2,3) G(2,4) G(2,8) \
-  G(3,2) G(3,3) G(3,4) G(3,8) \
-  G(4,2) G(4,3) G(4,4) G(4,8) \
-  G(8,2) G(8,3) G(8,4) G(8,8)
-#define SPECIFICS_rRR(G) \
-  G(2,2,2) G(2,2,3) G(4,2,4) G(8,2,8) \
-  G(2,3,2) G(3,3,3) G(4,3,4) G(8,3,8) \
-  G(4,4,2) G(4,4,3) G(4,4,4) G(8,4,8) \
-  G(8,8,2) G(8,8,3) G(8,8,4) G(8,8,8)
-#endif
-#endif
 
 #define IEEE_CLASS_R(XKIND) \
   simple elemental type(ieee_class_type) function ieee_class_a##XKIND(x); \
diff --git a/flang-rt/lib/runtime/iso_c_binding.f90 
b/flang-rt/lib/runtime/iso_c_binding.f90
index 619b1f2e5c6dd5..7664abd9d8b656 100644
--- a/flang-rt/lib/runtime/iso_c_binding.f90
+++ b/flang-rt/lib/runtime/iso_c_binding.f90
@@ -34,6 +34,9 @@ module iso_c_binding
     c_loc, c_null_funptr, c_null_ptr, c_ptr, c_sizeof, f_c_string, &
     operator(==), operator(/=)
 
+  intrinsic :: __builtin_selected_int_kind, __builtin_selected_unsigned_kind, &
+    __builtin_selected_real_kind
+
   ! Table 18.2 (in clause 18.3.1)
   ! TODO: Specialize (via macros?) for alternative targets
   integer, parameter, public :: &
@@ -41,7 +44,7 @@ module iso_c_binding
     c_int16_t = 2, &
     c_int32_t = 4, &
     c_int64_t = 8, &
-    c_int128_t = 16 ! anticipating future addition
+    c_int128_t = merge(16, -1, __builtin_selected_int_kind(38) == 16)
   integer, parameter, public :: &
     c_int = c_int32_t, &
     c_short = c_int16_t, &
@@ -77,15 +80,18 @@ module iso_c_binding
     c_int_least128_t = c_int128_t, &
     c_int_fast128_t = c_int128_t
 
+  logical, parameter :: &
+    hasReal10 = __builtin_selected_real_kind(18, 4931) == 10, &
+    hasReal16 = __builtin_selected_real_kind(33, 4931) == 16
   integer, parameter, public :: &
     c_float = 4, &
     c_double = 8, &
 #if defined(__x86_64__)
-    c_long_double = 10
+    c_long_double = merge(10, merge(-1, -3, hasReal16), hasReal10)
 #elif defined(_WIN32) && defined(__aarch64__)
     c_long_double = 8
 #else
-    c_long_double = 16
+    c_long_double = merge(16, merge(-1, -3, hasReal10), hasReal16)
 #endif
 
   integer, parameter, public :: &
@@ -116,14 +122,14 @@ module iso_c_binding
     c_float16 = 2, &
     c_float16_complex = c_float16
   integer, parameter, public :: &
-    c_float128 = 16, &
+    c_float128 = merge(16, merge(-1, -3, hasReal10), hasReal16), &
     c_float128_complex = c_float128
   integer, parameter, public :: &
     c_uint8_t = 1, &
     c_uint16_t = 2, &
     c_uint32_t = 4, &
     c_uint64_t = 8, &
-    c_uint128_t = 16
+    c_uint128_t = merge(16, -1, __builtin_selected_unsigned_kind(38) == 16)
   integer, parameter, public :: &
     c_unsigned_char = c_uint8_t, &
     c_unsigned_short = c_uint16_t, &
@@ -134,11 +140,7 @@ module iso_c_binding
     c_unsigned_long = c_uint64_t, &
 #endif
     c_unsigned_long_long = c_uint64_t, &
-#if defined(__powerpc__) || defined(_WIN32)
     c_uintmax_t = c_uint64_t
-#else
-    c_uintmax_t = c_uint128_t
-#endif
   integer, parameter, public :: &
     c_uint_fast8_t = c_uint8_t, &
     c_uint_fast16_t = c_uint16_t, &
diff --git a/flang-rt/lib/runtime/iso_fortran_env_impl.cpp 
b/flang-rt/lib/runtime/iso_fortran_env_impl.cpp
deleted file mode 100644
index 70230d0f16c7a7..00000000000000
--- a/flang-rt/lib/runtime/iso_fortran_env_impl.cpp
+++ /dev/null
@@ -1,253 +0,0 @@
-//===-- lib/runtime/iso_fortran_env_impl.cpp --------------------*- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Provides linkable symbols for the iso_fortran_env_impl module constants. It
-// replaces the Fortran source (flang/module/iso_fortran_env_impl.f90) to 
remove
-// the runtime library's build dependency on the Fortran compiler.
-//
-// The values here must stay in sync with the Fortran module source which
-// generates the .mod file during the flang compiler build.
-//
-// Symbol naming follows Flang's module variable mangling:
-//   _QM<module_name>EC<constant_name>
-//
-//===----------------------------------------------------------------------===//
-
-#include "flang/Common/float128.h"
-#include "flang/Common/float80.h"
-#include "flang/Common/type-kinds.h"
-#include <cstdint>
-
-// Fortran merge(tsource, fsource, mask) to match the source module style.
-static constexpr std::int32_t Merge(
-    std::int32_t tsource, std::int32_t fsource, bool mask) {
-  return mask ? tsource : fsource;
-}
-
-// Fortran digits() for integer kind K returns 8*K - 1 (excludes sign bit).
-static constexpr int IntDigits(int kind) { return 8 * kind - 1; }
-
-// Fortran digits() for unsigned kind K returns 8*K (no sign bit).
-static constexpr int UintDigits(int kind) { return 8 * kind; }
-
-// Fortran digits() for real kind K returns the binary precision.
-static constexpr int RealDigits(int kind) {
-  return Fortran::common::PrecisionOfRealKind(kind);
-}
-
-// The smallest valid real kind, used as a safe fallback when a selected
-// real kind is unavailable (so digits() can be called without error).
-static constexpr std::int32_t safeRealFallback{2};
-
-// Integer kinds, selected -> safe -> validated.
-static constexpr std::int32_t selectedInt8{1};
-static constexpr std::int32_t selectedInt16{2};
-static constexpr std::int32_t selectedInt32{4};
-static constexpr std::int32_t selectedInt64{8};
-static constexpr std::int32_t selectedInt128{16};
-
-static constexpr std::int32_t safeInt8{
-    Merge(selectedInt8, 1, selectedInt8 >= 0)};
-static constexpr std::int32_t safeInt16{
-    Merge(selectedInt16, 1, selectedInt16 >= 0)};
-static constexpr std::int32_t safeInt32{
-    Merge(selectedInt32, 1, selectedInt32 >= 0)};
-static constexpr std::int32_t safeInt64{
-    Merge(selectedInt64, 1, selectedInt64 >= 0)};
-static constexpr std::int32_t safeInt128{
-    Merge(selectedInt128, 1, selectedInt128 >= 0)};
-
-static constexpr std::int32_t int8{Merge(
-    selectedInt8, Merge(-2, -1, selectedInt8 >= 0), IntDigits(safeInt8) == 7)};
-static constexpr std::int32_t int16{Merge(selectedInt16,
-    Merge(-2, -1, selectedInt16 >= 0), IntDigits(safeInt16) == 15)};
-static constexpr std::int32_t int32{Merge(selectedInt32,
-    Merge(-2, -1, selectedInt32 >= 0), IntDigits(safeInt32) == 31)};
-static constexpr std::int32_t int64{Merge(selectedInt64,
-    Merge(-2, -1, selectedInt64 >= 0), IntDigits(safeInt64) == 63)};
-static constexpr std::int32_t int128{Merge(selectedInt128,
-    Merge(-2, -1, selectedInt128 >= 0), IntDigits(safeInt128) == 127)};
-
-// Unsigned kinds, same selection as integer, validated with unsigned digits.
-static constexpr std::int32_t selectedUInt8{selectedInt8};
-static constexpr std::int32_t selectedUInt16{selectedInt16};
-static constexpr std::int32_t selectedUInt32{selectedInt32};
-static constexpr std::int32_t selectedUInt64{selectedInt64};
-static constexpr std::int32_t selectedUInt128{selectedInt128};
-
-static constexpr std::int32_t safeUInt8{safeInt8};
-static constexpr std::int32_t safeUInt16{safeInt16};
-static constexpr std::int32_t safeUInt32{safeInt32};
-static constexpr std::int32_t safeUInt64{safeInt64};
-static constexpr std::int32_t safeUInt128{safeInt128};
-
-static constexpr std::int32_t uint8{Merge(selectedUInt8,
-    Merge(-2, -1, selectedUInt8 >= 0), UintDigits(safeUInt8) == 8)};
-static constexpr std::int32_t uint16{Merge(selectedUInt16,
-    Merge(-2, -1, selectedUInt16 >= 0), UintDigits(safeUInt16) == 16)};
-static constexpr std::int32_t uint32{Merge(selectedUInt32,
-    Merge(-2, -1, selectedUInt32 >= 0), UintDigits(safeUInt32) == 32)};
-static constexpr std::int32_t uint64{Merge(selectedUInt64,
-    Merge(-2, -1, selectedUInt64 >= 0), UintDigits(safeUInt64) == 64)};
-static constexpr std::int32_t uint128{Merge(selectedUInt128,
-    Merge(-2, -1, selectedUInt128 >= 0), UintDigits(safeUInt128) == 128)};
-
-// Logical kinds mirror integer kinds.
-static constexpr std::int32_t logical8{int8};
-static constexpr std::int32_t logical16{int16};
-static constexpr std::int32_t logical32{int32};
-static constexpr std::int32_t logical64{int64};
-
-// Real kinds, selected -> safe -> validated.
-static constexpr std::int32_t selectedReal16{2};
-static constexpr std::int32_t selectedBfloat16{3};
-static constexpr std::int32_t selectedReal32{4};
-static constexpr std::int32_t selectedReal64{8};
-
-#if FLANG_RT_SUPPORTS_REAL16
-static constexpr std::int32_t selectedReal80{16};
-#elif HAS_FLOAT80
-static constexpr std::int32_t selectedReal80{10};
-#else
-static constexpr std::int32_t selectedReal80{-3};
-#endif
-
-#if FLANG_RT_SUPPORTS_REAL16
-static constexpr std::int32_t selectedReal64x2{16};
-static constexpr std::int32_t selectedReal128{16};
-#elif HAS_FLOAT80
-static constexpr std::int32_t selectedReal64x2{-1};
-static constexpr std::int32_t selectedReal128{-1};
-#else
-static constexpr std::int32_t selectedReal64x2{-1};
-static constexpr std::int32_t selectedReal128{-3};
-#endif
-
-static constexpr std::int32_t safeReal16{
-    Merge(selectedReal16, safeRealFallback, selectedReal16 >= 0)};
-static constexpr std::int32_t safeBfloat16{
-    Merge(selectedBfloat16, safeRealFallback, selectedBfloat16 >= 0)};
-static constexpr std::int32_t safeReal32{
-    Merge(selectedReal32, safeRealFallback, selectedReal32 >= 0)};
-static constexpr std::int32_t safeReal64{
-    Merge(selectedReal64, safeRealFallback, selectedReal64 >= 0)};
-static constexpr std::int32_t safeReal80{
-    Merge(selectedReal80, safeRealFallback, selectedReal80 >= 0)};
-static constexpr std::int32_t safeReal64x2{
-    Merge(selectedReal64x2, safeRealFallback, selectedReal64x2 >= 0)};
-static constexpr std::int32_t safeReal128{
-    Merge(selectedReal128, safeRealFallback, selectedReal128 >= 0)};
-
-static constexpr std::int32_t real16{Merge(selectedReal16,
-    Merge(-2, -1, selectedReal16 >= 0), RealDigits(safeReal16) == 11)};
-static constexpr std::int32_t bfloat16{Merge(selectedBfloat16,
-    Merge(-2, -1, selectedBfloat16 >= 0), RealDigits(safeBfloat16) == 8)};
-static constexpr std::int32_t real32{Merge(selectedReal32,
-    Merge(-2, -1, selectedReal32 >= 0), RealDigits(safeReal32) == 24)};
-static constexpr std::int32_t real64{Merge(selectedReal64,
-    Merge(-2, -1, selectedReal64 >= 0), RealDigits(safeReal64) == 53)};
-static constexpr std::int32_t real80{Merge(selectedReal80,
-    Merge(-2, -1, selectedReal80 >= 0), RealDigits(safeReal80) == 64)};
-static constexpr std::int32_t real64x2{Merge(selectedReal64x2,
-    Merge(-2, -1, selectedReal64x2 >= 0), RealDigits(safeReal64x2) == 106)};
-static constexpr std::int32_t real128{Merge(selectedReal128,
-    Merge(-2, -1, selectedReal128 >= 0), RealDigits(safeReal128) == 113)};
-
-// Exported symbols with Flang module-variable mangling.
-#define FORTRAN_NAMED_CONST(name) _QMiso_fortran_env_implEC##name
-
-extern "C" {
-
-extern const std::int32_t FORTRAN_NAMED_CONST(selectedint8){selectedInt8};
-extern const std::int32_t FORTRAN_NAMED_CONST(selectedint16){selectedInt16};
-extern const std::int32_t FORTRAN_NAMED_CONST(selectedint32){selectedInt32};
-extern const std::int32_t FORTRAN_NAMED_CONST(selectedint64){selectedInt64};
-extern const std::int32_t FORTRAN_NAMED_CONST(selectedint128){selectedInt128};
-
-extern const std::int32_t FORTRAN_NAMED_CONST(safeint8){safeInt8};
-extern const std::int32_t FORTRAN_NAMED_CONST(safeint16){safeInt16};
-extern const std::int32_t FORTRAN_NAMED_CONST(safeint32){safeInt32};
-extern const std::int32_t FORTRAN_NAMED_CONST(safeint64){safeInt64};
-extern const std::int32_t FORTRAN_NAMED_CONST(safeint128){safeInt128};
-
-extern const std::int32_t FORTRAN_NAMED_CONST(int8){int8};
-extern const std::int32_t FORTRAN_NAMED_CONST(int16){int16};
-extern const std::int32_t FORTRAN_NAMED_CONST(int32){int32};
-extern const std::int32_t FORTRAN_NAMED_CONST(int64){int64};
-extern const std::int32_t FORTRAN_NAMED_CONST(int128){int128};
-
-extern const std::int32_t FORTRAN_NAMED_CONST(selecteduint8){selectedUInt8};
-extern const std::int32_t FORTRAN_NAMED_CONST(selecteduint16){selectedUInt16};
-extern const std::int32_t FORTRAN_NAMED_CONST(selecteduint32){selectedUInt32};
-extern const std::int32_t FORTRAN_NAMED_CONST(selecteduint64){selectedUInt64};
-extern const std::int32_t 
FORTRAN_NAMED_CONST(selecteduint128){selectedUInt128};
-
-extern const std::int32_t FORTRAN_NAMED_CONST(safeuint8){safeUInt8};
-extern const std::int32_t FORTRAN_NAMED_CONST(safeuint16){safeUInt16};
-extern const std::int32_t FORTRAN_NAMED_CONST(safeuint32){safeUInt32};
-extern const std::int32_t FORTRAN_NAMED_CONST(safeuint64){safeUInt64};
-extern const std::int32_t FORTRAN_NAMED_CONST(safeuint128){safeUInt128};
-
-extern const std::int32_t FORTRAN_NAMED_CONST(uint8){uint8};
-extern const std::int32_t FORTRAN_NAMED_CONST(uint16){uint16}...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/246686
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to