xref: /llvm-project/libcxxabi/test/exception_object_alignment.2.pass.cpp (revision e92a9c99d66d6a23bcd15b9bdf5ff8d02406446a)
1*e92a9c99SLouis Dionne //===----------------------------------------------------------------------===//
2*e92a9c99SLouis Dionne //
3*e92a9c99SLouis Dionne // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*e92a9c99SLouis Dionne // See https://llvm.org/LICENSE.txt for license information.
5*e92a9c99SLouis Dionne // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*e92a9c99SLouis Dionne //
7*e92a9c99SLouis Dionne //===----------------------------------------------------------------------===//
8*e92a9c99SLouis Dionne 
9*e92a9c99SLouis Dionne // UNSUPPORTED: libcxxabi-no-exceptions
10*e92a9c99SLouis Dionne 
11*e92a9c99SLouis Dionne // This test checks that the compiler does not make incorrect assumptions
12*e92a9c99SLouis Dionne // about the alignment of the exception (only in that specific case, of
13*e92a9c99SLouis Dionne // course).
14*e92a9c99SLouis Dionne //
15*e92a9c99SLouis Dionne // There was a bug where Clang would emit a call to memset assuming a 16-byte
16*e92a9c99SLouis Dionne // aligned exception even when back-deploying to older Darwin systems where
17*e92a9c99SLouis Dionne // exceptions are 8-byte aligned, which caused a segfault on those systems.
18*e92a9c99SLouis Dionne 
19*e92a9c99SLouis Dionne struct exception {
20*e92a9c99SLouis Dionne     exception() : x(0) { }
21*e92a9c99SLouis Dionne     virtual ~exception() { }
22*e92a9c99SLouis Dionne     int x;
23*e92a9c99SLouis Dionne };
24*e92a9c99SLouis Dionne 
25*e92a9c99SLouis Dionne struct foo : exception { };
26*e92a9c99SLouis Dionne 
27*e92a9c99SLouis Dionne int main() {
28*e92a9c99SLouis Dionne     try {
29*e92a9c99SLouis Dionne       throw foo();
30*e92a9c99SLouis Dionne     } catch (...) {
31*e92a9c99SLouis Dionne 
32*e92a9c99SLouis Dionne     }
33*e92a9c99SLouis Dionne     return 0;
34*e92a9c99SLouis Dionne }
35