summaryrefslogtreecommitdiff
path: root/absl/base/optimization_test.cc
diff options
context:
space:
mode:
authorGravatar Evan Brown <ezb@google.com>2022-07-27 13:45:19 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2022-07-27 13:46:14 -0700
commitc7e60ccfcd708a73008ed2df040162c66697bc18 (patch)
tree904eb83861d0174d48ee11b5637c8919be623d40 /absl/base/optimization_test.cc
parent51f6d868c8463ac13492d504cbc034e91b43a461 (diff)
Add ABSL_IS_TRIVIALLY_RELOCATABLE and ABSL_ATTRIBUTE_TRIVIAL_ABI macros for use with clang's __is_trivially_relocatable and [[clang::trivial_abi]].
PiperOrigin-RevId: 463668740 Change-Id: I2d2d2f53d8184a7e4f7c848c2a5f5140c2481d72
Diffstat (limited to 'absl/base/optimization_test.cc')
-rw-r--r--absl/base/optimization_test.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/absl/base/optimization_test.cc b/absl/base/optimization_test.cc
index e83369f3..5f7a8f4c 100644
--- a/absl/base/optimization_test.cc
+++ b/absl/base/optimization_test.cc
@@ -15,6 +15,7 @@
#include "absl/base/optimization.h"
#include "gtest/gtest.h"
+#include "absl/base/attributes.h"
#include "absl/types/optional.h"
namespace {
@@ -126,4 +127,22 @@ TEST(PredictTest, ExplicitBoolConversion) {
if (ABSL_PREDICT_FALSE(is_false)) ADD_FAILURE();
}
+TEST(TrivallyRelocatable, Sanity) {
+#if !defined(ABSL_HAVE_ATTRIBUTE_TRIVIAL_ABI) || \
+ !ABSL_HAVE_BUILTIN(__is_trivially_relocatable)
+ GTEST_SKIP() << "No trivial ABI support.";
+#endif
+
+ struct Trivial {};
+ struct NonTrivial {
+ NonTrivial(const NonTrivial&) {}
+ };
+ struct ABSL_ATTRIBUTE_TRIVIAL_ABI TrivialAbi {
+ TrivialAbi(const TrivialAbi&) {}
+ };
+ EXPECT_TRUE(ABSL_IS_TRIVIALLY_RELOCATABLE(Trivial));
+ EXPECT_FALSE(ABSL_IS_TRIVIALLY_RELOCATABLE(NonTrivial));
+ EXPECT_TRUE(ABSL_IS_TRIVIALLY_RELOCATABLE(TrivialAbi));
+}
+
} // namespace