Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / bindings / python / tests / cindex / test_tls_kind.py
blobb8ef74614ab038f2042522c247008fb1462e9a1b
1 import os
2 from clang.cindex import Config
4 if "CLANG_LIBRARY_PATH" in os.environ:
5 Config.set_library_path(os.environ["CLANG_LIBRARY_PATH"])
7 from clang.cindex import TLSKind
8 from clang.cindex import Cursor
9 from clang.cindex import TranslationUnit
11 from .util import get_cursor
12 from .util import get_tu
14 import unittest
17 class TestTLSKind(unittest.TestCase):
18 def test_tls_kind(self):
19 """Ensure that thread-local storage kinds are available on cursors."""
21 tu = get_tu(
22 """
23 int tls_none;
24 thread_local int tls_dynamic;
25 _Thread_local int tls_static;
26 """,
27 lang="cpp",
30 tls_none = get_cursor(tu.cursor, "tls_none")
31 self.assertEqual(tls_none.tls_kind, TLSKind.NONE)
33 tls_dynamic = get_cursor(tu.cursor, "tls_dynamic")
34 self.assertEqual(tls_dynamic.tls_kind, TLSKind.DYNAMIC)
36 tls_static = get_cursor(tu.cursor, "tls_static")
37 self.assertEqual(tls_static.tls_kind, TLSKind.STATIC)
39 # The following case tests '__declspec(thread)'. Since it is a Microsoft
40 # specific extension, specific flags are required for the parser to pick
41 # these up.
42 flags = [
43 "-fms-extensions",
44 "-target",
45 "x86_64-unknown-windows-win32",
46 "-fms-compatibility-version=18",
48 tu = get_tu(
49 """
50 __declspec(thread) int tls_declspec_msvc18;
51 """,
52 lang="cpp",
53 flags=flags,
56 tls_declspec_msvc18 = get_cursor(tu.cursor, "tls_declspec_msvc18")
57 self.assertEqual(tls_declspec_msvc18.tls_kind, TLSKind.STATIC)
59 flags = [
60 "-fms-extensions",
61 "-target",
62 "x86_64-unknown-windows-win32",
63 "-fms-compatibility-version=19",
65 tu = get_tu(
66 """
67 __declspec(thread) int tls_declspec_msvc19;
68 """,
69 lang="cpp",
70 flags=flags,
73 tls_declspec_msvc19 = get_cursor(tu.cursor, "tls_declspec_msvc19")
74 self.assertEqual(tls_declspec_msvc19.tls_kind, TLSKind.DYNAMIC)