Skip to content

Commit 7611e12

Browse files
committed
[build-script] Add support for compiling swift with tsan enabled.
1 parent 07b463b commit 7611e12

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

utils/build-presets.ini

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,25 @@ skip-test-watchos
336336

337337
enable-asan
338338

339+
[preset: buildbot_incremental_tsan,tools=RDA,stdlib=RDA]
340+
mixin-preset=buildbot_incremental_base_all_platforms
341+
342+
build-subdir=buildbot_incremental_tsan
343+
344+
# Build Release with debug info, so that we can symbolicate backtraces.
345+
release-debuginfo
346+
assertions
347+
enable-tsan
348+
349+
dash-dash
350+
351+
skip-build-ios
352+
skip-test-ios
353+
skip-build-tvos
354+
skip-test-tvos
355+
skip-build-watchos
356+
skip-test-watchos
357+
339358
[preset: buildbot_incremental_asan_ubsan,tools=RDA,stdlib=RDA]
340359
mixin-preset=buildbot_incremental_base_all_platforms
341360

utils/build-script

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1849,6 +1849,10 @@ details of the setups of other systems or automated environments.""")
18491849
"--enable-ubsan",
18501850
help="enable Undefined Behavior Sanitizer",
18511851
action=arguments.action.optional_bool)
1852+
parser.add_argument(
1853+
"--enable-tsan",
1854+
help="enable Thread Sanitizer",
1855+
action=arguments.action.optional_bool)
18521856
parser.add_argument(
18531857
"--clang-compiler-version",
18541858
help="string that indicates a compiler version for Clang",

utils/swift_build_support/swift_build_support/cmake.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ def common_options(self):
9090
sanitizers.append('Address')
9191
if args.enable_ubsan:
9292
sanitizers.append('Undefined')
93+
if args.enable_tsan:
94+
sanitizers.append('Thread')
9395
if sanitizers:
9496
define("LLVM_USE_SANITIZER", ";".join(sanitizers))
9597

utils/swift_build_support/tests/test_cmake.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def default_args(self):
3232
host_cxx="/path/to/clang++",
3333
enable_asan=False,
3434
enable_ubsan=False,
35+
enable_tsan=False,
3536
export_compile_commands=False,
3637
distcc=False,
3738
cmake_generator="Ninja",
@@ -84,6 +85,17 @@ def test_common_options_ubsan(self):
8485
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
8586
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++"])
8687

88+
def test_common_options_tsan(self):
89+
args = self.default_args()
90+
args.enable_tsan = True
91+
cmake = self.cmake(args)
92+
self.assertEqual(
93+
list(cmake.common_options()),
94+
["-G", "Ninja",
95+
"-DLLVM_USE_SANITIZER=Thread",
96+
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
97+
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++"])
98+
8799
def test_common_options_asan_ubsan(self):
88100
args = self.default_args()
89101
args.enable_asan = True
@@ -96,6 +108,31 @@ def test_common_options_asan_ubsan(self):
96108
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
97109
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++"])
98110

111+
def test_common_options_ubsan_tsan(self):
112+
args = self.default_args()
113+
args.enable_ubsan = True
114+
args.enable_tsan = True
115+
cmake = self.cmake(args)
116+
self.assertEqual(
117+
list(cmake.common_options()),
118+
["-G", "Ninja",
119+
"-DLLVM_USE_SANITIZER=Undefined;Thread",
120+
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
121+
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++"])
122+
123+
def test_common_options_asan_ubsan_tsan(self):
124+
args = self.default_args()
125+
args.enable_asan = True
126+
args.enable_ubsan = True
127+
args.enable_tsan = True
128+
cmake = self.cmake(args)
129+
self.assertEqual(
130+
list(cmake.common_options()),
131+
["-G", "Ninja",
132+
"-DLLVM_USE_SANITIZER=Address;Undefined;Thread",
133+
"-DCMAKE_C_COMPILER:PATH=/path/to/clang",
134+
"-DCMAKE_CXX_COMPILER:PATH=/path/to/clang++"])
135+
99136
def test_common_options_export_compile_commands(self):
100137
args = self.default_args()
101138
args.export_compile_commands = True

0 commit comments

Comments
 (0)