[PATCH] D96536: Make sure some types are indeed trivially_copyable per llvm::is_trivially_copyable
serge via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 11 12:38:34 PST 2021
serge-sans-paille created this revision.
serge-sans-paille added reviewers: danilaml, strega-nil.
serge-sans-paille requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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.
https://reviews.llvm.org/D96536
Files:
llvm/unittests/Support/TypeTraitsTest.cpp
Index: llvm/unittests/Support/TypeTraitsTest.cpp
===================================================================
--- llvm/unittests/Support/TypeTraitsTest.cpp
+++ 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 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96536.323115.patch
Type: text/x-patch
Size: 1612 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210211/8592f77f/attachment.bin>
More information about the llvm-commits
mailing list