summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2014-03-02 20:56:28 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2014-03-02 20:56:28 +0000
commit49c8ae21f59608479727cdaafa880e51c5f10e15 (patch)
treee92a422e86a1f7b2f8d3282f9247494451c8ac1c /llvm/unittests/ADT
parentc3084ad29406adfa8c53e56c30345cfb8d631c9d (diff)
downloadbcm5719-llvm-49c8ae21f59608479727cdaafa880e51c5f10e15.tar.gz
bcm5719-llvm-49c8ae21f59608479727cdaafa880e51c5f10e15.zip
Give APInt move semantics.
The interaction between defaulted operators and move elision isn't totally obvious, add a unit test so it doesn't break unintentionally. llvm-svn: 202662
Diffstat (limited to 'llvm/unittests/ADT')
-rw-r--r--llvm/unittests/ADT/APSIntTest.cpp44
-rw-r--r--llvm/unittests/ADT/CMakeLists.txt1
2 files changed, 45 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/APSIntTest.cpp b/llvm/unittests/ADT/APSIntTest.cpp
new file mode 100644
index 00000000000..eef9c8a90af
--- /dev/null
+++ b/llvm/unittests/ADT/APSIntTest.cpp
@@ -0,0 +1,44 @@
+//===- llvm/unittest/ADT/APSIntTest.cpp - APSInt unit tests ---------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/APSInt.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+TEST(APSIntTest, MoveTest) {
+ APSInt A(32, true);
+ EXPECT_TRUE(A.isUnsigned());
+
+ APSInt B(128, false);
+ A = B;
+ EXPECT_FALSE(A.isUnsigned());
+
+ APSInt C(B);
+ EXPECT_FALSE(C.isUnsigned());
+
+ APInt Wide(256, 0);
+ const uint64_t *Bits = Wide.getRawData();
+ APSInt D(std::move(Wide));
+ EXPECT_TRUE(D.isUnsigned());
+ EXPECT_EQ(Bits, D.getRawData()); // Verify that "Wide" was really moved.
+
+ A = APSInt(64, true);
+ EXPECT_TRUE(A.isUnsigned());
+
+ Wide = APInt(128, 1);
+ Bits = Wide.getRawData();
+ A = std::move(Wide);
+ EXPECT_TRUE(A.isUnsigned());
+ EXPECT_EQ(Bits, A.getRawData()); // Verify that "Wide" was really moved.
+}
+
+}
diff --git a/llvm/unittests/ADT/CMakeLists.txt b/llvm/unittests/ADT/CMakeLists.txt
index b7d006ac66d..f26ac02feb2 100644
--- a/llvm/unittests/ADT/CMakeLists.txt
+++ b/llvm/unittests/ADT/CMakeLists.txt
@@ -5,6 +5,7 @@ set(LLVM_LINK_COMPONENTS
set(ADTSources
APFloatTest.cpp
APIntTest.cpp
+ APSIntTest.cpp
ArrayRefTest.cpp
BitVectorTest.cpp
DAGDeltaAlgorithmTest.cpp
OpenPOWER on IntegriCloud