[libcxx-commits] [libcxx] 31d41e3 - [libc++] Add tests for _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu May 7 09:40:26 PDT 2020


Author: Louis Dionne
Date: 2020-05-07T12:40:02-04:00
New Revision: 31d41e38794f3e8e8859ccaabcc1f8d0c40a7a10

URL: https://github.com/llvm/llvm-project/commit/31d41e38794f3e8e8859ccaabcc1f8d0c40a7a10
DIFF: https://github.com/llvm/llvm-project/commit/31d41e38794f3e8e8859ccaabcc1f8d0c40a7a10.diff

LOG: [libc++] Add tests for _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT

The issue on Apple platforms was fixed in 2464d8135e2a, but this commit
adds some tests to make sure we don't regress.

See https://llvm.org/PR45549.

Differential Revision: https://reviews.llvm.org/D78963

Added: 
    libcxx/test/libcxx/language.support/support.rtti/type.info/type_info.comparison.apple.compile.pass.cpp
    libcxx/test/libcxx/language.support/support.rtti/type.info/type_info.comparison.merged.sh.cpp
    libcxx/test/libcxx/language.support/support.rtti/type.info/type_info.comparison.unmerged.sh.cpp

Modified: 
    libcxx/include/__config_site.in

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__config_site.in b/libcxx/include/__config_site.in
index 1ccc158c631e..4da11a9e6744 100644
--- a/libcxx/include/__config_site.in
+++ b/libcxx/include/__config_site.in
@@ -27,7 +27,9 @@
 #cmakedefine _LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL
 #cmakedefine _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
 #cmakedefine _LIBCPP_NO_VCRUNTIME
+#ifndef _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT
 #cmakedefine01 _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT
+#endif
 #cmakedefine _LIBCPP_ABI_NAMESPACE @_LIBCPP_ABI_NAMESPACE@
 #cmakedefine _LIBCPP_HAS_PARALLEL_ALGORITHMS
 

diff  --git a/libcxx/test/libcxx/language.support/support.rtti/type.info/type_info.comparison.apple.compile.pass.cpp b/libcxx/test/libcxx/language.support/support.rtti/type.info/type_info.comparison.apple.compile.pass.cpp
new file mode 100644
index 000000000000..d6fd0fba31d3
--- /dev/null
+++ b/libcxx/test/libcxx/language.support/support.rtti/type.info/type_info.comparison.apple.compile.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// This test makes sure that we do assume that type_infos are unique across
+// all translation units on Apple platforms. See https://llvm.org/PR45549.
+
+// TODO:
+// We don't really want to require 'darwin' here -- instead we'd like to express
+// that this test requires the flavor of libc++ built by Apple, which we don't
+// have a clear way to express right now. If another flavor of libc++ was built
+// targetting Apple platforms without assuming merged RTTI, this test would fail.
+// REQUIRES: darwin
+
+#include <typeinfo>
+
+#if !defined(_LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT)
+#   error "_LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT should be defined on Apple platforms"
+#endif
+
+#if _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT != 1
+#   error "_LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT should be 1 (assume RTTI is merged) on Apple platforms"
+#endif

diff  --git a/libcxx/test/libcxx/language.support/support.rtti/type.info/type_info.comparison.merged.sh.cpp b/libcxx/test/libcxx/language.support/support.rtti/type.info/type_info.comparison.merged.sh.cpp
new file mode 100644
index 000000000000..5e70be87d31e
--- /dev/null
+++ b/libcxx/test/libcxx/language.support/support.rtti/type.info/type_info.comparison.merged.sh.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: -fno-rtti
+
+// FILE_DEPENDENCIES: %t.exe
+// RUN: %{cxx} %s %{flags} %{compile_flags} -c -o %t.tu1.o -DTU1 -D_LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT=1
+// RUN: %{cxx} %s %{flags} %{compile_flags} -c -o %t.tu2.o -DTU2 -D_LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT=1
+// RUN: %{cxx} %s %{flags} %{compile_flags} -c -o %t.main.o -DMAIN -D_LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT=1
+// RUN: %{cxx} %t.tu1.o %t.tu2.o %t.main.o %{flags} %{link_flags} -o %t.exe
+// RUN: %{exec} %t.exe
+
+#include <cassert>
+#include <typeindex>
+#include <vector>
+
+extern std::vector<std::type_index> registry;
+
+void register1();
+void register2();
+
+#if defined(TU1)
+  namespace { struct A { bool x; }; }
+  void register1() { registry.emplace_back(std::type_index{typeid(A)}); }
+#elif defined(TU2)
+  namespace { struct A { int x, y; }; }
+  void register2() { registry.emplace_back(std::type_index{typeid(A)}); }
+#elif defined(MAIN)
+  std::vector<std::type_index> registry;
+
+  int main() {
+    register1();
+    register2();
+
+    assert(registry.size() == 2);
+    assert(registry[0] != registry[1]);
+  }
+#else
+# error
+#endif

diff  --git a/libcxx/test/libcxx/language.support/support.rtti/type.info/type_info.comparison.unmerged.sh.cpp b/libcxx/test/libcxx/language.support/support.rtti/type.info/type_info.comparison.unmerged.sh.cpp
new file mode 100644
index 000000000000..b9de801e9b49
--- /dev/null
+++ b/libcxx/test/libcxx/language.support/support.rtti/type.info/type_info.comparison.unmerged.sh.cpp
@@ -0,0 +1,45 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: -fno-rtti
+
+// FILE_DEPENDENCIES: %t.exe
+// RUN: %{cxx} %s %{flags} %{compile_flags} -c -o %t.tu1.o -DTU1 -D_LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT=0
+// RUN: %{cxx} %s %{flags} %{compile_flags} -c -o %t.tu2.o -DTU2 -D_LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT=0
+// RUN: %{cxx} %s %{flags} %{compile_flags} -c -o %t.main.o -DMAIN -D_LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT=0
+// RUN: %{cxx} %t.tu1.o %t.tu2.o %t.main.o %{flags} %{link_flags} -o %t.exe
+// RUN: %{exec} %t.exe
+
+#include <cassert>
+#include <typeindex>
+#include <vector>
+
+extern std::vector<std::type_index> registry;
+
+void register1();
+void register2();
+
+#if defined(TU1)
+  namespace { struct A { bool x; }; }
+  void register1() { registry.emplace_back(std::type_index{typeid(A)}); }
+#elif defined(TU2)
+  namespace { struct A { int x, y; }; }
+  void register2() { registry.emplace_back(std::type_index{typeid(A)}); }
+#elif defined(MAIN)
+  std::vector<std::type_index> registry;
+
+  int main() {
+    register1();
+    register2();
+
+    assert(registry.size() == 2);
+    assert(registry[0] == registry[1]);
+  }
+#else
+# error
+#endif


        


More information about the libcxx-commits mailing list