Skip to content

Commit d1a96e9

Browse files
committed
[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
1 parent 3ec88ca commit d1a96e9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

clang/lib/Basic/Targets/OSTargets.h

+10-2
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,16 @@ class LLVM_LIBRARY_VISIBILITY EmscriptenTargetInfo
948948
}
949949

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

955963
} // namespace targets

0 commit comments

Comments
 (0)