xref: /llvm-project/compiler-rt/test/cfi/lit.cfg.py (revision f98ee40f4b5d7474fc67e82824bf6abbaedb7b1c)
18007ff1aSReid Klecknerimport lit.formats
28007ff1aSReid Klecknerimport os
38007ff1aSReid Kleckner
4*f98ee40fSTobias Hietaconfig.name = "cfi" + config.name_suffix
5*f98ee40fSTobias Hietaconfig.suffixes = [".c", ".cpp", ".test"]
68007ff1aSReid Klecknerconfig.test_source_root = os.path.dirname(__file__)
78007ff1aSReid Kleckner
8*f98ee40fSTobias Hieta
98007ff1aSReid Klecknerdef build_invocation(compile_flags):
108007ff1aSReid Kleckner    return " " + " ".join([config.clang] + compile_flags) + " "
118007ff1aSReid Kleckner
12*f98ee40fSTobias Hieta
138007ff1aSReid Klecknerclang = build_invocation([config.target_cflags])
148007ff1aSReid Klecknerclangxx = build_invocation([config.target_cflags] + config.cxx_mode_flags)
158007ff1aSReid Kleckner
16*f98ee40fSTobias Hietaconfig.substitutions.append((r"%clang ", clang + " "))
17*f98ee40fSTobias Hietaconfig.substitutions.append((r"%clangxx ", clangxx + " "))
18a14263e8SJon Roelofs
19*f98ee40fSTobias Hietaif "darwin" in config.available_features:
20a14263e8SJon Roelofs    # -fsanitize=cfi is not supported on Darwin hosts
21a14263e8SJon Roelofs    config.unsupported = True
22a14263e8SJon Roelofselif config.lto_supported:
23*f98ee40fSTobias Hieta    clang_cfi = clang + "-fsanitize=cfi "
248007ff1aSReid Kleckner
258007ff1aSReid Kleckner    if config.cfi_lit_test_mode == "Devirt":
26*f98ee40fSTobias Hieta        config.available_features.add("devirt")
27*f98ee40fSTobias Hieta        clang_cfi += "-fwhole-program-vtables "
288007ff1aSReid Kleckner        config.substitutions.append((r"%expect_crash_unless_devirt ", ""))
298007ff1aSReid Kleckner    else:
30*f98ee40fSTobias Hieta        config.substitutions.append(
31*f98ee40fSTobias Hieta            (r"%expect_crash_unless_devirt ", config.expect_crash)
32*f98ee40fSTobias Hieta        )
338007ff1aSReid Kleckner
34*f98ee40fSTobias Hieta    cxx = " ".join(config.cxx_mode_flags) + " "
35*f98ee40fSTobias Hieta    diag = "-fno-sanitize-trap=cfi -fsanitize-recover=cfi "
36*f98ee40fSTobias Hieta    non_dso = "-fvisibility=hidden "
37*f98ee40fSTobias Hieta    dso = "-fsanitize-cfi-cross-dso -fvisibility=default "
388007ff1aSReid Kleckner    if config.android:
39*f98ee40fSTobias Hieta        dso += "-include " + config.test_source_root + "/cross-dso/util/cfi_stubs.h "
408007ff1aSReid Kleckner    config.substitutions.append((r"%clang_cfi ", clang_cfi + non_dso))
418007ff1aSReid Kleckner    config.substitutions.append((r"%clangxx_cfi ", clang_cfi + cxx + non_dso))
428007ff1aSReid Kleckner    config.substitutions.append((r"%clang_cfi_diag ", clang_cfi + non_dso + diag))
43*f98ee40fSTobias Hieta    config.substitutions.append(
44*f98ee40fSTobias Hieta        (r"%clangxx_cfi_diag ", clang_cfi + cxx + non_dso + diag)
45*f98ee40fSTobias Hieta    )
468007ff1aSReid Kleckner    config.substitutions.append((r"%clangxx_cfi_dso ", clang_cfi + cxx + dso))
47*f98ee40fSTobias Hieta    config.substitutions.append(
48*f98ee40fSTobias Hieta        (r"%clangxx_cfi_dso_diag ", clang_cfi + cxx + dso + diag)
49*f98ee40fSTobias Hieta    )
50*f98ee40fSTobias Hieta    config.substitutions.append(
51*f98ee40fSTobias Hieta        (r"%debug_info_flags", " ".join(config.debug_info_flags))
52*f98ee40fSTobias Hieta    )
538007ff1aSReid Klecknerelse:
548007ff1aSReid Kleckner    config.unsupported = True
558007ff1aSReid Kleckner
568007ff1aSReid Klecknerif config.default_sanitizer_opts:
57*f98ee40fSTobias Hieta    config.environment["UBSAN_OPTIONS"] = ":".join(config.default_sanitizer_opts)
588007ff1aSReid Kleckner
59*f98ee40fSTobias Hietaif lit_config.params.get("check_supported", None) and config.unsupported:
608007ff1aSReid Kleckner    raise BaseException("Tests unsupported")
61