From d1a96e906cc03a95cfd41a1f22bdda92651250c7 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 23 Jun 2021 12:02:32 -0700 Subject: [PATCH] [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: https://github.com/emscripten-core/emscripten/pull/14456 Differential Revision: https://reviews.llvm.org/D104808 --- clang/lib/Basic/Targets/OSTargets.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index ce56b4f1f005e1..335ca5635642cd 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -948,8 +948,16 @@ class LLVM_LIBRARY_VISIBILITY EmscriptenTargetInfo } public: - explicit EmscriptenTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) - : WebAssemblyOSTargetInfo(Triple, Opts) {} + explicit EmscriptenTargetInfo(const llvm::Triple &Triple, + const TargetOptions &Opts) + : WebAssemblyOSTargetInfo(Triple, Opts) { + // Keeping the alignment of long double to 8 bytes even though its size is + // 16 bytes allows emscripten to have an 8-byte-aligned max_align_t which + // in turn gives is a 8-byte aligned malloc. + // Emscripten's ABI is unstable and we may change this back to 128 to match + // the WebAssembly default in the future. + this->LongDoubleAlign = 64; + } }; } // namespace targets