1
2from clang.cindex import TLSKind
3from clang.cindex import Cursor
4from clang.cindex import TranslationUnit
5
6from .util import get_cursor
7from .util import get_tu
8
9def test_tls_kind():
10    """Ensure that thread-local storage kinds are available on cursors."""
11
12    tu = get_tu("""
13int tls_none;
14thread_local int tls_dynamic;
15_Thread_local int tls_static;
16""", lang = 'cpp')
17
18    tls_none = get_cursor(tu.cursor, 'tls_none')
19    assert tls_none.tls_kind == TLSKind.NONE;
20
21    tls_dynamic = get_cursor(tu.cursor, 'tls_dynamic')
22    assert tls_dynamic.tls_kind == TLSKind.DYNAMIC
23
24    tls_static = get_cursor(tu.cursor, 'tls_static')
25    assert tls_static.tls_kind == TLSKind.STATIC
26
27    # The following case tests '__declspec(thread)'.  Since it is a Microsoft
28    # specific extension, specific flags are required for the parser to pick
29    # these up.
30    flags = ['-fms-extensions', '-target', 'x86_64-unknown-windows-win32']
31    tu = get_tu("""
32__declspec(thread) int tls_declspec;
33""", lang = 'cpp', flags=flags)
34
35    tls_declspec = get_cursor(tu.cursor, 'tls_declspec')
36    assert tls_declspec.tls_kind == TLSKind.STATIC
37
38