Skip to content

Commit 3f58d24

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 63017e4 commit 3f58d24

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
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/memory_manager.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class MemoryManager final {
7171
// bug that triggers a syntax error when using [[maybe_unused]] on the
7272
// first parameter of a constructor:
7373
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81429
74-
__attribute__((unused)) MemoryAllocator* constant_allocator,
74+
ET_UNUSED MemoryAllocator* constant_allocator,
7575
HierarchicalAllocator* non_constant_allocator,
7676
MemoryAllocator* runtime_allocator,
7777
MemoryAllocator* temporary_allocator)

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

+24-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@
8080
[[deprecated("This API is experimental and may change without notice.")]]
8181
#define ET_FALLTHROUGH [[fallthrough]]
8282
#define ET_NODISCARD [[nodiscard]]
83+
84+
#if defined(__GNUC__) && (__GNUC__ < 9 || (__GNUC__ == 9 && __GNUC_MINOR__ < 3))
85+
#define ET_UNUSED __attribute__((unused))
86+
#else
8387
#define ET_UNUSED [[maybe_unused]]
88+
#endif
8489

8590
// UNLIKELY Macro
8691
// example
@@ -100,22 +105,38 @@
100105
#endif // (__cplusplus) >= 202002L
101106

102107
/// Define a C symbol with weak linkage.
108+
#ifdef _WIN32
109+
// There currently doesn't seem to be a great way to do this in Windows and given
110+
// that weak linkage is not really critical on Windows, we'll just leave it as a stub.
111+
#define ET_WEAK
112+
#else
103113
#define ET_WEAK __attribute__((weak))
114+
#endif
104115

105116
/**
106117
* Annotation marking a function as printf-like, providing compiler support
107118
* for format string argument checking.
108119
*/
120+
#ifdef _WIN32
121+
#include <sal.h>
122+
#define ET_PRINTFLIKE(_string_index, _va_index) _Printf_format_string_
123+
#else
109124
#define ET_PRINTFLIKE(_string_index, _va_index) \
110125
__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)
126+
#endif
114127

115128
#ifndef __has_builtin
116129
#define __has_builtin(x) (0)
117130
#endif
118131

132+
#if __has_builtin(__builtin_strrchr)
133+
/// Name of the source file without a directory string.
134+
#define ET_SHORT_FILENAME (__builtin_strrchr("/" __FILE__, '/') + 1)
135+
#else
136+
#include <cstring>
137+
#define ET_SHORT_FILENAME (strchr("/" __FILE__, '/') + 1)
138+
#endif
139+
119140
#if __has_builtin(__builtin_LINE)
120141
/// Current line as an integer.
121142
#define ET_LINE __builtin_LINE()

0 commit comments

Comments
 (0)