From 4458621d3d604a274eaa7fb84c34a74469e4a020 Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Thu, 11 Feb 2021 21:34:29 +0100 Subject: [PATCH] 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 --- unittests/Support/TypeTraitsTest.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/unittests/Support/TypeTraitsTest.cpp b/unittests/Support/TypeTraitsTest.cpp index e7a102543e6..15a38b8fb65 100644 --- a/unittests/Support/TypeTraitsTest.cpp +++ b/unittests/Support/TypeTraitsTest.cpp @@ -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(); } +// 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, false, false>(); + TrivialityTester, false, false>(); + + TrivialityTester, false, false>(); + TrivialityTester, true, true>(); + TrivialityTester, false, false>(); + TrivialityTester(); + TrivialityTester, true, true>(); + TrivialityTester, true, true>(); + TrivialityTester, true, true>(); +} + } // namespace triviality } // end anonymous namespace