Skip to content

Commit c471b0c

Browse files
committed
WebAssembly: disable relative pointers in the runtime
This is completely untested.
1 parent 26e162d commit c471b0c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

include/swift/Basic/RelativePointer.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ static inline uintptr_t applyRelativeOffset(BasePtrTy *basePtr, Offset offset) {
144144
std::is_signed<Offset>::value,
145145
"offset type should be signed integer");
146146

147+
#ifdef __wasm__
148+
// WebAssembly: hack: disable relative pointers
149+
return (uintptr_t)(intptr_t)offset;
150+
#endif
151+
147152
auto base = reinterpret_cast<uintptr_t>(basePtr);
148153
// We want to do wrapping arithmetic, but with a sign-extended
149154
// offset. To do this in C, we need to do signed promotion to get
@@ -162,6 +167,13 @@ static inline Offset measureRelativeOffset(A *referent, B *base) {
162167
static_assert(std::is_integral<Offset>::value &&
163168
std::is_signed<Offset>::value,
164169
"offset type should be signed integer");
170+
#ifdef __wasm__
171+
// WebAssembly: hack: disable relative pointers
172+
auto offset = (Offset)(uintptr_t)referent;
173+
assert((intptr_t)offset == (intptr_t)(uintptr_t)referent
174+
&& "pointer too large to fit in offset type");
175+
return offset;
176+
#endif
165177

166178
auto distance = (uintptr_t)referent - (uintptr_t)base;
167179
// Truncate as unsigned, then wrap around to signed.

0 commit comments

Comments
 (0)