Debian Codegraph @

clang/bindings/python/tests/cindex/test_tls_kind.py

raw
1 from clang.cindex import TLSKind
2
3
4 import unittest
5
6 from .util import get_cursor, get_tu
7
8
9 class TestTLSKind(unittest.TestCase):
10 def test_tls_kind(self):
11 """Ensure that thread-local storage kinds are available on cursors."""
12
13 tu = get_tu(
14 """
15 int tls_none;
16 thread_local int tls_dynamic;
17 _Thread_local int tls_static;
18 """,
19 lang="cpp",
20 )
21
22 tls_none = get_cursor(tu.cursor, "tls_none")
23 self.assertEqual(tls_none.tls_kind, TLSKind.NONE)
24
25 tls_dynamic = get_cursor(tu.cursor, "tls_dynamic")
26 self.assertEqual(tls_dynamic.tls_kind, TLSKind.DYNAMIC)
27
28 tls_static = get_cursor(tu.cursor, "tls_static")
29 self.assertEqual(tls_static.tls_kind, TLSKind.STATIC)
30
31 # The following case tests '__declspec(thread)'. Since it is a Microsoft
32 # specific extension, specific flags are required for the parser to pick
33 # these up.
34 flags = [
35 "-fms-extensions",
36 "-target",
37 "x86_64-unknown-windows-win32",
38 "-fms-compatibility-version=18",
39 ]
40 tu = get_tu(
41 """
42 __declspec(thread) int tls_declspec_msvc18;
43 """,
44 lang="cpp",
45 flags=flags,
46 )
47
48 tls_declspec_msvc18 = get_cursor(tu.cursor, "tls_declspec_msvc18")
49 self.assertEqual(tls_declspec_msvc18.tls_kind, TLSKind.STATIC)
50
51 flags = [
52 "-fms-extensions",
53 "-target",
54 "x86_64-unknown-windows-win32",
55 "-fms-compatibility-version=19",
56 ]
57 tu = get_tu(
58 """
59 __declspec(thread) int tls_declspec_msvc19;
60 """,
61 lang="cpp",
62 flags=flags,
63 )
64
65 tls_declspec_msvc19 = get_cursor(tu.cursor, "tls_declspec_msvc19")
66 self.assertEqual(tls_declspec_msvc19.tls_kind, TLSKind.DYNAMIC)