Skip to content

Commit c557d85

Browse files
authored
[flang][runtime] Add build-time flags to runtime to adjust SELECTED_x_KIND() (#105575)
Add FLANG_RUNTIME_NO_INTEGER_16 and FLANG_RUNTIME_NO_REAL_{2,10,16} to allow one to disable those kinds from being returned from SELECTED_INT_KIND and SELECTED_REAL_KIND even if they are actually available in the C++ build compiler.
1 parent 6b98a72 commit c557d85

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

flang/runtime/numeric.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ inline RT_API_ATTRS CppTypeFor<TypeCategory::Integer, 4> SelectedIntKind(T x) {
105105
return 4;
106106
} else if (x <= 18) {
107107
return 8;
108-
#ifdef __SIZEOF_INT128__
108+
#if defined __SIZEOF_INT128__ && !defined FLANG_RUNTIME_NO_INTEGER_16
109109
} else if (x <= 38) {
110110
return 16;
111111
#endif
@@ -137,23 +137,35 @@ inline RT_API_ATTRS CppTypeFor<TypeCategory::Integer, 4> SelectedRealKind(
137137
return -5;
138138
}
139139

140+
#ifndef FLANG_RUNTIME_NO_REAL_2
141+
constexpr bool hasReal2{true};
142+
#else
143+
constexpr bool hasReal2{false};
144+
#endif
145+
#if defined LDBL_MANT_DIG == 64 && !defined FLANG_RUNTIME_NO_REAL_10
146+
constexpr bool hasReal10{true};
147+
#else
148+
constexpr bool hasReal10{false};
149+
#endif
150+
#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && \
151+
!defined FLANG_RUNTIME_NO_REAL_16
152+
constexpr bool hasReal16{true};
153+
#else
154+
constexpr bool hasReal16{false};
155+
#endif
156+
140157
int error{0};
141158
int kind{0};
142-
if (p <= 3) {
159+
if (hasReal2 && p <= 3) {
143160
kind = 2;
144161
} else if (p <= 6) {
145162
kind = 4;
146163
} else if (p <= 15) {
147164
kind = 8;
148-
#if LDBL_MANT_DIG == 64
149-
} else if (p <= 18) {
165+
} else if (hasReal10 && p <= 18) {
150166
kind = 10;
151-
} else if (p <= 33) {
152-
kind = 16;
153-
#elif LDBL_MANT_DIG == 113
154-
} else if (p <= 33) {
167+
} else if (hasReal16 && p <= 33) {
155168
kind = 16;
156-
#endif
157169
} else {
158170
error -= 1;
159171
}
@@ -164,13 +176,10 @@ inline RT_API_ATTRS CppTypeFor<TypeCategory::Integer, 4> SelectedRealKind(
164176
kind = kind < 3 ? (p == 3 ? 4 : 3) : kind;
165177
} else if (r <= 307) {
166178
kind = kind < 8 ? 8 : kind;
167-
#if LDBL_MANT_DIG == 64
168-
} else if (r <= 4931) {
179+
} else if (hasReal10 && r <= 4931) {
169180
kind = kind < 10 ? 10 : kind;
170-
#elif LDBL_MANT_DIG == 113
171-
} else if (r <= 4931) {
181+
} else if (hasReal16 && r <= 4931) {
172182
kind = kind < 16 ? 16 : kind;
173-
#endif
174183
} else {
175184
error -= 2;
176185
}

0 commit comments

Comments
 (0)