Skip to content

Commit 11d1742

Browse files
authored
compiler.h changes for Windows MSVC support
Differential Revision: D65328573 Pull Request resolved: #6623
1 parent 8a4e492 commit 11d1742

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
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

+21-5
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#error "You need C++17 to compile ExecuTorch"
3737
#endif
3838

39-
#if defined(_WIN32) && (defined(min) || defined(max))
39+
#if defined(_MSC_VER) && (defined(min) || defined(max))
4040
#error \
4141
"Macro clash with min and max -- define NOMINMAX when compiling your program on Windows"
4242
#endif
@@ -100,22 +100,38 @@
100100
#endif // (__cplusplus) >= 202002L
101101

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

105112
/**
106113
* Annotation marking a function as printf-like, providing compiler support
107114
* for format string argument checking.
108115
*/
116+
#ifdef _MSC_VER
117+
#include <sal.h>
118+
#define ET_PRINTFLIKE(_string_index, _va_index) _Printf_format_string_
119+
#else
109120
#define ET_PRINTFLIKE(_string_index, _va_index) \
110121
__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)
122+
#endif
114123

115124
#ifndef __has_builtin
116125
#define __has_builtin(x) (0)
117126
#endif
118127

128+
#if __has_builtin(__builtin_strrchr)
129+
/// Name of the source file without a directory string.
130+
#define ET_SHORT_FILENAME (__builtin_strrchr("/" __FILE__, '/') + 1)
131+
#else
132+
#define ET_SHORT_FILENAME __FILE__
133+
#endif
134+
119135
#if __has_builtin(__builtin_LINE)
120136
/// Current line as an integer.
121137
#define ET_LINE __builtin_LINE()
@@ -141,7 +157,7 @@
141157
#endif // ifndef
142158

143159
// Define size_t and ssize_t.
144-
#ifndef _WIN32
160+
#ifndef _MSC_VER
145161
#include <sys/types.h>
146162
#else
147163
#include <stddef.h>

0 commit comments

Comments
 (0)