Author: Jonas Devlieghere Date: 2021-02-04T08:52:56-08:00 New Revision: 727bd89b605b39659c793f338ce1e18dafc3581e
URL: https://github.com/llvm/llvm-project/commit/727bd89b605b39659c793f338ce1e18dafc3581e DIFF: https://github.com/llvm/llvm-project/commit/727bd89b605b39659c793f338ce1e18dafc3581e.diff LOG: [lldb] Simplify the logic to detect compiler flag support This patch effectively does the following 3 things: - Centralize the logic to figure out if a compiler flag is supported. - Stop sanity checking whether the compiler works at all. While useful, that's not the decorator's responsibility. - Invoke the compiler with xcrun on Darwin so we know where to find the sysroot. On my macOS Big Sur system, the clang invocation couldn't find libSystem and would fail the sanity check in the decorator. This meant that the test suite would always try to run the ASan/UBSan/TSan tests, regardless of whether compiler-rt was built. Differential revision: https://reviews.llvm.org/D95995 Added: Modified: lldb/packages/Python/lldbsuite/test/decorators.py Removed: ################################################################################ diff --git a/lldb/packages/Python/lldbsuite/test/decorators.py b/lldb/packages/Python/lldbsuite/test/decorators.py index ff445fa0b926..6d781defdea4 100644 --- a/lldb/packages/Python/lldbsuite/test/decorators.py +++ b/lldb/packages/Python/lldbsuite/test/decorators.py @@ -86,6 +86,20 @@ def _match_decorator_property(expected, actual): else: return expected == actual + +def _compiler_supports(compiler, flag): + """Test whether the compiler supports the given flag.""" + if platform.system() == 'Darwin': + compiler = "xcrun " + compiler + f = tempfile.NamedTemporaryFile() + try: + cmd = "echo 'int main() {}' | %s %s -x c -o %s -" % (compiler, flag, f.name) + subprocess.check_call(cmd, shell=True) + except subprocess.CalledProcessError: + return False + return True + + def expectedFailure(func): return unittest2.expectedFailure(func) @@ -729,12 +743,7 @@ def is_compiler_clang_with_thread_sanitizer(self): # rdar://28659145 - TSAN tests don't look like they're supported on i386 if self.getArchitecture() == 'i386' and platform.system() == 'Darwin': return "TSAN tests not compatible with i386 targets" - f = tempfile.NamedTemporaryFile() - cmd = "echo 'int main() {}' | %s -x c -o %s -" % (compiler_path, f.name) - if os.popen(cmd).close() is not None: - return None # The compiler cannot compile at all, let's *not* skip the test - cmd = "echo 'int main() {}' | %s -fsanitize=thread -x c -o %s -" % (compiler_path, f.name) - if os.popen(cmd).close() is not None: + if not _compiler_supports(compiler_path, '-fsanitize=thread'): return "Compiler cannot compile with -fsanitize=thread" return None return skipTestIfFn(is_compiler_clang_with_thread_sanitizer)(func) @@ -755,8 +764,7 @@ def is_compiler_clang_with_ubsan(self): outputf = tempfile.NamedTemporaryFile() # Try to compile with ubsan turned on. - cmd = '%s -fsanitize=undefined %s -o %s' % (self.getCompiler(), inputf.name, outputf.name) - if os.popen(cmd).close() is not None: + if not _compiler_supports(self.getCompiler(), '-fsanitize=undefined'): return "Compiler cannot compile with -fsanitize=undefined" # Check that we actually see ubsan instrumentation in the binary. @@ -804,16 +812,9 @@ def is_compiler_with_address_sanitizer(self): if is_running_under_asan(): return "Address sanitizer tests are disabled when runing under ASAN" - compiler_path = self.getCompiler() - compiler = os.path.basename(compiler_path) - f = tempfile.NamedTemporaryFile() if lldbplatformutil.getPlatform() == 'windows': return "ASAN tests not compatible with 'windows'" - cmd = "echo 'int main() {}' | %s -x c -o %s -" % (compiler_path, f.name) - if os.popen(cmd).close() is not None: - return None # The compiler cannot compile at all, let's *not* skip the test - cmd = "echo 'int main() {}' | %s -fsanitize=address -x c -o %s -" % (compiler_path, f.name) - if os.popen(cmd).close() is not None: + if not _compiler_supports(self.getCompiler(), '-fsanitize=address'): return "Compiler cannot compile with -fsanitize=address" return None return skipTestIfFn(is_compiler_with_address_sanitizer)(func) _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits