Skip to content

Commit 718638d

Browse files
authored
[flang][runtime] Enable I/O APIs in F18 runtime offload builds. (#87543)
1 parent d53b829 commit 718638d

File tree

8 files changed

+235
-213
lines changed

8 files changed

+235
-213
lines changed

flang/include/flang/Runtime/io-api.h

Lines changed: 82 additions & 82 deletions
Large diffs are not rendered by default.

flang/runtime/environment.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static void SetEnvironmentDefaults(const EnvironmentDefaultList *envDefaults) {
4949
}
5050
}
5151

52+
RT_OFFLOAD_API_GROUP_BEGIN
5253
Fortran::common::optional<Convert> GetConvertFromString(
5354
const char *x, std::size_t n) {
5455
static const char *keywords[]{
@@ -68,6 +69,7 @@ Fortran::common::optional<Convert> GetConvertFromString(
6869
return Fortran::common::nullopt;
6970
}
7071
}
72+
RT_OFFLOAD_API_GROUP_END
7173

7274
void ExecutionEnvironment::Configure(int ac, const char *av[],
7375
const char *env[], const EnvironmentDefaultList *envDefaults) {

flang/runtime/environment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ RT_OFFLOAD_VAR_GROUP_END
3131
// External unformatted I/O data conversions
3232
enum class Convert { Unknown, Native, LittleEndian, BigEndian, Swap };
3333

34-
Fortran::common::optional<Convert> GetConvertFromString(
34+
RT_API_ATTRS Fortran::common::optional<Convert> GetConvertFromString(
3535
const char *, std::size_t);
3636

3737
struct ExecutionEnvironment {

flang/runtime/freestanding-tools.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
#define STD_STRCPY_UNSUPPORTED 1
5353
#endif
5454

55+
#if !defined(STD_STRCMP_UNSUPPORTED) && \
56+
(defined(__CUDACC__) || defined(__CUDA__)) && defined(__CUDA_ARCH__)
57+
#define STD_STRCMP_UNSUPPORTED 1
58+
#endif
59+
5560
namespace Fortran::runtime {
5661

5762
#if STD_FILL_N_UNSUPPORTED
@@ -176,5 +181,19 @@ static inline RT_API_ATTRS char *strcpy(char *dest, const char *src) {
176181
using std::strcpy;
177182
#endif // !STD_STRCPY_UNSUPPORTED
178183

184+
#if STD_STRCMP_UNSUPPORTED
185+
// Provides alternative implementation for std::strcmp(), if
186+
// it is not supported.
187+
static inline RT_API_ATTRS int strcmp(const char *lhs, const char *rhs) {
188+
while (*lhs != '\0' && *lhs == *rhs) {
189+
++lhs;
190+
++rhs;
191+
}
192+
return static_cast<unsigned char>(*lhs) - static_cast<unsigned char>(*rhs);
193+
}
194+
#else // !STD_STRCMP_UNSUPPORTED
195+
using std::strcmp;
196+
#endif // !STD_STRCMP_UNSUPPORTED
197+
179198
} // namespace Fortran::runtime
180199
#endif // FORTRAN_RUNTIME_FREESTANDING_TOOLS_H_

0 commit comments

Comments
 (0)