1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

Make sure some types are indeed trivially_copyable per llvm::is_trivially_copyable

Test a few types used as llvm::SmallVector parameter. It is important to ensure
we have a consistent behavior for these types to prevent ABI issues as the one
we met in https://bugs.llvm.org/show_bug.cgi?id=39427.

Differential Revision: https://reviews.llvm.org/D96536
This commit is contained in:
serge-sans-paille 2021-02-11 21:34:29 +01:00
parent 01ce9f6d68
commit 4458621d3d

View File

@ -6,6 +6,12 @@
//
//===----------------------------------------------------------------------===//
#include "llvm/ADT/FunctionExtras.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/type_traits.h"
#include "gtest/gtest.h"
@ -92,6 +98,26 @@ TEST(Triviality, Tester) {
TrivialityTester<B &&, false, true>();
}
// Test that the following ADT behave as expected wrt. trivially copyable trait
//
// NB: It is important that this trait behaves the same for (at least) these
// types for all supported compilers to prevent ABI issue when llvm is compiled
// with compiler A and an other project using llvm is compiled with compiler B.
TEST(Triviality, ADT) {
TrivialityTester<llvm::SmallVector<int>, false, false>();
TrivialityTester<llvm::SmallString<8>, false, false>();
TrivialityTester<std::function<int()>, false, false>();
TrivialityTester<std::pair<int, bool>, true, true>();
TrivialityTester<llvm::unique_function<int()>, false, false>();
TrivialityTester<llvm::StringRef, true, true>();
TrivialityTester<llvm::ArrayRef<int>, true, true>();
TrivialityTester<llvm::PointerIntPair<int *, 2>, true, true>();
TrivialityTester<llvm::Optional<int>, true, true>();
}
} // namespace triviality
} // end anonymous namespace