summaryrefslogtreecommitdiffstats
path: root/libcxxabi/test/test_exception_address_alignment.pass.cpp
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2017-03-04 02:04:45 +0000
committerEric Fiselier <eric@efcs.ca>2017-03-04 02:04:45 +0000
commitc74a2e1297341bdf7111c3aa833c71afeae31402 (patch)
tree603f0db8a2608349813543fc8dbd52745e98d503 /libcxxabi/test/test_exception_address_alignment.pass.cpp
parent9984624edf9925a37b2d274a84b0709b238c216c (diff)
downloadbcm5719-llvm-c74a2e1297341bdf7111c3aa833c71afeae31402.tar.gz
bcm5719-llvm-c74a2e1297341bdf7111c3aa833c71afeae31402.zip
[libcxxabi] Fix alignment of allocated exceptions in 32 bit builds
Summary: In 32 bit builds on a 64 bit system `std::malloc` does not return correctly aligned memory. This leads to undefined behavior. This patch switches to using `posix_memalign` to allocate correctly aligned memory instead. Reviewers: mclow.lists, danalbert, jroelofs, compnerd Reviewed By: compnerd Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25417 llvm-svn: 296952
Diffstat (limited to 'libcxxabi/test/test_exception_address_alignment.pass.cpp')
-rw-r--r--libcxxabi/test/test_exception_address_alignment.pass.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/libcxxabi/test/test_exception_address_alignment.pass.cpp b/libcxxabi/test/test_exception_address_alignment.pass.cpp
new file mode 100644
index 00000000000..5c5b4dfe7cc
--- /dev/null
+++ b/libcxxabi/test/test_exception_address_alignment.pass.cpp
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Test that the address of the exception object is properly aligned to the
+// largest supported alignment for the system.
+
+#include <cstdint>
+#include <cassert>
+
+struct __attribute__((aligned)) AlignedType {};
+struct MinAligned { };
+static_assert(alignof(MinAligned) == 1 && sizeof(MinAligned) == 1, "");
+
+int main() {
+ for (int i=0; i < 10; ++i) {
+ try {
+ throw MinAligned{};
+ } catch (MinAligned const& ref) {
+ assert(reinterpret_cast<uintptr_t>(&ref) % alignof(AlignedType) == 0);
+ }
+ }
+}
OpenPOWER on IntegriCloud