blob: f612848aa4469e55bd7f8e3d0cfd228e212899f1 [file] [log] [blame]
Dan Albert12c0c8b2014-12-18 00:03:57 +00001//===--------------------- cxa_thread_atexit_test.cpp ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Eric Fiselier82a1fc82016-10-31 14:14:04 +000010// UNSUPPORTED: libcxxabi-no-threads
Eric Fiselier879d18bf2015-02-03 23:50:47 +000011// REQUIRES: linux
Dan Albert12c0c8b2014-12-18 00:03:57 +000012
Eric Fiselierafa6f972017-03-04 01:26:41 +000013// this test will only work if CMake detects a real __cxa_thread_atexit_impl
14// at configure time. This function, however, was added only in glibc 2.18,
15// and there are still plenty of systems only using 2.17 (Ex RHEL 7).
16// XFAIL: libcxxabi-no-cxa-thread-atexit-impl
17
Dan Albert12c0c8b2014-12-18 00:03:57 +000018#include <assert.h>
19#include <cxxabi.h>
20
21static bool AtexitImplCalled = false;
22
23extern "C" int __cxa_thread_atexit_impl(void (*dtor)(void *), void *obj,
24 void *dso_symbol) {
25 assert(dtor == reinterpret_cast<void (*)(void *)>(1));
26 assert(obj == reinterpret_cast<void *>(2));
27 assert(dso_symbol == reinterpret_cast<void *>(3));
28 AtexitImplCalled = true;
29 return 4;
30}
31
32int main() {
33 int RV = __cxxabiv1::__cxa_thread_atexit(
34 reinterpret_cast<void (*)(void *)>(1), reinterpret_cast<void *>(2),
35 reinterpret_cast<void *>(3));
Eric Fiselierb4e15b82016-09-16 08:16:07 +000036 assert(RV == 4);
Dan Albert12c0c8b2014-12-18 00:03:57 +000037 assert(AtexitImplCalled);
38 return 0;
39}