summaryrefslogtreecommitdiff
path: root/test
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
commitaad059409f93f48058f669d730cb35ad7b84bb69 (patch)
tree9ed81b7357634d43cfdd134cb1f915e75de2daac /test
parentda7d616fd2870e097eaa85bcec38b97a6d6dbde2 (diff)
[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 git-svn-id: https://llvm.org/svn/llvm-project/libcxxabi/trunk@296952 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/test_exception_address_alignment.pass.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/test_exception_address_alignment.pass.cpp b/test/test_exception_address_alignment.pass.cpp
new file mode 100644
index 0000000..5c5b4df
--- /dev/null
+++ b/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);
+ }
+ }
+}