Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / builtins / Unit / lit.cfg.py
blobf63d15919888efa6dbbda1be3ff3b7a6430492e6
1 # -*- Python -*-
3 import os
4 import platform
5 import shlex
6 import subprocess
8 import lit.formats
10 # Choose between lit's internal shell pipeline runner and a real shell. If
11 # LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override.
12 use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
13 if use_lit_shell:
14 # 0 is external, "" is default, and everything else is internal.
15 execute_external = use_lit_shell == "0"
16 else:
17 # Otherwise we default to internal on Windows and external elsewhere, as
18 # bash on Windows is usually very slow.
19 execute_external = not sys.platform in ["win32"]
22 def get_required_attr(config, attr_name):
23 attr_value = getattr(config, attr_name, None)
24 if attr_value == None:
25 lit_config.fatal(
26 "No attribute %r in test configuration! You may need to run "
27 "tests from your build directory or add this attribute "
28 "to lit.site.cfg.py " % attr_name
30 return attr_value
33 def get_library_path(file):
34 cmd = subprocess.Popen(
35 [config.clang.strip(), "-print-file-name=%s" % file]
36 + shlex.split(config.target_cflags),
37 stdout=subprocess.PIPE,
38 env=config.environment,
39 universal_newlines=True,
41 if not cmd.stdout:
42 lit_config.fatal("Couldn't find the library path for '%s'" % file)
43 dir = cmd.stdout.read().strip()
44 if sys.platform in ["win32"] and execute_external:
45 # Don't pass dosish path separator to msys bash.exe.
46 dir = dir.replace("\\", "/")
47 return dir
50 def get_libgcc_file_name():
51 cmd = subprocess.Popen(
52 [config.clang.strip(), "-print-libgcc-file-name"]
53 + shlex.split(config.target_cflags),
54 stdout=subprocess.PIPE,
55 env=config.environment,
56 universal_newlines=True,
58 if not cmd.stdout:
59 lit_config.fatal("Couldn't find the library path for '%s'" % file)
60 dir = cmd.stdout.read().strip()
61 if sys.platform in ["win32"] and execute_external:
62 # Don't pass dosish path separator to msys bash.exe.
63 dir = dir.replace("\\", "/")
64 return dir
67 # Setup config name.
68 config.name = "Builtins" + config.name_suffix
70 # Platform-specific default Builtins_OPTIONS for lit tests.
71 default_builtins_opts = ""
73 # Setup source root.
74 config.test_source_root = os.path.dirname(__file__)
76 # Path to the static library
77 is_msvc = get_required_attr(config, "is_msvc")
78 if is_msvc:
79 base_lib = os.path.join(
80 config.compiler_rt_libdir, "clang_rt.builtins%s.lib " % config.target_suffix
82 config.substitutions.append(("%librt ", base_lib))
83 elif config.host_os == "Darwin":
84 base_lib = os.path.join(config.compiler_rt_libdir, "libclang_rt.osx.a ")
85 config.substitutions.append(("%librt ", base_lib + " -lSystem "))
86 elif config.host_os == "Windows":
87 base_lib = os.path.join(
88 config.compiler_rt_libdir, "libclang_rt.builtins%s.a" % config.target_suffix
90 if sys.platform in ["win32"] and execute_external:
91 # Don't pass dosish path separator to msys bash.exe.
92 base_lib = base_lib.replace("\\", "/")
93 config.substitutions.append(
95 "%librt ",
96 base_lib
97 + " -lmingw32 -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 ",
100 else:
101 base_lib = os.path.join(
102 config.compiler_rt_libdir, "libclang_rt.builtins%s.a" % config.target_suffix
104 if sys.platform in ["win32"] and execute_external:
105 # Don't pass dosish path separator to msys bash.exe.
106 base_lib = base_lib.replace("\\", "/")
107 config.substitutions.append(("%librt ", base_lib + " -lc -lm "))
109 builtins_build_crt = get_required_attr(config, "builtins_build_crt")
110 if builtins_build_crt:
111 base_obj = os.path.join(
112 config.compiler_rt_libdir, "clang_rt.%%s%s.o" % config.target_suffix
114 if sys.platform in ["win32"] and execute_external:
115 # Don't pass dosish path separator to msys bash.exe.
116 base_obj = base_obj.replace("\\", "/")
118 config.substitutions.append(("%crtbegin", base_obj % "crtbegin"))
119 config.substitutions.append(("%crtend", base_obj % "crtend"))
121 config.substitutions.append(("%crt1", get_library_path("crt1.o")))
122 config.substitutions.append(("%crti", get_library_path("crti.o")))
123 config.substitutions.append(("%crtn", get_library_path("crtn.o")))
125 config.substitutions.append(("%libgcc", get_libgcc_file_name()))
127 config.substitutions.append(
128 ("%libstdcxx", "-l" + config.sanitizer_cxx_lib.lstrip("lib"))
131 config.available_features.add("crt")
133 builtins_source_dir = os.path.join(
134 get_required_attr(config, "compiler_rt_src_root"), "lib", "builtins"
136 if sys.platform in ["win32"] and execute_external:
137 # Don't pass dosish path separator to msys bash.exe.
138 builtins_source_dir = builtins_source_dir.replace("\\", "/")
139 builtins_lit_source_dir = get_required_attr(config, "builtins_lit_source_dir")
141 extra_link_flags = ["-nodefaultlibs"]
143 target_cflags = [get_required_attr(config, "target_cflags")]
144 target_cflags += ["-fno-builtin", "-I", builtins_source_dir]
145 target_cflags += extra_link_flags
146 target_cxxflags = config.cxx_mode_flags + target_cflags
147 clang_builtins_static_cflags = [""] + config.debug_info_flags + target_cflags
148 clang_builtins_static_cxxflags = config.cxx_mode_flags + clang_builtins_static_cflags
150 clang_builtins_cflags = clang_builtins_static_cflags
151 clang_builtins_cxxflags = clang_builtins_static_cxxflags
153 # FIXME: Right now we don't compile the C99 complex builtins when using
154 # clang-cl. Fix that.
155 if not is_msvc:
156 config.available_features.add("c99-complex")
158 builtins_is_msvc = get_required_attr(config, "builtins_is_msvc")
159 if not builtins_is_msvc:
160 config.available_features.add("int128")
162 clang_wrapper = ""
165 def build_invocation(compile_flags):
166 return " " + " ".join([clang_wrapper, config.clang] + compile_flags) + " "
169 config.substitutions.append(("%clang ", build_invocation(target_cflags)))
170 config.substitutions.append(("%clangxx ", build_invocation(target_cxxflags)))
171 config.substitutions.append(
172 ("%clang_builtins ", build_invocation(clang_builtins_cflags))
174 config.substitutions.append(
175 ("%clangxx_builtins ", build_invocation(clang_builtins_cxxflags))
178 # Default test suffixes.
179 config.suffixes = [".c", ".cpp"]
181 if not config.emulator:
182 config.available_features.add("native-run")
184 # Add features for available sources
185 builtins_source_features = config.builtins_lit_source_features.split(";")
186 # Sanity checks
187 if not builtins_source_features:
188 lit_config.fatal("builtins_source_features cannot be empty")
189 builtins_source_features_set = set()
190 builtins_source_feature_duplicates = []
191 for builtin_source_feature in builtins_source_features:
192 if len(builtin_source_feature) == 0:
193 lit_config.fatal("builtins_source_feature cannot contain empty features")
194 if builtin_source_feature not in builtins_source_features_set:
195 builtins_source_features_set.add(builtin_source_feature)
196 else:
197 builtins_source_feature_duplicates.append(builtin_source_feature)
199 if len(builtins_source_feature_duplicates) > 0:
200 lit_config.fatal(
201 "builtins_source_features contains duplicates: {}".format(
202 builtins_source_feature_duplicates
205 config.available_features.update(builtins_source_features)