Skip to content

Commit 689673c

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 689673c

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

kernels/prim_ops/register_prim_ops.cpp

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,7 @@ class MemoryManager final {
6767
* TODO(T162089316): Remove this once all users migrate to the new ctor.
6868
*/
6969
ET_DEPRECATED MemoryManager(
70-
// We would normally use ET_UNUSED here, but GCC older than 9.3 has a
71-
// bug that triggers a syntax error when using [[maybe_unused]] on the
72-
// first parameter of a constructor:
73-
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81429
74-
__attribute__((unused)) MemoryAllocator* constant_allocator,
70+
ET_UNUSED MemoryAllocator* constant_allocator,
7571
HierarchicalAllocator* non_constant_allocator,
7672
MemoryAllocator* runtime_allocator,
7773
MemoryAllocator* temporary_allocator)

runtime/executor/program.cpp

Lines changed: 0 additions & 2 deletions
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

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@
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+
// GCC older than 9.3 has a bug that triggers a syntax error when using [[maybe_unused]]
86+
// on the first parameter of a constructor:
87+
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81429
88+
#define ET_UNUSED __attribute__((unused))
89+
#else
8390
#define ET_UNUSED [[maybe_unused]]
91+
#endif
8492

8593
// UNLIKELY Macro
8694
// example
@@ -100,22 +108,38 @@
100108
#endif // (__cplusplus) >= 202002L
101109

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

105119
/**
106120
* Annotation marking a function as printf-like, providing compiler support
107121
* for format string argument checking.
108122
*/
123+
#ifdef _WIN32
124+
#include <sal.h>
125+
#define ET_PRINTFLIKE(_string_index, _va_index) _Printf_format_string_
126+
#else
109127
#define ET_PRINTFLIKE(_string_index, _va_index) \
110128
__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)
129+
#endif
114130

115131
#ifndef __has_builtin
116132
#define __has_builtin(x) (0)
117133
#endif
118134

135+
#if __has_builtin(__builtin_strrchr)
136+
/// Name of the source file without a directory string.
137+
#define ET_SHORT_FILENAME (__builtin_strrchr("/" __FILE__, '/') + 1)
138+
#else
139+
#include <cstring>
140+
#define ET_SHORT_FILENAME (strchr("/" __FILE__, '/') + 1)
141+
#endif
142+
119143
#if __has_builtin(__builtin_LINE)
120144
/// Current line as an integer.
121145
#define ET_LINE __builtin_LINE()

0 commit comments

Comments
 (0)