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