llvm.org GIT mirror llvm / 3efb8b2
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@202662 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 6 years ago
3 changed file(s) with 50 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
2929 explicit APSInt(uint32_t BitWidth, bool isUnsigned = true)
3030 : APInt(BitWidth, 0), IsUnsigned(isUnsigned) {}
3131
32 explicit APSInt(const APInt &I, bool isUnsigned = true)
33 : APInt(I), IsUnsigned(isUnsigned) {}
34
35 APSInt &operator=(const APSInt &RHS) {
36 APInt::operator=(RHS);
37 IsUnsigned = RHS.IsUnsigned;
38 return *this;
39 }
40
41 APSInt &operator=(const APInt &RHS) {
32 explicit APSInt(APInt I, bool isUnsigned = true)
33 : APInt(std::move(I)), IsUnsigned(isUnsigned) {}
34
35 APSInt &operator=(APInt RHS) {
4236 // Retain our current sign.
43 APInt::operator=(RHS);
37 APInt::operator=(std::move(RHS));
4438 return *this;
4539 }
4640
0 //===- llvm/unittest/ADT/APSIntTest.cpp - APSInt unit tests ---------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/ADT/APSInt.h"
10 #include "gtest/gtest.h"
11
12 using namespace llvm;
13
14 namespace {
15
16 TEST(APSIntTest, MoveTest) {
17 APSInt A(32, true);
18 EXPECT_TRUE(A.isUnsigned());
19
20 APSInt B(128, false);
21 A = B;
22 EXPECT_FALSE(A.isUnsigned());
23
24 APSInt C(B);
25 EXPECT_FALSE(C.isUnsigned());
26
27 APInt Wide(256, 0);
28 const uint64_t *Bits = Wide.getRawData();
29 APSInt D(std::move(Wide));
30 EXPECT_TRUE(D.isUnsigned());
31 EXPECT_EQ(Bits, D.getRawData()); // Verify that "Wide" was really moved.
32
33 A = APSInt(64, true);
34 EXPECT_TRUE(A.isUnsigned());
35
36 Wide = APInt(128, 1);
37 Bits = Wide.getRawData();
38 A = std::move(Wide);
39 EXPECT_TRUE(A.isUnsigned());
40 EXPECT_EQ(Bits, A.getRawData()); // Verify that "Wide" was really moved.
41 }
42
43 }
44 set(ADTSources
55 APFloatTest.cpp
66 APIntTest.cpp
7 APSIntTest.cpp
78 ArrayRefTest.cpp
89 BitVectorTest.cpp
910 DAGDeltaAlgorithmTest.cpp