Skip to content

Commit be2de10

Browse files
tarun292facebook-github-bot
authored andcommitted
compiler.h changes for Windows MSVC support (#6623)
Summary: Adding some MSVC (Windows) specific macros to compiler.h to make sure we can build with MSVC. Reviewed By: dbort Differential Revision: D65328573
1 parent 8ab3385 commit be2de10

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

kernels/prim_ops/register_prim_ops.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ static Kernel prim_ops[] = {
148148
EValue& out = *stack[2];
149149
if (a.isInt() && b.isInt()) {
150150
const int64_t quot = a.toInt() / b.toInt();
151-
if (std::signbit(a.toInt()) == std::signbit(b.toInt())) {
151+
if ((a.toInt() < 0) == (b.toInt() < 0)) {
152152
out = EValue(quot);
153153
return;
154154
}

runtime/executor/program.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
#define ET_ENABLE_PROGRAM_VERIFICATION 1
2828
#endif
2929

30-
#pragma clang diagnostic ignored "-Wshadow"
31-
3230
namespace executorch {
3331
namespace runtime {
3432

runtime/platform/compiler.h

+19-3
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,38 @@
100100
#endif // (__cplusplus) >= 202002L
101101

102102
/// Define a C symbol with weak linkage.
103+
#ifdef _WIN32
104+
// There currently doesn't seem to be a great way to do this in Windows and given
105+
// that weak linkage is not really critical on Windows, we'll just leave it as a stub.
106+
#define ET_WEAK
107+
#else
103108
#define ET_WEAK __attribute__((weak))
109+
#endif
104110

105111
/**
106112
* Annotation marking a function as printf-like, providing compiler support
107113
* for format string argument checking.
108114
*/
115+
#ifdef _WIN32
116+
#include <sal.h>
117+
#define ET_PRINTFLIKE(_string_index, _va_index) _Printf_format_string_
118+
#else
109119
#define ET_PRINTFLIKE(_string_index, _va_index) \
110120
__attribute__((format(printf, _string_index, _va_index)))
111-
112-
/// Name of the source file without a directory string.
113-
#define ET_SHORT_FILENAME (__builtin_strrchr("/" __FILE__, '/') + 1)
121+
#endif
114122

115123
#ifndef __has_builtin
116124
#define __has_builtin(x) (0)
117125
#endif
118126

127+
#if __has_builtin(__builtin_strrchr)
128+
/// Name of the source file without a directory string.
129+
#define ET_SHORT_FILENAME (__builtin_strrchr("/" __FILE__, '/') + 1)
130+
#else
131+
#include <cstring>
132+
#define ET_SHORT_FILENAME (strchr("/" __FILE__, '/') + 1)
133+
#endif
134+
119135
#if __has_builtin(__builtin_LINE)
120136
/// Current line as an integer.
121137
#define ET_LINE __builtin_LINE()

0 commit comments

Comments
 (0)