Skip to content

Commit 3c91984

Browse files
committed
[clang] LazyOffsetPtr: Use native pointer width
On big-endian systems, narrow casting will read the higher bits of the value. LazyOffsetPtr's `getAddressOfPointer` returns the address-of `Ptr` which was unconditionally a 64-bit value. On 32-bit big endian systems, reading this value as a 32-bit pointer returns invalid data. Fixes: bc73ef0 ("PR60985: Fix merging of lambda closure types across modules.") Closes: #111993
1 parent efcfa6e commit 3c91984

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

clang/include/clang/AST/ExternalASTSource.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,25 +326,25 @@ struct LazyOffsetPtr {
326326
///
327327
/// If the low bit is clear, a pointer to the AST node. If the low
328328
/// bit is set, the upper 63 bits are the offset.
329-
mutable uint64_t Ptr = 0;
329+
mutable uintptr_t Ptr = 0;
330330

331331
public:
332332
LazyOffsetPtr() = default;
333-
explicit LazyOffsetPtr(T *Ptr) : Ptr(reinterpret_cast<uint64_t>(Ptr)) {}
333+
explicit LazyOffsetPtr(T *Ptr) : Ptr(reinterpret_cast<uintptr_t>(Ptr)) {}
334334

335-
explicit LazyOffsetPtr(uint64_t Offset) : Ptr((Offset << 1) | 0x01) {
336-
assert((Offset << 1 >> 1) == Offset && "Offsets must require < 63 bits");
335+
explicit LazyOffsetPtr(uintptr_t Offset) : Ptr((Offset << 1) | 0x01) {
336+
assert((Offset << 1 >> 1) == Offset && "Offsets must fit in addressable bits");
337337
if (Offset == 0)
338338
Ptr = 0;
339339
}
340340

341341
LazyOffsetPtr &operator=(T *Ptr) {
342-
this->Ptr = reinterpret_cast<uint64_t>(Ptr);
342+
this->Ptr = reinterpret_cast<uintptr_t>(Ptr);
343343
return *this;
344344
}
345345

346-
LazyOffsetPtr &operator=(uint64_t Offset) {
347-
assert((Offset << 1 >> 1) == Offset && "Offsets must require < 63 bits");
346+
LazyOffsetPtr &operator=(uintptr_t Offset) {
347+
assert((Offset << 1 >> 1) == Offset && "Offsets must fit in addressable bits");
348348
if (Offset == 0)
349349
Ptr = 0;
350350
else
@@ -375,7 +375,7 @@ struct LazyOffsetPtr {
375375
if (isOffset()) {
376376
assert(Source &&
377377
"Cannot deserialize a lazy pointer without an AST source");
378-
Ptr = reinterpret_cast<uint64_t>((Source->*Get)(OffsT(Ptr >> 1)));
378+
Ptr = reinterpret_cast<uintptr_t>((Source->*Get)(OffsT(Ptr >> 1)));
379379
}
380380
return reinterpret_cast<T*>(Ptr);
381381
}

0 commit comments

Comments
 (0)