Skip to content

Commit a09a8ef

Browse files
sbc100arichardson
authored andcommitted
[clang][emscripten] Reduce alignof long double from 16 to 8 bytes
This means `max_align_t` is 8 bytes which also sets the alignment malloc. Since this is technically and ABI breaking change we have limited to just the emscripten OS target. It is also relatively low import breakage since it will only effect the alignement of struct that contai `long double`s (extremerly rare I imagine). Emscripten's malloc implementation already use 8 byte alignement (dlmalloc uses and alignement of 2*sizeof(void*) == 8 rather than checking max_align_t) so will not be effected by this change. By bringing the ABI in line with the current malloc code this will fix several issue we have seen in the wild. See: emscripten-core/emscripten#14456 Differential Revision: https://reviews.llvm.org/D104808
2 parents 0912db9 + d1a96e9 commit a09a8ef

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

clang/lib/Basic/Targets/OSTargets.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,8 +950,16 @@ class LLVM_LIBRARY_VISIBILITY EmscriptenTargetInfo
950950
}
951951

952952
public:
953-
explicit EmscriptenTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
954-
: WebAssemblyOSTargetInfo<Target>(Triple, Opts) {}
953+
explicit EmscriptenTargetInfo(const llvm::Triple &Triple,
954+
const TargetOptions &Opts)
955+
: WebAssemblyOSTargetInfo<Target>(Triple, Opts) {
956+
// Keeping the alignment of long double to 8 bytes even though its size is
957+
// 16 bytes allows emscripten to have an 8-byte-aligned max_align_t which
958+
// in turn gives is a 8-byte aligned malloc.
959+
// Emscripten's ABI is unstable and we may change this back to 128 to match
960+
// the WebAssembly default in the future.
961+
this->LongDoubleAlign = 64;
962+
}
955963
};
956964

957965
} // namespace targets

0 commit comments

Comments
 (0)