diff --git a/libcxx/include/__config_site.in b/libcxx/include/__config_site.in --- 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 --- /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 + +#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 --- /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 +#include +#include + +extern std::vector 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 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 --- /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 +#include +#include + +extern std::vector 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 registry; + + int main() { + register1(); + register2(); + + assert(registry.size() == 2); + assert(registry[0] == registry[1]); + } +#else +# error +#endif