Debian Codegraph @

llvm-project/clang/bindings/python/tests/cindex/test_tls_kind.py

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