Skip to content

Commit f4e90e3

Browse files
authored
[flang][runtime] Get rid of warnings in F18 runtime CUDA build. (#85488)
1 parent 715a931 commit f4e90e3

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

flang/runtime/freestanding-tools.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@
4242
#define STD_REALLOC_UNSUPPORTED 1
4343
#endif
4444

45+
#if !defined(STD_MEMCHR_UNSUPPORTED) && \
46+
(defined(__CUDACC__) || defined(__CUDA__)) && defined(__CUDA_ARCH__)
47+
#define STD_MEMCHR_UNSUPPORTED 1
48+
#endif
49+
4550
namespace Fortran::runtime {
4651

4752
#if STD_FILL_N_UNSUPPORTED
@@ -134,5 +139,23 @@ static inline RT_API_ATTRS void *realloc(void *ptr, std::size_t newByteSize) {
134139
using std::realloc;
135140
#endif // !STD_REALLOC_UNSUPPORTED
136141

142+
#if STD_MEMCHR_UNSUPPORTED
143+
// Provides alternative implementation for std::memchr(), if
144+
// it is not supported.
145+
static inline RT_API_ATTRS const void *memchr(
146+
const void *ptr, int ch, std::size_t count) {
147+
auto buf{reinterpret_cast<const unsigned char *>(ptr)};
148+
auto c{static_cast<unsigned char>(ch)};
149+
for (; count--; ++buf) {
150+
if (*buf == c) {
151+
return buf;
152+
}
153+
}
154+
return nullptr;
155+
}
156+
#else // !STD_MEMCMP_UNSUPPORTED
157+
using std::memchr;
158+
#endif // !STD_MEMCMP_UNSUPPORTED
159+
137160
} // namespace Fortran::runtime
138161
#endif // FORTRAN_RUNTIME_FREESTANDING_TOOLS_H_

flang/runtime/numeric-templates.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,19 @@ template <typename T> struct ABSTy {
122122
static constexpr RT_API_ATTRS T compute(T x) { return std::abs(x); }
123123
};
124124

125+
// Suppress the warnings about calling __host__-only
126+
// 'long double' std::frexp, from __device__ code.
127+
RT_DIAG_PUSH
128+
RT_DIAG_DISABLE_CALL_HOST_FROM_DEVICE_WARN
129+
125130
template <typename T> struct FREXPTy {
126131
static constexpr RT_API_ATTRS T compute(T x, int *e) {
127132
return std::frexp(x, e);
128133
}
129134
};
130135

136+
RT_DIAG_POP
137+
131138
template <typename T> struct ILOGBTy {
132139
static constexpr RT_API_ATTRS int compute(T x) { return std::ilogb(x); }
133140
};

flang/runtime/tools.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ RT_API_ATTRS void ShallowCopy(const Descriptor &to, const Descriptor &from) {
175175

176176
RT_API_ATTRS char *EnsureNullTerminated(
177177
char *str, std::size_t length, Terminator &terminator) {
178-
if (std::memchr(str, '\0', length) == nullptr) {
178+
if (runtime::memchr(str, '\0', length) == nullptr) {
179179
char *newCmd{(char *)AllocateMemoryOrCrash(terminator, length + 1)};
180180
std::memcpy(newCmd, str, length);
181181
newCmd[length] = '\0';

flang/runtime/tools.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ template <>
430430
inline RT_API_ATTRS const char *FindCharacter(
431431
const char *data, char ch, std::size_t chars) {
432432
return reinterpret_cast<const char *>(
433-
std::memchr(data, static_cast<int>(ch), chars));
433+
runtime::memchr(data, static_cast<int>(ch), chars));
434434
}
435435

436436
// Copy payload data from one allocated descriptor to another.

0 commit comments

Comments
 (0)