EricWF created this revision.
EricWF added reviewers: mclow.lists, danalbert, jroelofs.
EricWF added a subscriber: cfe-commits.

Currently we use '-nodefaultlibs' when building and running the libc++ tests. 
However we should prefer using '-stdlib=libc++'.
This patch automatically detects when the test suite can use "-stdlib=libc++" 
and prefers it when possible.

We use `-stdlib=libc++` when the following are true:

1. `CXX` is clang or apple clang.
2. 'cxx_abi' is set to 'none'. This means that libc++ handles the ABI library 
dependency on its own.
3. We are using the default unwinder (ie not libunwind).


http://reviews.llvm.org/D13796

Files:
  test/libcxx/compiler.py
  test/libcxx/test/config.py

Index: test/libcxx/test/config.py
===================================================================
--- test/libcxx/test/config.py
+++ test/libcxx/test/config.py
@@ -71,6 +71,7 @@
         self.abi_library_root = None
         self.env = {}
         self.use_target = False
+        self.use_stdlib_eq_libcxx = False
         self.use_system_cxx_lib = False
         self.use_clang_verify = False
         self.long_tests = None
@@ -107,6 +108,7 @@
         self.configure_use_clang_verify()
         self.configure_execute_external()
         self.configure_ccache()
+        self.configure_use_stdlib_eq_libcxx()
         self.configure_compile_flags()
         self.configure_link_flags()
         self.configure_env()
@@ -355,6 +357,19 @@
         if self.cxx.hasCompileFlag('-fsized-deallocation'):
             self.config.available_features.add('fsized-deallocation')
 
+    def configure_use_stdlib_eq_libcxx(self):
+        cxx_abi = self.get_lit_conf('cxx_abi', 'libcxxabi')
+        use_llvm_unwinder = self.get_lit_bool('llvm_unwinder', False)
+        deduced_use_stdlib_eq_libcxx = (self.cxx.isClang() and
+                                        cxx_abi == 'none' and
+                                        not use_llvm_unwinder)
+        self.use_stdlib_eq_libcxx = self.get_lit_bool(
+            'use_stdlib_eq_libcxx', deduced_use_stdlib_eq_libcxx)
+        if self.use_stdlib_eq_libcxx and not deduced_use_stdlib_eq_libcxx:
+            self.lit_config.fatal('--param=use_stdlib_eq_libcxx=true cannot be '
+                'specified in this configuration.')
+
+
     def configure_compile_flags(self):
         no_default_flags = self.get_lit_bool('no_default_flags', False)
         if not no_default_flags:
@@ -496,16 +511,23 @@
     def configure_link_flags(self):
         no_default_flags = self.get_lit_bool('no_default_flags', False)
         if not no_default_flags:
-            self.cxx.link_flags += ['-nodefaultlibs']
+            if not self.use_stdlib_eq_libcxx:
+                self.cxx.link_flags += ['-nodefaultlibs']
 
             # Configure library path
             self.configure_link_flags_cxx_library_path()
             self.configure_link_flags_abi_library_path()
 
-            # Configure libraries
             self.configure_link_flags_cxx_library()
             self.configure_link_flags_abi_library()
-            self.configure_extra_library_flags()
+
+            enable_threads = ('libcpp-has-no-threads' not in
+                               self.config.available_features)
+
+            if not self.use_stdlib_eq_libcxx:
+                self.configure_builtin_libraries(enable_threads)
+            elif enable_threads:
+                self.cxx.link_flags += ['-lpthread']
 
         link_flags_str = self.get_lit_conf('link_flags', '')
         self.cxx.link_flags += shlex.split(link_flags_str)
@@ -538,12 +560,15 @@
 
     def configure_link_flags_cxx_library(self):
         libcxx_library = self.get_lit_conf('libcxx_library')
-        if libcxx_library:
+        if self.use_stdlib_eq_libcxx:
+            self.cxx.link_flags += ['-stdlib=libc++']
+        elif libcxx_library:
             self.cxx.link_flags += [libcxx_library]
         else:
             self.cxx.link_flags += ['-lc++']
 
     def configure_link_flags_abi_library(self):
+
         cxx_abi = self.get_lit_conf('cxx_abi', 'libcxxabi')
         if cxx_abi == 'libstdc++':
             self.cxx.link_flags += ['-lstdc++']
@@ -562,9 +587,8 @@
             self.lit_config.fatal(
                 'C++ ABI setting %s unsupported for tests' % cxx_abi)
 
-    def configure_extra_library_flags(self):
-        enable_threads = ('libcpp-has-no-threads' not in
-                          self.config.available_features)
+    def configure_builtin_libraries(self, enable_threads):
+        assert not self.use_stdlib_eq_libcxx
         llvm_unwinder = self.get_lit_bool('llvm_unwinder', False)
         target_platform = self.target_info.platform()
         if target_platform == 'darwin':
@@ -648,7 +672,8 @@
                                              symbolizer_search_paths)
             # Setup the sanitizer compile flags
             self.cxx.flags += ['-g', '-fno-omit-frame-pointer']
-            if self.target_info.platform() == 'linux':
+            if self.target_info.platform() == 'linux' and \
+               not self.use_stdlib_eq_libcxx:
                 # The libraries and their order are taken from the
                 # linkSanitizerRuntimeDeps function in
                 # clang/lib/Driver/Tools.cpp
@@ -684,7 +709,9 @@
                 self.lit_config.fatal('unsupported value for '
                                       'use_sanitizer: {0}'.format(san))
             san_lib = self.get_lit_conf('sanitizer_library')
-            if san_lib:
+            # FIXME Issues a warning when sanitizer_library is given
+            # when self.use_stdlib_eq_libcxx is ON.
+            if san_lib and not self.use_stdlib_eq_libcxx:
                 self.cxx.link_flags += [
                     san_lib, '-Wl,-rpath,%s' % os.path.dirname(san_lib)]
 
Index: test/libcxx/compiler.py
===================================================================
--- test/libcxx/compiler.py
+++ test/libcxx/compiler.py
@@ -38,6 +38,12 @@
         self.type = compiler_type
         self.version = (major_ver, minor_ver, patchlevel)
 
+    def isClang(self):
+        return self.type == 'clang' or self.type == 'apple-clang'
+
+    def isGCC(self):
+        return self.type == 'gcc'
+
     def _basicCmd(self, source_files, out, is_link=False, input_is_cxx=False):
         cmd = []
         if self.use_ccache and not is_link:
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to