xref: /llvm-project/compiler-rt/test/msan/lit.cfg.py (revision f98ee40f4b5d7474fc67e82824bf6abbaedb7b1c)
1# -*- Python -*-
2
3import os
4
5# Setup config name.
6config.name = "MemorySanitizer" + getattr(config, "name_suffix", "default")
7
8# Setup source root.
9config.test_source_root = os.path.dirname(__file__)
10
11# Setup default compiler flags used with -fsanitize=memory option.
12clang_msan_cflags = (
13    [
14        "-fsanitize=memory",
15        "-mno-omit-leaf-frame-pointer",
16        "-fno-omit-frame-pointer",
17        "-fno-optimize-sibling-calls",
18    ]
19    + [config.target_cflags]
20    + config.debug_info_flags
21)
22# Some Msan tests leverage backtrace() which requires libexecinfo on FreeBSD.
23if config.host_os == "FreeBSD":
24    clang_msan_cflags += ["-lexecinfo", "-fPIC"]
25# On SystemZ we need -mbackchain to make the fast unwinder work.
26if config.target_arch == "s390x":
27    clang_msan_cflags.append("-mbackchain")
28clang_msan_cxxflags = config.cxx_mode_flags + clang_msan_cflags
29
30# Flags for KMSAN invocation. This is C-only, we're not interested in C++.
31clang_kmsan_cflags = (
32    ["-fsanitize=kernel-memory"] + [config.target_cflags] + config.debug_info_flags
33)
34
35
36def build_invocation(compile_flags):
37    return " " + " ".join([config.clang] + compile_flags) + " "
38
39
40config.substitutions.append(("%clang_msan ", build_invocation(clang_msan_cflags)))
41config.substitutions.append(("%clangxx_msan ", build_invocation(clang_msan_cxxflags)))
42config.substitutions.append(("%clang_kmsan ", build_invocation(clang_kmsan_cflags)))
43
44# Default test suffixes.
45config.suffixes = [".c", ".cpp"]
46
47if config.host_os not in ["Linux", "NetBSD", "FreeBSD"]:
48    config.unsupported = True
49
50# For mips64, mips64el we have forced store_context_size to 1 because these
51# archs use slow unwinder which is not async signal safe. Therefore we only
52# check the first frame since store_context size is 1.
53if config.host_arch in ["mips64", "mips64el"]:
54    config.substitutions.append(("CHECK-%short-stack", "CHECK-SHORT-STACK"))
55else:
56    config.substitutions.append(("CHECK-%short-stack", "CHECK-FULL-STACK"))
57
58if config.host_os == "NetBSD":
59    config.substitutions.insert(0, ("%run", config.netbsd_noaslr_prefix))
60