[llvm] ca0bb0e - Make sure some types are indeed trivially_copyable per llvm::is_trivially_copyable
via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 24 09:25:15 PST 2021
Author: serge-sans-paille
Date: 2021-02-24T18:24:57+01:00
New Revision: ca0bb0e8875097b9cdc60790438a1118da3911ba
URL: https://github.com/llvm/llvm-project/commit/ca0bb0e8875097b9cdc60790438a1118da3911ba
DIFF: https://github.com/llvm/llvm-project/commit/ca0bb0e8875097b9cdc60790438a1118da3911ba.diff
LOG: 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
Added:
Modified:
llvm/unittests/Support/TypeTraitsTest.cpp
Removed:
################################################################################
diff --git a/llvm/unittests/Support/TypeTraitsTest.cpp b/llvm/unittests/Support/TypeTraitsTest.cpp
index e7a102543e66..15a38b8fb65b 100644
--- a/llvm/unittests/Support/TypeTraitsTest.cpp
+++ b/llvm/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<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
More information about the llvm-commits
mailing list