[llvm-branch-commits] [llvm] [compiler-rt] [clang] [TySan] A Type Sanitizer (Runtime Library) (PR #76261)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Dec 22 11:21:05 PST 2023


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {darker}-->


:warning: Python code formatter, darker found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
darker --check --diff -r fbaff4033ba060d1478c924ba736be407b4edb80...00e6e657f700e84501cf46a786ccd9389e208ff2 compiler-rt/test/tysan/lit.cfg.py
``````````

</details>

<details>
<summary>
View the diff from darker here.
</summary>

``````````diff
--- lit.cfg.py	2023-12-22 19:18:34.000000 +0000
+++ lit.cfg.py	2023-12-22 19:20:58.101017 +0000
@@ -7,133 +7,155 @@
 import lit.formats
 
 # Get shlex.quote if available (added in 3.3), and fall back to pipes.quote if
 # it's not available.
 try:
-  import shlex
-  sh_quote = shlex.quote
+    import shlex
+
+    sh_quote = shlex.quote
 except:
-  import pipes
-  sh_quote = pipes.quote
+    import pipes
+
+    sh_quote = pipes.quote
+
 
 def get_required_attr(config, attr_name):
-  attr_value = getattr(config, attr_name, None)
-  if attr_value == None:
-    lit_config.fatal(
-      "No attribute %r in test configuration! You may need to run "
-      "tests from your build directory or add this attribute "
-      "to lit.site.cfg.py " % attr_name)
-  return attr_value
+    attr_value = getattr(config, attr_name, None)
+    if attr_value == None:
+        lit_config.fatal(
+            "No attribute %r in test configuration! You may need to run "
+            "tests from your build directory or add this attribute "
+            "to lit.site.cfg.py " % attr_name
+        )
+    return attr_value
+
 
 def push_dynamic_library_lookup_path(config, new_path):
-  if platform.system() == 'Windows':
-    dynamic_library_lookup_var = 'PATH'
-  elif platform.system() == 'Darwin':
-    dynamic_library_lookup_var = 'DYLD_LIBRARY_PATH'
-  else:
-    dynamic_library_lookup_var = 'LD_LIBRARY_PATH'
+    if platform.system() == "Windows":
+        dynamic_library_lookup_var = "PATH"
+    elif platform.system() == "Darwin":
+        dynamic_library_lookup_var = "DYLD_LIBRARY_PATH"
+    else:
+        dynamic_library_lookup_var = "LD_LIBRARY_PATH"
 
-  new_ld_library_path = os.path.pathsep.join(
-    (new_path, config.environment.get(dynamic_library_lookup_var, '')))
-  config.environment[dynamic_library_lookup_var] = new_ld_library_path
+    new_ld_library_path = os.path.pathsep.join(
+        (new_path, config.environment.get(dynamic_library_lookup_var, ""))
+    )
+    config.environment[dynamic_library_lookup_var] = new_ld_library_path
 
-  if platform.system() == 'FreeBSD':
-    dynamic_library_lookup_var = 'LD_32_LIBRARY_PATH'
-    new_ld_32_library_path = os.path.pathsep.join(
-      (new_path, config.environment.get(dynamic_library_lookup_var, '')))
-    config.environment[dynamic_library_lookup_var] = new_ld_32_library_path
+    if platform.system() == "FreeBSD":
+        dynamic_library_lookup_var = "LD_32_LIBRARY_PATH"
+        new_ld_32_library_path = os.path.pathsep.join(
+            (new_path, config.environment.get(dynamic_library_lookup_var, ""))
+        )
+        config.environment[dynamic_library_lookup_var] = new_ld_32_library_path
 
-  if platform.system() == 'SunOS':
-    dynamic_library_lookup_var = 'LD_LIBRARY_PATH_32'
-    new_ld_library_path_32 = os.path.pathsep.join(
-      (new_path, config.environment.get(dynamic_library_lookup_var, '')))
-    config.environment[dynamic_library_lookup_var] = new_ld_library_path_32
+    if platform.system() == "SunOS":
+        dynamic_library_lookup_var = "LD_LIBRARY_PATH_32"
+        new_ld_library_path_32 = os.path.pathsep.join(
+            (new_path, config.environment.get(dynamic_library_lookup_var, ""))
+        )
+        config.environment[dynamic_library_lookup_var] = new_ld_library_path_32
 
-    dynamic_library_lookup_var = 'LD_LIBRARY_PATH_64'
-    new_ld_library_path_64 = os.path.pathsep.join(
-      (new_path, config.environment.get(dynamic_library_lookup_var, '')))
-    config.environment[dynamic_library_lookup_var] = new_ld_library_path_64
+        dynamic_library_lookup_var = "LD_LIBRARY_PATH_64"
+        new_ld_library_path_64 = os.path.pathsep.join(
+            (new_path, config.environment.get(dynamic_library_lookup_var, ""))
+        )
+        config.environment[dynamic_library_lookup_var] = new_ld_library_path_64
+
 
 # Setup config name.
-config.name = 'TypeSanitizer' + config.name_suffix
+config.name = "TypeSanitizer" + config.name_suffix
 
 # Platform-specific default TYSAN_OPTIONS for lit tests.
 default_tysan_opts = list(config.default_sanitizer_opts)
 
 # On Darwin, leak checking is not enabled by default. Enable on macOS
 # tests to prevent regressions
-if config.host_os == 'Darwin' and config.apple_platform == 'osx':
-  default_tysan_opts += ['detect_leaks=1']
+if config.host_os == "Darwin" and config.apple_platform == "osx":
+    default_tysan_opts += ["detect_leaks=1"]
 
-default_tysan_opts_str = ':'.join(default_tysan_opts)
+default_tysan_opts_str = ":".join(default_tysan_opts)
 if default_tysan_opts_str:
-  config.environment['TYSAN_OPTIONS'] = default_tysan_opts_str
-  default_tysan_opts_str += ':'
-config.substitutions.append(('%env_tysan_opts=',
-                             'env TYSAN_OPTIONS=' + default_tysan_opts_str))
+    config.environment["TYSAN_OPTIONS"] = default_tysan_opts_str
+    default_tysan_opts_str += ":"
+config.substitutions.append(
+    ("%env_tysan_opts=", "env TYSAN_OPTIONS=" + default_tysan_opts_str)
+)
 
 # Setup source root.
 config.test_source_root = os.path.dirname(__file__)
 
-if config.host_os not in ['FreeBSD', 'NetBSD']:
-  libdl_flag = "-ldl"
+if config.host_os not in ["FreeBSD", "NetBSD"]:
+    libdl_flag = "-ldl"
 else:
-  libdl_flag = ""
+    libdl_flag = ""
 
 # GCC-ASan doesn't link in all the necessary libraries automatically, so
 # we have to do it ourselves.
-if config.compiler_id == 'GNU':
-  extra_link_flags = ["-pthread", "-lstdc++", libdl_flag]
+if config.compiler_id == "GNU":
+    extra_link_flags = ["-pthread", "-lstdc++", libdl_flag]
 else:
-  extra_link_flags = []
+    extra_link_flags = []
 
 # Setup default compiler flags used with -fsanitize=address option.
 # FIXME: Review the set of required flags and check if it can be reduced.
 target_cflags = [get_required_attr(config, "target_cflags")] + extra_link_flags
 target_cxxflags = config.cxx_mode_flags + target_cflags
-clang_tysan_static_cflags = (["-fsanitize=type",
-                            "-mno-omit-leaf-frame-pointer",
-                            "-fno-omit-frame-pointer",
-                            "-fno-optimize-sibling-calls"] +
-                            config.debug_info_flags + target_cflags)
-if config.target_arch == 's390x':
-  clang_tysan_static_cflags.append("-mbackchain")
+clang_tysan_static_cflags = (
+    [
+        "-fsanitize=type",
+        "-mno-omit-leaf-frame-pointer",
+        "-fno-omit-frame-pointer",
+        "-fno-optimize-sibling-calls",
+    ]
+    + config.debug_info_flags
+    + target_cflags
+)
+if config.target_arch == "s390x":
+    clang_tysan_static_cflags.append("-mbackchain")
 clang_tysan_static_cxxflags = config.cxx_mode_flags + clang_tysan_static_cflags
 
-clang_tysan_cflags = clang_tysan_static_cflags 
+clang_tysan_cflags = clang_tysan_static_cflags
 clang_tysan_cxxflags = clang_tysan_static_cxxflags
 
+
 def build_invocation(compile_flags):
-  return " " + " ".join([config.clang] + compile_flags) + " "
+    return " " + " ".join([config.clang] + compile_flags) + " "
 
-config.substitutions.append( ("%clang ", build_invocation(target_cflags)) )
-config.substitutions.append( ("%clangxx ", build_invocation(target_cxxflags)) )
-config.substitutions.append( ("%clang_tysan ", build_invocation(clang_tysan_cflags)) )
-config.substitutions.append( ("%clangxx_tysan ", build_invocation(clang_tysan_cxxflags)) )
+
+config.substitutions.append(("%clang ", build_invocation(target_cflags)))
+config.substitutions.append(("%clangxx ", build_invocation(target_cxxflags)))
+config.substitutions.append(("%clang_tysan ", build_invocation(clang_tysan_cflags)))
+config.substitutions.append(("%clangxx_tysan ", build_invocation(clang_tysan_cxxflags)))
 
 
 # FIXME: De-hardcode this path.
 tysan_source_dir = os.path.join(
-  get_required_attr(config, "compiler_rt_src_root"), "lib", "tysan")
+    get_required_attr(config, "compiler_rt_src_root"), "lib", "tysan"
+)
 python_exec = sh_quote(get_required_attr(config, "python_executable"))
 
 # Set LD_LIBRARY_PATH to pick dynamic runtime up properly.
 push_dynamic_library_lookup_path(config, config.compiler_rt_libdir)
 
 # Default test suffixes.
-config.suffixes = ['.c', '.cpp']
+config.suffixes = [".c", ".cpp"]
 
-if config.host_os == 'Darwin':
-  config.suffixes.append('.mm')
+if config.host_os == "Darwin":
+    config.suffixes.append(".mm")
 
-if config.host_os == 'Windows':
-  config.substitutions.append(('%fPIC', ''))
-  config.substitutions.append(('%fPIE', ''))
-  config.substitutions.append(('%pie', ''))
+if config.host_os == "Windows":
+    config.substitutions.append(("%fPIC", ""))
+    config.substitutions.append(("%fPIE", ""))
+    config.substitutions.append(("%pie", ""))
 else:
-  config.substitutions.append(('%fPIC', '-fPIC'))
-  config.substitutions.append(('%fPIE', '-fPIE'))
-  config.substitutions.append(('%pie', '-pie'))
+    config.substitutions.append(("%fPIC", "-fPIC"))
+    config.substitutions.append(("%fPIE", "-fPIE"))
+    config.substitutions.append(("%pie", "-pie"))
 
 # Only run the tests on supported OSs.
-if config.host_os not in ['Linux', 'Darwin',]:
-  config.unsupported = True
+if config.host_os not in [
+    "Linux",
+    "Darwin",
+]:
+    config.unsupported = True

``````````

</details>


https://github.com/llvm/llvm-project/pull/76261


More information about the llvm-branch-commits mailing list