Skip to content

Commit d8efe22

Browse files
committed
stdlib: adjust the shims for MSVC mode compilation
The SwiftStdint.h header is used in the compiler as well. The compiler may be built with cl (Visual Studio) on Windows, which does not define `__INTPTR_TYPE__` nor does it define `__INTPTR_WIDTH__`. Simply define the `__swift_{,u}intptr_t` typedefs as Microsoft does on that platform when building with Visual Studio.
1 parent 9cda374 commit d8efe22

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

stdlib/public/SwiftShims/RefCount.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,11 +1406,20 @@ typedef swift::InlineRefCounts InlineRefCounts;
14061406
#endif
14071407

14081408
// These assertions apply to both the C and the C++ declarations.
1409+
#if defined(_MSC_VER) && !defined(__clang__)
1410+
static_assert(sizeof(InlineRefCounts) == sizeof(InlineRefCountsPlaceholder),
1411+
"InlineRefCounts and InlineRefCountsPlaceholder must match");
1412+
static_assert(sizeof(InlineRefCounts) == sizeof(__swift_uintptr_t),
1413+
"InlineRefCounts must be pointer-sized");
1414+
static_assert(__alignof(InlineRefCounts) == __alignof(__swift_uintptr_t),
1415+
"InlineRefCounts must be pointer-aligned");
1416+
#else
14091417
_Static_assert(sizeof(InlineRefCounts) == sizeof(InlineRefCountsPlaceholder),
14101418
"InlineRefCounts and InlineRefCountsPlaceholder must match");
14111419
_Static_assert(sizeof(InlineRefCounts) == sizeof(__swift_uintptr_t),
14121420
"InlineRefCounts must be pointer-sized");
14131421
_Static_assert(_Alignof(InlineRefCounts) == _Alignof(__swift_uintptr_t),
14141422
"InlineRefCounts must be pointer-aligned");
1423+
#endif
14151424

14161425
#endif

stdlib/public/SwiftShims/SwiftStdint.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,20 @@ typedef unsigned __INT8_TYPE__ __swift_uint8_t;
7070
#define __swift_intn_t(n) __swift_join3(__swift_int, n, _t)
7171
#define __swift_uintn_t(n) __swift_join3(__swift_uint, n, _t)
7272

73+
#if defined(_MSC_VER) && !defined(__clang__)
74+
#if defined(_WIN32)
75+
typedef __swift_int32_t __swift_intptr_t;
76+
typedef __swift_uint32_t __swift_uintptr_t;
77+
#elif defined(_WIN64)
78+
typedef __swift_int64_t __swift_intptr_t;
79+
typedef __swift_uint64_t __swift_uintptr_t;
80+
#else
81+
#error unknown windows pointer width
82+
#endif
83+
#else
7384
typedef __swift_intn_t(__INTPTR_WIDTH__) __swift_intptr_t;
7485
typedef __swift_uintn_t(__INTPTR_WIDTH__) __swift_uintptr_t;
7586
#endif
87+
#endif
7688

7789
#endif // SWIFT_STDLIB_SHIMS_SWIFT_STDINT_H

0 commit comments

Comments
 (0)