diff options
author | dim <dim@FreeBSD.org> | 2011-10-20 21:10:27 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2011-10-20 21:10:27 +0000 |
commit | 7b3392326c40c3c20697816acae597ba7b3144eb (patch) | |
tree | 2cbcf22585e99f8a87d12d5ff94f392c0d266819 /unittests | |
parent | 1176aa52646fe641a4243a246aa7f960c708a274 (diff) | |
download | FreeBSD-src-7b3392326c40c3c20697816acae597ba7b3144eb.zip FreeBSD-src-7b3392326c40c3c20697816acae597ba7b3144eb.tar.gz |
Vendor import of llvm release_30 branch r142614:
http://llvm.org/svn/llvm-project/llvm/branches/release_30@142614
Diffstat (limited to 'unittests')
21 files changed, 800 insertions, 89 deletions
diff --git a/unittests/ADT/APFloatTest.cpp b/unittests/ADT/APFloatTest.cpp index 08ac2a0..b6e02e3 100644 --- a/unittests/ADT/APFloatTest.cpp +++ b/unittests/ADT/APFloatTest.cpp @@ -34,11 +34,13 @@ static std::string convertToString(double d, unsigned Prec, unsigned Pad) { namespace { TEST(APFloatTest, Zero) { - EXPECT_EQ(0.0f, APFloat(APFloat::IEEEsingle, 0.0f).convertToFloat()); - EXPECT_EQ(-0.0f, APFloat(APFloat::IEEEsingle, -0.0f).convertToFloat()); + EXPECT_EQ(0.0f, APFloat(0.0f).convertToFloat()); + EXPECT_EQ(-0.0f, APFloat(-0.0f).convertToFloat()); + EXPECT_TRUE(APFloat(-0.0f).isNegative()); - EXPECT_EQ(0.0, APFloat(APFloat::IEEEdouble, 0.0).convertToDouble()); - EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, -0.0).convertToDouble()); + EXPECT_EQ(0.0, APFloat(0.0).convertToDouble()); + EXPECT_EQ(-0.0, APFloat(-0.0).convertToDouble()); + EXPECT_TRUE(APFloat(-0.0).isNegative()); } TEST(APFloatTest, fromZeroDecimalString) { @@ -646,4 +648,9 @@ TEST(APFloatTest, exactInverse) { EXPECT_FALSE(APFloat(1.40129846e-45f).getExactInverse(0)); } +TEST(APFloatTest, getLargest) { + EXPECT_EQ(3.402823466e+38f, APFloat::getLargest(APFloat::IEEEsingle).convertToFloat()); + EXPECT_EQ(1.7976931348623158e+308, APFloat::getLargest(APFloat::IEEEdouble).convertToDouble()); +} + } diff --git a/unittests/ADT/APIntTest.cpp b/unittests/ADT/APIntTest.cpp index 1f78cd3..490811d 100644 --- a/unittests/ADT/APIntTest.cpp +++ b/unittests/ADT/APIntTest.cpp @@ -237,6 +237,24 @@ TEST(APIntTest, fromString) { EXPECT_EQ(APInt(32, uint64_t(-16LL)), APInt(32, "-10", 16)); EXPECT_EQ(APInt(32, uint64_t(-31LL)), APInt(32, "-1F", 16)); EXPECT_EQ(APInt(32, uint64_t(-32LL)), APInt(32, "-20", 16)); + + EXPECT_EQ(APInt(32, 0), APInt(32, "0", 36)); + EXPECT_EQ(APInt(32, 1), APInt(32, "1", 36)); + EXPECT_EQ(APInt(32, 35), APInt(32, "Z", 36)); + EXPECT_EQ(APInt(32, 36), APInt(32, "10", 36)); + EXPECT_EQ(APInt(32, 71), APInt(32, "1Z", 36)); + EXPECT_EQ(APInt(32, 72), APInt(32, "20", 36)); + + EXPECT_EQ(APInt(32, uint64_t(-0LL)), APInt(32, "-0", 36)); + EXPECT_EQ(APInt(32, uint64_t(-1LL)), APInt(32, "-1", 36)); + EXPECT_EQ(APInt(32, uint64_t(-35LL)), APInt(32, "-Z", 36)); + EXPECT_EQ(APInt(32, uint64_t(-36LL)), APInt(32, "-10", 36)); + EXPECT_EQ(APInt(32, uint64_t(-71LL)), APInt(32, "-1Z", 36)); + EXPECT_EQ(APInt(32, uint64_t(-72LL)), APInt(32, "-20", 36)); +} + +TEST(APIntTest, FromArray) { + EXPECT_EQ(APInt(32, uint64_t(1)), APInt(32, ArrayRef<uint64_t>(1))); } TEST(APIntTest, StringBitsNeeded2) { @@ -336,6 +354,9 @@ TEST(APIntTest, toString) { APInt(8, 0).toString(S, 16, true, true); EXPECT_EQ(S.str().str(), "0x0"); S.clear(); + APInt(8, 0).toString(S, 36, true, true); + EXPECT_EQ(S.str().str(), "0"); + S.clear(); isSigned = false; APInt(8, 255, isSigned).toString(S, 2, isSigned, true); @@ -350,6 +371,9 @@ TEST(APIntTest, toString) { APInt(8, 255, isSigned).toString(S, 16, isSigned, true); EXPECT_EQ(S.str().str(), "0xFF"); S.clear(); + APInt(8, 255, isSigned).toString(S, 36, isSigned, true); + EXPECT_EQ(S.str().str(), "73"); + S.clear(); isSigned = true; APInt(8, 255, isSigned).toString(S, 2, isSigned, true); @@ -364,6 +388,9 @@ TEST(APIntTest, toString) { APInt(8, 255, isSigned).toString(S, 16, isSigned, true); EXPECT_EQ(S.str().str(), "-0x1"); S.clear(); + APInt(8, 255, isSigned).toString(S, 36, isSigned, true); + EXPECT_EQ(S.str().str(), "-1"); + S.clear(); } TEST(APIntTest, Log2) { @@ -403,7 +430,7 @@ TEST(APIntTest, magicu) { TEST(APIntTest, StringDeath) { EXPECT_DEATH(APInt(0, "", 0), "Bitwidth too small"); EXPECT_DEATH(APInt(32, "", 0), "Invalid string length"); - EXPECT_DEATH(APInt(32, "0", 0), "Radix should be 2, 8, 10, or 16!"); + EXPECT_DEATH(APInt(32, "0", 0), "Radix should be 2, 8, 10, 16, or 36!"); EXPECT_DEATH(APInt(32, "", 10), "Invalid string length"); EXPECT_DEATH(APInt(32, "-", 10), "String is only a sign, needs a value."); EXPECT_DEATH(APInt(1, "1234", 10), "Insufficient bit width"); @@ -414,4 +441,13 @@ TEST(APIntTest, StringDeath) { #endif #endif +TEST(APIntTest, mul_clear) { + APInt ValA(65, -1ULL); + APInt ValB(65, 4); + APInt ValC(65, 0); + ValC = ValA * ValB; + ValA *= ValB; + EXPECT_EQ(ValA.toString(10, false), ValC.toString(10, false)); +} + } diff --git a/unittests/ADT/DAGDeltaAlgorithmTest.cpp b/unittests/ADT/DAGDeltaAlgorithmTest.cpp index b90e0c7..370b7c2 100644 --- a/unittests/ADT/DAGDeltaAlgorithmTest.cpp +++ b/unittests/ADT/DAGDeltaAlgorithmTest.cpp @@ -13,23 +13,6 @@ #include <cstdarg> using namespace llvm; -namespace std { - -static std::ostream &operator<<(std::ostream &OS, - const std::set<unsigned> &S) { - OS << "{"; - for (std::set<unsigned>::const_iterator it = S.begin(), - ie = S.end(); it != ie; ++it) { - if (it != S.begin()) - OS << ","; - OS << *it; - } - OS << "}"; - return OS; -} - -} - namespace { typedef DAGDeltaAlgorithm::edge_ty edge_ty; diff --git a/unittests/ADT/SCCIteratorTest.cpp b/unittests/ADT/SCCIteratorTest.cpp new file mode 100644 index 0000000..00fa066 --- /dev/null +++ b/unittests/ADT/SCCIteratorTest.cpp @@ -0,0 +1,346 @@ +//===----- llvm/unittest/ADT/SCCIteratorTest.cpp - SCCIterator tests ------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <limits.h> +#include "llvm/ADT/GraphTraits.h" +#include "llvm/ADT/SCCIterator.h" +#include "gtest/gtest.h" + +using namespace llvm; + +namespace llvm { + +/// Graph<N> - A graph with N nodes. Note that N can be at most 8. +template <unsigned N> +class Graph { +private: + // Disable copying. + Graph(const Graph&); + Graph& operator=(const Graph&); + + static void ValidateIndex(unsigned Idx) { + assert(Idx < N && "Invalid node index!"); + } +public: + + /// NodeSubset - A subset of the graph's nodes. + class NodeSubset { + typedef unsigned char BitVector; // Where the limitation N <= 8 comes from. + BitVector Elements; + NodeSubset(BitVector e) : Elements(e) {} + public: + /// NodeSubset - Default constructor, creates an empty subset. + NodeSubset() : Elements(0) { + assert(N <= sizeof(BitVector)*CHAR_BIT && "Graph too big!"); + } + /// NodeSubset - Copy constructor. + NodeSubset(const NodeSubset &other) : Elements(other.Elements) {} + + /// Comparison operators. + bool operator==(const NodeSubset &other) const { + return other.Elements == this->Elements; + } + bool operator!=(const NodeSubset &other) const { + return !(*this == other); + } + + /// AddNode - Add the node with the given index to the subset. + void AddNode(unsigned Idx) { + ValidateIndex(Idx); + Elements |= 1U << Idx; + } + + /// DeleteNode - Remove the node with the given index from the subset. + void DeleteNode(unsigned Idx) { + ValidateIndex(Idx); + Elements &= ~(1U << Idx); + } + + /// count - Return true if the node with the given index is in the subset. + bool count(unsigned Idx) { + ValidateIndex(Idx); + return (Elements & (1U << Idx)) != 0; + } + + /// isEmpty - Return true if this is the empty set. + bool isEmpty() const { + return Elements == 0; + } + + /// isSubsetOf - Return true if this set is a subset of the given one. + bool isSubsetOf(const NodeSubset &other) const { + return (this->Elements | other.Elements) == other.Elements; + } + + /// Complement - Return the complement of this subset. + NodeSubset Complement() const { + return ~(unsigned)this->Elements & ((1U << N) - 1); + } + + /// Join - Return the union of this subset and the given one. + NodeSubset Join(const NodeSubset &other) const { + return this->Elements | other.Elements; + } + + /// Meet - Return the intersection of this subset and the given one. + NodeSubset Meet(const NodeSubset &other) const { + return this->Elements & other.Elements; + } + }; + + /// NodeType - Node index and set of children of the node. + typedef std::pair<unsigned, NodeSubset> NodeType; + +private: + /// Nodes - The list of nodes for this graph. + NodeType Nodes[N]; +public: + + /// Graph - Default constructor. Creates an empty graph. + Graph() { + // Let each node know which node it is. This allows us to find the start of + // the Nodes array given a pointer to any element of it. + for (unsigned i = 0; i != N; ++i) + Nodes[i].first = i; + } + + /// AddEdge - Add an edge from the node with index FromIdx to the node with + /// index ToIdx. + void AddEdge(unsigned FromIdx, unsigned ToIdx) { + ValidateIndex(FromIdx); + Nodes[FromIdx].second.AddNode(ToIdx); + } + + /// DeleteEdge - Remove the edge (if any) from the node with index FromIdx to + /// the node with index ToIdx. + void DeleteEdge(unsigned FromIdx, unsigned ToIdx) { + ValidateIndex(FromIdx); + Nodes[FromIdx].second.DeleteNode(ToIdx); + } + + /// AccessNode - Get a pointer to the node with the given index. + NodeType *AccessNode(unsigned Idx) const { + ValidateIndex(Idx); + // The constant cast is needed when working with GraphTraits, which insists + // on taking a constant Graph. + return const_cast<NodeType *>(&Nodes[Idx]); + } + + /// NodesReachableFrom - Return the set of all nodes reachable from the given + /// node. + NodeSubset NodesReachableFrom(unsigned Idx) const { + // This algorithm doesn't scale, but that doesn't matter given the small + // size of our graphs. + NodeSubset Reachable; + + // The initial node is reachable. + Reachable.AddNode(Idx); + do { + NodeSubset Previous(Reachable); + + // Add in all nodes which are children of a reachable node. + for (unsigned i = 0; i != N; ++i) + if (Previous.count(i)) + Reachable = Reachable.Join(Nodes[i].second); + + // If nothing changed then we have found all reachable nodes. + if (Reachable == Previous) + return Reachable; + + // Rinse and repeat. + } while (1); + } + + /// ChildIterator - Visit all children of a node. + class ChildIterator { + friend class Graph; + + /// FirstNode - Pointer to first node in the graph's Nodes array. + NodeType *FirstNode; + /// Children - Set of nodes which are children of this one and that haven't + /// yet been visited. + NodeSubset Children; + + ChildIterator(); // Disable default constructor. + protected: + ChildIterator(NodeType *F, NodeSubset C) : FirstNode(F), Children(C) {} + + public: + /// ChildIterator - Copy constructor. + ChildIterator(const ChildIterator& other) : FirstNode(other.FirstNode), + Children(other.Children) {} + + /// Comparison operators. + bool operator==(const ChildIterator &other) const { + return other.FirstNode == this->FirstNode && + other.Children == this->Children; + } + bool operator!=(const ChildIterator &other) const { + return !(*this == other); + } + + /// Prefix increment operator. + ChildIterator& operator++() { + // Find the next unvisited child node. + for (unsigned i = 0; i != N; ++i) + if (Children.count(i)) { + // Remove that child - it has been visited. This is the increment! + Children.DeleteNode(i); + return *this; + } + assert(false && "Incrementing end iterator!"); + return *this; // Avoid compiler warnings. + } + + /// Postfix increment operator. + ChildIterator operator++(int) { + ChildIterator Result(*this); + ++(*this); + return Result; + } + + /// Dereference operator. + NodeType *operator*() { + // Find the next unvisited child node. + for (unsigned i = 0; i != N; ++i) + if (Children.count(i)) + // Return a pointer to it. + return FirstNode + i; + assert(false && "Dereferencing end iterator!"); + return 0; // Avoid compiler warning. + } + }; + + /// child_begin - Return an iterator pointing to the first child of the given + /// node. + static ChildIterator child_begin(NodeType *Parent) { + return ChildIterator(Parent - Parent->first, Parent->second); + } + + /// child_end - Return the end iterator for children of the given node. + static ChildIterator child_end(NodeType *Parent) { + return ChildIterator(Parent - Parent->first, NodeSubset()); + } +}; + +template <unsigned N> +struct GraphTraits<Graph<N> > { + typedef typename Graph<N>::NodeType NodeType; + typedef typename Graph<N>::ChildIterator ChildIteratorType; + + static inline NodeType *getEntryNode(const Graph<N> &G) { return G.AccessNode(0); } + static inline ChildIteratorType child_begin(NodeType *Node) { + return Graph<N>::child_begin(Node); + } + static inline ChildIteratorType child_end(NodeType *Node) { + return Graph<N>::child_end(Node); + } +}; + +TEST(SCCIteratorTest, AllSmallGraphs) { + // Test SCC computation against every graph with NUM_NODES nodes or less. + // Since SCC considers every node to have an implicit self-edge, we only + // create graphs for which every node has a self-edge. +#define NUM_NODES 4 +#define NUM_GRAPHS (NUM_NODES * (NUM_NODES - 1)) + typedef Graph<NUM_NODES> GT; + + /// Enumerate all graphs using NUM_GRAPHS bits. + assert(NUM_GRAPHS < sizeof(unsigned) * CHAR_BIT && "Too many graphs!"); + for (unsigned GraphDescriptor = 0; GraphDescriptor < (1U << NUM_GRAPHS); + ++GraphDescriptor) { + GT G; + + // Add edges as specified by the descriptor. + unsigned DescriptorCopy = GraphDescriptor; + for (unsigned i = 0; i != NUM_NODES; ++i) + for (unsigned j = 0; j != NUM_NODES; ++j) { + // Always add a self-edge. + if (i == j) { + G.AddEdge(i, j); + continue; + } + if (DescriptorCopy & 1) + G.AddEdge(i, j); + DescriptorCopy >>= 1; + } + + // Test the SCC logic on this graph. + + /// NodesInSomeSCC - Those nodes which are in some SCC. + GT::NodeSubset NodesInSomeSCC; + + for (scc_iterator<GT> I = scc_begin(G), E = scc_end(G); I != E; ++I) { + std::vector<GT::NodeType*> &SCC = *I; + + // Get the nodes in this SCC as a NodeSubset rather than a vector. + GT::NodeSubset NodesInThisSCC; + for (unsigned i = 0, e = SCC.size(); i != e; ++i) + NodesInThisSCC.AddNode(SCC[i]->first); + + // There should be at least one node in every SCC. + EXPECT_FALSE(NodesInThisSCC.isEmpty()); + + // Check that every node in the SCC is reachable from every other node in + // the SCC. + for (unsigned i = 0; i != NUM_NODES; ++i) + if (NodesInThisSCC.count(i)) + EXPECT_TRUE(NodesInThisSCC.isSubsetOf(G.NodesReachableFrom(i))); + + // OK, now that we now that every node in the SCC is reachable from every + // other, this means that the set of nodes reachable from any node in the + // SCC is the same as the set of nodes reachable from every node in the + // SCC. Check that for every node N not in the SCC but reachable from the + // SCC, no element of the SCC is reachable from N. + for (unsigned i = 0; i != NUM_NODES; ++i) + if (NodesInThisSCC.count(i)) { + GT::NodeSubset NodesReachableFromSCC = G.NodesReachableFrom(i); + GT::NodeSubset ReachableButNotInSCC = + NodesReachableFromSCC.Meet(NodesInThisSCC.Complement()); + + for (unsigned j = 0; j != NUM_NODES; ++j) + if (ReachableButNotInSCC.count(j)) + EXPECT_TRUE(G.NodesReachableFrom(j).Meet(NodesInThisSCC).isEmpty()); + + // The result must be the same for all other nodes in this SCC, so + // there is no point in checking them. + break; + } + + // This is indeed a SCC: a maximal set of nodes for which each node is + // reachable from every other. + + // Check that we didn't already see this SCC. + EXPECT_TRUE(NodesInSomeSCC.Meet(NodesInThisSCC).isEmpty()); + + NodesInSomeSCC = NodesInSomeSCC.Join(NodesInThisSCC); + + // Check a property that is specific to the LLVM SCC iterator and + // guaranteed by it: if a node in SCC S1 has an edge to a node in + // SCC S2, then S1 is visited *after* S2. This means that the set + // of nodes reachable from this SCC must be contained either in the + // union of this SCC and all previously visited SCC's. + + for (unsigned i = 0; i != NUM_NODES; ++i) + if (NodesInThisSCC.count(i)) { + GT::NodeSubset NodesReachableFromSCC = G.NodesReachableFrom(i); + EXPECT_TRUE(NodesReachableFromSCC.isSubsetOf(NodesInSomeSCC)); + // The result must be the same for all other nodes in this SCC, so + // there is no point in checking them. + break; + } + } + + // Finally, check that the nodes in some SCC are exactly those that are + // reachable from the initial node. + EXPECT_EQ(NodesInSomeSCC, G.NodesReachableFrom(0)); + } +} + +} diff --git a/unittests/ADT/SmallVectorTest.cpp b/unittests/ADT/SmallVectorTest.cpp index 0d3535d..d5bfe76 100644 --- a/unittests/ADT/SmallVectorTest.cpp +++ b/unittests/ADT/SmallVectorTest.cpp @@ -383,7 +383,7 @@ TEST_F(SmallVectorTest, ComparisonTest) { // Constant vector tests. TEST_F(SmallVectorTest, ConstVectorTest) { - const VectorType constVector; + VectorType constVector; EXPECT_EQ(0u, constVector.size()); EXPECT_TRUE(constVector.empty()); diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp index 5731e4a..8364eac 100644 --- a/unittests/ADT/StringRefTest.cpp +++ b/unittests/ADT/StringRefTest.cpp @@ -73,6 +73,12 @@ TEST(StringRefTest, StringOps) { EXPECT_EQ( 1, StringRef("2").compare_numeric("1")); EXPECT_EQ( 0, StringRef("llvm_v1i64_ty").compare_numeric("llvm_v1i64_ty")); EXPECT_EQ( 1, StringRef("\xFF").compare_numeric("\1")); + EXPECT_EQ( 1, StringRef("V16").compare_numeric("V1_q0")); + EXPECT_EQ(-1, StringRef("V1_q0").compare_numeric("V16")); + EXPECT_EQ(-1, StringRef("V8_q0").compare_numeric("V16")); + EXPECT_EQ( 1, StringRef("V16").compare_numeric("V8_q0")); + EXPECT_EQ(-1, StringRef("V1_q0").compare_numeric("V8_q0")); + EXPECT_EQ( 1, StringRef("V8_q0").compare_numeric("V1_q0")); } TEST(StringRefTest, Operators) { diff --git a/unittests/ADT/TwineTest.cpp b/unittests/ADT/TwineTest.cpp index 57f54cb..e9cc41d 100644 --- a/unittests/ADT/TwineTest.cpp +++ b/unittests/ADT/TwineTest.cpp @@ -37,12 +37,16 @@ TEST(TwineTest, Numbers) { EXPECT_EQ("-123", Twine(-123).str()); EXPECT_EQ("123", Twine(123).str()); EXPECT_EQ("-123", Twine(-123).str()); - EXPECT_EQ("123", Twine((char) 123).str()); - EXPECT_EQ("-123", Twine((signed char) -123).str()); EXPECT_EQ("7b", Twine::utohexstr(123).str()); } +TEST(TwineTest, Characters) { + EXPECT_EQ("x", Twine('x').str()); + EXPECT_EQ("x", Twine(static_cast<unsigned char>('x')).str()); + EXPECT_EQ("x", Twine(static_cast<signed char>('x')).str()); +} + TEST(TwineTest, Concat) { // Check verse repr, since we care about the actual representation not just // the result. diff --git a/unittests/Analysis/ScalarEvolutionTest.cpp b/unittests/Analysis/ScalarEvolutionTest.cpp index 39ced2a..ea5aeb3 100644 --- a/unittests/Analysis/ScalarEvolutionTest.cpp +++ b/unittests/Analysis/ScalarEvolutionTest.cpp @@ -8,35 +8,48 @@ //===----------------------------------------------------------------------===// #include <llvm/Analysis/ScalarEvolutionExpressions.h> +#include <llvm/Analysis/LoopInfo.h> #include <llvm/GlobalVariable.h> #include <llvm/Constants.h> #include <llvm/LLVMContext.h> #include <llvm/Module.h> #include <llvm/PassManager.h> +#include <llvm/ADT/SmallVector.h> #include "gtest/gtest.h" namespace llvm { namespace { -TEST(ScalarEvolutionsTest, SCEVUnknownRAUW) { +// We use this fixture to ensure that we clean up ScalarEvolution before +// deleting the PassManager. +class ScalarEvolutionsTest : public testing::Test { +protected: + ScalarEvolutionsTest() : M("", Context), SE(*new ScalarEvolution) {} + ~ScalarEvolutionsTest() { + // Manually clean up, since we allocated new SCEV objects after the + // pass was finished. + SE.releaseMemory(); + } LLVMContext Context; - Module M("world", Context); + Module M; + PassManager PM; + ScalarEvolution &SE; +}; - const FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), +TEST_F(ScalarEvolutionsTest, SCEVUnknownRAUW) { + FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), std::vector<Type *>(), false); Function *F = cast<Function>(M.getOrInsertFunction("f", FTy)); BasicBlock *BB = BasicBlock::Create(Context, "entry", F); ReturnInst::Create(Context, 0, BB); - const Type *Ty = Type::getInt1Ty(Context); + Type *Ty = Type::getInt1Ty(Context); Constant *Init = Constant::getNullValue(Ty); Value *V0 = new GlobalVariable(M, Ty, false, GlobalValue::ExternalLinkage, Init, "V0"); Value *V1 = new GlobalVariable(M, Ty, false, GlobalValue::ExternalLinkage, Init, "V1"); Value *V2 = new GlobalVariable(M, Ty, false, GlobalValue::ExternalLinkage, Init, "V2"); // Create a ScalarEvolution and "run" it so that it gets initialized. - PassManager PM; - ScalarEvolution &SE = *new ScalarEvolution(); PM.add(&SE); PM.run(M); @@ -72,10 +85,149 @@ TEST(ScalarEvolutionsTest, SCEVUnknownRAUW) { EXPECT_EQ(cast<SCEVUnknown>(M0->getOperand(1))->getValue(), V0); EXPECT_EQ(cast<SCEVUnknown>(M1->getOperand(1))->getValue(), V0); EXPECT_EQ(cast<SCEVUnknown>(M2->getOperand(1))->getValue(), V0); +} + +TEST_F(ScalarEvolutionsTest, SCEVMultiplyAddRecs) { + Type *Ty = Type::getInt32Ty(Context); + SmallVector<Type *, 10> Types; + Types.append(10, Ty); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(Context), Types, false); + Function *F = cast<Function>(M.getOrInsertFunction("f", FTy)); + BasicBlock *BB = BasicBlock::Create(Context, "entry", F); + ReturnInst::Create(Context, 0, BB); + + // Create a ScalarEvolution and "run" it so that it gets initialized. + PM.add(&SE); + PM.run(M); + + // It's possible to produce an empty loop through the default constructor, + // but you can't add any blocks to it without a LoopInfo pass. + Loop L; + const_cast<std::vector<BasicBlock*>&>(L.getBlocks()).push_back(BB); + + Function::arg_iterator AI = F->arg_begin(); + SmallVector<const SCEV *, 5> A; + A.push_back(SE.getSCEV(&*AI++)); + A.push_back(SE.getSCEV(&*AI++)); + A.push_back(SE.getSCEV(&*AI++)); + A.push_back(SE.getSCEV(&*AI++)); + A.push_back(SE.getSCEV(&*AI++)); + const SCEV *A_rec = SE.getAddRecExpr(A, &L, SCEV::FlagAnyWrap); + + SmallVector<const SCEV *, 5> B; + B.push_back(SE.getSCEV(&*AI++)); + B.push_back(SE.getSCEV(&*AI++)); + B.push_back(SE.getSCEV(&*AI++)); + B.push_back(SE.getSCEV(&*AI++)); + B.push_back(SE.getSCEV(&*AI++)); + const SCEV *B_rec = SE.getAddRecExpr(B, &L, SCEV::FlagAnyWrap); + + /* Spot check that we perform this transformation: + {A0,+,A1,+,A2,+,A3,+,A4} * {B0,+,B1,+,B2,+,B3,+,B4} = + {A0*B0,+, + A1*B0 + A0*B1 + A1*B1,+, + A2*B0 + 2A1*B1 + A0*B2 + 2A2*B1 + 2A1*B2 + A2*B2,+, + A3*B0 + 3A2*B1 + 3A1*B2 + A0*B3 + 3A3*B1 + 6A2*B2 + 3A1*B3 + 3A3*B2 + + 3A2*B3 + A3*B3,+, + A4*B0 + 4A3*B1 + 6A2*B2 + 4A1*B3 + A0*B4 + 4A4*B1 + 12A3*B2 + 12A2*B3 + + 4A1*B4 + 6A4*B2 + 12A3*B3 + 6A2*B4 + 4A4*B3 + 4A3*B4 + A4*B4,+, + 5A4*B1 + 10A3*B2 + 10A2*B3 + 5A1*B4 + 20A4*B2 + 30A3*B3 + 20A2*B4 + + 30A4*B3 + 30A3*B4 + 20A4*B4,+, + 15A4*B2 + 20A3*B3 + 15A2*B4 + 60A4*B3 + 60A3*B4 + 90A4*B4,+, + 35A4*B3 + 35A3*B4 + 140A4*B4,+, + 70A4*B4} + */ + + const SCEVAddRecExpr *Product = + dyn_cast<SCEVAddRecExpr>(SE.getMulExpr(A_rec, B_rec)); + ASSERT_TRUE(Product); + ASSERT_EQ(Product->getNumOperands(), 9u); + + SmallVector<const SCEV *, 16> Sum; + Sum.push_back(SE.getMulExpr(A[0], B[0])); + EXPECT_EQ(Product->getOperand(0), SE.getAddExpr(Sum)); + Sum.clear(); + + // SCEV produces different an equal but different expression for these. + // Re-enable when PR11052 is fixed. +#if 0 + Sum.push_back(SE.getMulExpr(A[1], B[0])); + Sum.push_back(SE.getMulExpr(A[0], B[1])); + Sum.push_back(SE.getMulExpr(A[1], B[1])); + EXPECT_EQ(Product->getOperand(1), SE.getAddExpr(Sum)); + Sum.clear(); + + Sum.push_back(SE.getMulExpr(A[2], B[0])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 2), A[1], B[1])); + Sum.push_back(SE.getMulExpr(A[0], B[2])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 2), A[2], B[1])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 2), A[1], B[2])); + Sum.push_back(SE.getMulExpr(A[2], B[2])); + EXPECT_EQ(Product->getOperand(2), SE.getAddExpr(Sum)); + Sum.clear(); + + Sum.push_back(SE.getMulExpr(A[3], B[0])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 3), A[2], B[1])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 3), A[1], B[2])); + Sum.push_back(SE.getMulExpr(A[0], B[3])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 3), A[3], B[1])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 6), A[2], B[2])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 3), A[1], B[3])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 3), A[3], B[2])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 3), A[2], B[3])); + Sum.push_back(SE.getMulExpr(A[3], B[3])); + EXPECT_EQ(Product->getOperand(3), SE.getAddExpr(Sum)); + Sum.clear(); + + Sum.push_back(SE.getMulExpr(A[4], B[0])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 4), A[3], B[1])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 6), A[2], B[2])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 4), A[1], B[3])); + Sum.push_back(SE.getMulExpr(A[0], B[4])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 4), A[4], B[1])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 12), A[3], B[2])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 12), A[2], B[3])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 4), A[1], B[4])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 6), A[4], B[2])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 12), A[3], B[3])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 6), A[2], B[4])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 4), A[4], B[3])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 4), A[3], B[4])); + Sum.push_back(SE.getMulExpr(A[4], B[4])); + EXPECT_EQ(Product->getOperand(4), SE.getAddExpr(Sum)); + Sum.clear(); + + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 5), A[4], B[1])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 10), A[3], B[2])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 10), A[2], B[3])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 5), A[1], B[4])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 20), A[4], B[2])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 30), A[3], B[3])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 20), A[2], B[4])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 30), A[4], B[3])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 30), A[3], B[4])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 20), A[4], B[4])); + EXPECT_EQ(Product->getOperand(5), SE.getAddExpr(Sum)); + Sum.clear(); + + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 15), A[4], B[2])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 20), A[3], B[3])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 15), A[2], B[4])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 60), A[4], B[3])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 60), A[3], B[4])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 90), A[4], B[4])); + EXPECT_EQ(Product->getOperand(6), SE.getAddExpr(Sum)); + Sum.clear(); + + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 35), A[4], B[3])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 35), A[3], B[4])); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 140), A[4], B[4])); + EXPECT_EQ(Product->getOperand(7), SE.getAddExpr(Sum)); + Sum.clear(); +#endif - // Manually clean up, since we allocated new SCEV objects after the - // pass was finished. - SE.releaseMemory(); + Sum.push_back(SE.getMulExpr(SE.getConstant(Ty, 70), A[4], B[4])); + EXPECT_EQ(Product->getOperand(8), SE.getAddExpr(Sum)); } } // end anonymous namespace diff --git a/unittests/ExecutionEngine/ExecutionEngineTest.cpp b/unittests/ExecutionEngine/ExecutionEngineTest.cpp index 904ee2b..4dcef20 100644 --- a/unittests/ExecutionEngine/ExecutionEngineTest.cpp +++ b/unittests/ExecutionEngine/ExecutionEngineTest.cpp @@ -30,7 +30,7 @@ protected: ASSERT_TRUE(Engine.get() != NULL); } - GlobalVariable *NewExtGlobal(const Type *T, const Twine &Name) { + GlobalVariable *NewExtGlobal(Type *T, const Twine &Name) { return new GlobalVariable(*M, T, false, // Not constant. GlobalValue::ExternalLinkage, NULL, Name); } diff --git a/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp b/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp index a36ec3b..f8d8830 100644 --- a/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITEventListenerTest.cpp @@ -16,7 +16,7 @@ #include "llvm/CodeGen/MachineCodeInfo.h" #include "llvm/ExecutionEngine/JIT.h" #include "llvm/Support/TypeBuilder.h" -#include "llvm/Target/TargetSelect.h" +#include "llvm/Support/TargetSelect.h" #include "gtest/gtest.h" #include <vector> @@ -45,7 +45,7 @@ struct RecordingJITEventListener : public JITEventListener { std::vector<FunctionEmittedEvent> EmittedEvents; std::vector<FunctionFreedEvent> FreedEvents; - int NextIndex; + unsigned NextIndex; RecordingJITEventListener() : NextIndex(0) {} diff --git a/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp b/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp index 039b5e0..be5d152 100644 --- a/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITMemoryManagerTest.cpp @@ -22,7 +22,7 @@ namespace { Function *makeFakeFunction() { std::vector<Type*> params; - const FunctionType *FTy = + FunctionType *FTy = FunctionType::get(Type::getVoidTy(getGlobalContext()), params, false); return Function::Create(FTy, GlobalValue::ExternalLinkage); } diff --git a/unittests/ExecutionEngine/JIT/JITTest.cpp b/unittests/ExecutionEngine/JIT/JITTest.cpp index 9c001c4..2ef2730 100644 --- a/unittests/ExecutionEngine/JIT/JITTest.cpp +++ b/unittests/ExecutionEngine/JIT/JITTest.cpp @@ -27,7 +27,7 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/TypeBuilder.h" -#include "llvm/Target/TargetSelect.h" +#include "llvm/Support/TargetSelect.h" #include "llvm/Type.h" #include <vector> @@ -38,13 +38,13 @@ namespace { Function *makeReturnGlobal(std::string Name, GlobalVariable *G, Module *M) { std::vector<Type*> params; - const FunctionType *FTy = FunctionType::get(G->getType()->getElementType(), + FunctionType *FTy = FunctionType::get(G->getType()->getElementType(), params, false); Function *F = Function::Create(FTy, GlobalValue::ExternalLinkage, Name, M); BasicBlock *Entry = BasicBlock::Create(M->getContext(), "entry", F); IRBuilder<> builder(Entry); Value *Load = builder.CreateLoad(G); - const Type *GTy = G->getType()->getElementType(); + Type *GTy = G->getType()->getElementType(); Value *Add = builder.CreateAdd(Load, ConstantInt::get(GTy, 1LL)); builder.CreateStore(Add, G); builder.CreateRet(Add); @@ -236,7 +236,7 @@ TEST(JIT, GlobalInFunction) { ASSERT_EQ(Error, ""); // Create a global variable. - const Type *GTy = Type::getInt32Ty(context); + Type *GTy = Type::getInt32Ty(context); GlobalVariable *G = new GlobalVariable( *M, GTy, @@ -284,6 +284,8 @@ int PlusOne(int arg) { return arg + 1; } +// ARM tests disabled pending fix for PR10783. +#if !defined(__arm__) TEST_F(JITTest, FarCallToKnownFunction) { // x86-64 can only make direct calls to functions within 32 bits of // the current PC. To call anything farther away, we have to load @@ -320,11 +322,11 @@ TEST_F(JITTest, FarCallToKnownFunction) { TEST_F(JITTest, NonLazyCompilationStillNeedsStubs) { TheJIT->DisableLazyCompilation(true); - const FunctionType *Func1Ty = + FunctionType *Func1Ty = cast<FunctionType>(TypeBuilder<void(void), false>::get(Context)); std::vector<Type*> arg_types; arg_types.push_back(Type::getInt1Ty(Context)); - const FunctionType *FuncTy = FunctionType::get( + FunctionType *FuncTy = FunctionType::get( Type::getVoidTy(Context), arg_types, false); Function *Func1 = Function::Create(Func1Ty, Function::ExternalLinkage, "func1", M); @@ -377,7 +379,7 @@ TEST_F(JITTest, NonLazyLeaksNoStubs) { TheJIT->DisableLazyCompilation(true); // Create two functions with a single basic block each. - const FunctionType *FuncTy = + FunctionType *FuncTy = cast<FunctionType>(TypeBuilder<int(), false>::get(Context)); Function *Func1 = Function::Create(FuncTy, Function::ExternalLinkage, "func1", M); @@ -461,6 +463,7 @@ TEST_F(JITTest, ModuleDeletion) { EXPECT_EQ(RJMM->startExceptionTableCalls.size(), NumTablesDeallocated); } +#endif // !defined(__arm__) // ARM and PPC still emit stubs for calls since the target may be too far away // to call directly. This #if can probably be removed when @@ -608,6 +611,8 @@ extern "C" int32_t JITTest_AvailableExternallyFunction() { } namespace { +// ARM tests disabled pending fix for PR10783. +#if !defined(__arm__) TEST_F(JITTest, AvailableExternallyFunctionIsntCompiled) { TheJIT->DisableLazyCompilation(true); LoadAssembly("define available_externally i32 " @@ -763,6 +768,7 @@ TEST(LazyLoadedJITTest, EagerCompiledRecursionThroughGhost) { (intptr_t)TheJIT->getPointerToFunction(recur1IR)); EXPECT_EQ(3, recur1(4)); } +#endif // !defined(__arm__) // This code is copied from JITEventListenerTest, but it only runs once for all // the tests in this directory. Everything seems fine, but that's strange diff --git a/unittests/ExecutionEngine/JIT/MultiJITTest.cpp b/unittests/ExecutionEngine/JIT/MultiJITTest.cpp index 8997d39..91ea64a 100644 --- a/unittests/ExecutionEngine/JIT/MultiJITTest.cpp +++ b/unittests/ExecutionEngine/JIT/MultiJITTest.cpp @@ -65,6 +65,9 @@ void createModule2(LLVMContext &Context2, Module *&M2, Function *&FooF2) { FooF2 = M2->getFunction("foo2"); } +// ARM tests disabled pending fix for PR10783. +#if !defined(__arm__) + TEST(MultiJitTest, EagerMode) { LLVMContext Context1; Module *M1 = 0; @@ -160,5 +163,6 @@ TEST(MultiJitTest, JitPool) { EXPECT_EQ((intptr_t)getPointerToNamedFunction("getPointerToNamedFunction"), (intptr_t)&getPointerToNamedFunction); } +#endif // !defined(__arm__) } // anonymous namespace diff --git a/unittests/Support/BlockFrequencyTest.cpp b/unittests/Support/BlockFrequencyTest.cpp new file mode 100644 index 0000000..edeea9b --- /dev/null +++ b/unittests/Support/BlockFrequencyTest.cpp @@ -0,0 +1,56 @@ +#include "llvm/Support/DataTypes.h" +#include "llvm/Support/BlockFrequency.h" +#include "llvm/Support/BranchProbability.h" + +#include "gtest/gtest.h" +#include <climits> + +using namespace llvm; + +namespace { + +TEST(BlockFrequencyTest, OneToZero) { + BlockFrequency Freq(1); + BranchProbability Prob(UINT32_MAX - 1, UINT32_MAX); + Freq *= Prob; + EXPECT_EQ(Freq.getFrequency(), 0u); +} + +TEST(BlockFrequencyTest, OneToOne) { + BlockFrequency Freq(1); + BranchProbability Prob(UINT32_MAX, UINT32_MAX); + Freq *= Prob; + EXPECT_EQ(Freq.getFrequency(), 1u); +} + +TEST(BlockFrequencyTest, ThreeToOne) { + BlockFrequency Freq(3); + BranchProbability Prob(3000000, 9000000); + Freq *= Prob; + EXPECT_EQ(Freq.getFrequency(), 1u); +} + +TEST(BlockFrequencyTest, MaxToHalfMax) { + BlockFrequency Freq(UINT64_MAX); + BranchProbability Prob(UINT32_MAX / 2, UINT32_MAX); + Freq *= Prob; + EXPECT_EQ(Freq.getFrequency(), 9223372034707292159LLu); +} + +TEST(BlockFrequencyTest, BigToBig) { + const uint64_t Big = 387246523487234346LL; + const uint32_t P = 123456789; + BlockFrequency Freq(Big); + BranchProbability Prob(P, P); + Freq *= Prob; + EXPECT_EQ(Freq.getFrequency(), Big); +} + +TEST(BlockFrequencyTest, MaxToMax) { + BlockFrequency Freq(UINT64_MAX); + BranchProbability Prob(UINT32_MAX, UINT32_MAX); + Freq *= Prob; + EXPECT_EQ(Freq.getFrequency(), UINT64_MAX); +} + +} diff --git a/unittests/Support/DataExtractorTest.cpp b/unittests/Support/DataExtractorTest.cpp new file mode 100644 index 0000000..9813e46 --- /dev/null +++ b/unittests/Support/DataExtractorTest.cpp @@ -0,0 +1,111 @@ +//===- llvm/unittest/Support/DataExtractorTest.cpp - DataExtractor tests --===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "gtest/gtest.h" +#include "llvm/Support/DataExtractor.h" +using namespace llvm; + +namespace { + +const char numberData[] = "\x80\x90\xFF\xFF\x80\x00\x00\x00"; +const char stringData[] = "hellohello\0hello"; +const char leb128data[] = "\xA6\x49"; + +TEST(DataExtractorTest, OffsetOverflow) { + DataExtractor DE(StringRef(numberData, sizeof(numberData)-1), false, 8); + EXPECT_FALSE(DE.isValidOffsetForDataOfSize(-2U, 5)); +} + +TEST(DataExtractorTest, UnsignedNumbers) { + DataExtractor DE(StringRef(numberData, sizeof(numberData)-1), false, 8); + uint32_t offset = 0; + + EXPECT_EQ(0x80U, DE.getU8(&offset)); + EXPECT_EQ(1U, offset); + offset = 0; + EXPECT_EQ(0x8090U, DE.getU16(&offset)); + EXPECT_EQ(2U, offset); + offset = 0; + EXPECT_EQ(0x8090FFFFU, DE.getU32(&offset)); + EXPECT_EQ(4U, offset); + offset = 0; + EXPECT_EQ(0x8090FFFF80000000ULL, DE.getU64(&offset)); + EXPECT_EQ(8U, offset); + offset = 0; + EXPECT_EQ(0x8090FFFF80000000ULL, DE.getAddress(&offset)); + EXPECT_EQ(8U, offset); + offset = 0; + + uint32_t data[2]; + EXPECT_EQ(data, DE.getU32(&offset, data, 2)); + EXPECT_EQ(0x8090FFFFU, data[0]); + EXPECT_EQ(0x80000000U, data[1]); + EXPECT_EQ(8U, offset); + offset = 0; + + // Now for little endian. + DE = DataExtractor(StringRef(numberData, sizeof(numberData)-1), true, 4); + EXPECT_EQ(0x9080U, DE.getU16(&offset)); + EXPECT_EQ(2U, offset); + offset = 0; + EXPECT_EQ(0xFFFF9080U, DE.getU32(&offset)); + EXPECT_EQ(4U, offset); + offset = 0; + EXPECT_EQ(0x80FFFF9080ULL, DE.getU64(&offset)); + EXPECT_EQ(8U, offset); + offset = 0; + EXPECT_EQ(0xFFFF9080U, DE.getAddress(&offset)); + EXPECT_EQ(4U, offset); + offset = 0; + + EXPECT_EQ(data, DE.getU32(&offset, data, 2)); + EXPECT_EQ(0xFFFF9080U, data[0]); + EXPECT_EQ(0x80U, data[1]); + EXPECT_EQ(8U, offset); +} + +TEST(DataExtractorTest, SignedNumbers) { + DataExtractor DE(StringRef(numberData, sizeof(numberData)-1), false, 8); + uint32_t offset = 0; + + EXPECT_EQ(-128, DE.getSigned(&offset, 1)); + EXPECT_EQ(1U, offset); + offset = 0; + EXPECT_EQ(-32624, DE.getSigned(&offset, 2)); + EXPECT_EQ(2U, offset); + offset = 0; + EXPECT_EQ(-2137980929, DE.getSigned(&offset, 4)); + EXPECT_EQ(4U, offset); + offset = 0; + EXPECT_EQ(-9182558167379214336LL, DE.getSigned(&offset, 8)); + EXPECT_EQ(8U, offset); +} + +TEST(DataExtractorTest, Strings) { + DataExtractor DE(StringRef(stringData, sizeof(stringData)-1), false, 8); + uint32_t offset = 0; + + EXPECT_EQ(stringData, DE.getCStr(&offset)); + EXPECT_EQ(11U, offset); + EXPECT_EQ(NULL, DE.getCStr(&offset)); + EXPECT_EQ(11U, offset); +} + +TEST(DataExtractorTest, LEB128) { + DataExtractor DE(StringRef(leb128data, sizeof(leb128data)-1), false, 8); + uint32_t offset = 0; + + EXPECT_EQ(9382ULL, DE.getULEB128(&offset)); + EXPECT_EQ(2U, offset); + offset = 0; + EXPECT_EQ(-7002LL, DE.getSLEB128(&offset)); + EXPECT_EQ(2U, offset); +} + +} diff --git a/unittests/Support/TypeBuilderTest.cpp b/unittests/Support/TypeBuilderTest.cpp index 0609178..20d0e73 100644 --- a/unittests/Support/TypeBuilderTest.cpp +++ b/unittests/Support/TypeBuilderTest.cpp @@ -184,14 +184,14 @@ class MyPortableType { namespace llvm { template<bool cross> class TypeBuilder<MyType, cross> { public: - static const StructType *get(LLVMContext &Context) { + static StructType *get(LLVMContext &Context) { // Using the static result variable ensures that the type is // only looked up once. std::vector<Type*> st; st.push_back(TypeBuilder<int, cross>::get(Context)); st.push_back(TypeBuilder<int*, cross>::get(Context)); st.push_back(TypeBuilder<void*[], cross>::get(Context)); - static const StructType *const result = StructType::get(Context, st); + static StructType *const result = StructType::get(Context, st); return result; } @@ -207,14 +207,14 @@ public: template<bool cross> class TypeBuilder<MyPortableType, cross> { public: - static const StructType *get(LLVMContext &Context) { + static StructType *get(LLVMContext &Context) { // Using the static result variable ensures that the type is // only looked up once. std::vector<Type*> st; st.push_back(TypeBuilder<types::i<32>, cross>::get(Context)); st.push_back(TypeBuilder<types::i<32>*, cross>::get(Context)); st.push_back(TypeBuilder<types::i<8>*[], cross>::get(Context)); - static const StructType *const result = StructType::get(Context, st); + static StructType *const result = StructType::get(Context, st); return result; } @@ -235,19 +235,19 @@ TEST(TypeBuilderTest, Extensions) { TypeBuilder<int, false>::get(getGlobalContext()), TypeBuilder<int*, false>::get(getGlobalContext()), TypeBuilder<void*[], false>::get(getGlobalContext()), - NULL)), + (void*)0)), (TypeBuilder<MyType*, false>::get(getGlobalContext()))); EXPECT_EQ(PointerType::getUnqual(StructType::get( TypeBuilder<types::i<32>, false>::get(getGlobalContext()), TypeBuilder<types::i<32>*, false>::get(getGlobalContext()), TypeBuilder<types::i<8>*[], false>::get(getGlobalContext()), - NULL)), + (void*)0)), (TypeBuilder<MyPortableType*, false>::get(getGlobalContext()))); EXPECT_EQ(PointerType::getUnqual(StructType::get( TypeBuilder<types::i<32>, false>::get(getGlobalContext()), TypeBuilder<types::i<32>*, false>::get(getGlobalContext()), TypeBuilder<types::i<8>*[], false>::get(getGlobalContext()), - NULL)), + (void*)0)), (TypeBuilder<MyPortableType*, true>::get(getGlobalContext()))); } diff --git a/unittests/Transforms/Utils/Cloning.cpp b/unittests/Transforms/Utils/Cloning.cpp index 1ce549d1..1b85869 100644 --- a/unittests/Transforms/Utils/Cloning.cpp +++ b/unittests/Transforms/Utils/Cloning.cpp @@ -124,7 +124,7 @@ TEST_F(CloneInstruction, Inbounds) { Constant *Z = Constant::getNullValue(Type::getInt32Ty(context)); std::vector<Value *> ops; ops.push_back(Z); - GetElementPtrInst *GEP = GetElementPtrInst::Create(V, ops.begin(), ops.end()); + GetElementPtrInst *GEP = GetElementPtrInst::Create(V, ops); EXPECT_FALSE(this->clone(GEP)->isInBounds()); GEP->setIsInBounds(); diff --git a/unittests/VMCore/ConstantsTest.cpp b/unittests/VMCore/ConstantsTest.cpp index 8277584..623ea0d 100644 --- a/unittests/VMCore/ConstantsTest.cpp +++ b/unittests/VMCore/ConstantsTest.cpp @@ -16,7 +16,7 @@ namespace llvm { namespace { TEST(ConstantsTest, Integer_i1) { - const IntegerType* Int1 = IntegerType::get(getGlobalContext(), 1); + IntegerType* Int1 = IntegerType::get(getGlobalContext(), 1); Constant* One = ConstantInt::get(Int1, 1, true); Constant* Zero = ConstantInt::get(Int1, 0); Constant* NegOne = ConstantInt::get(Int1, static_cast<uint64_t>(-1), true); @@ -97,7 +97,7 @@ TEST(ConstantsTest, Integer_i1) { } TEST(ConstantsTest, IntSigns) { - const IntegerType* Int8Ty = Type::getInt8Ty(getGlobalContext()); + IntegerType* Int8Ty = Type::getInt8Ty(getGlobalContext()); EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, false)->getSExtValue()); EXPECT_EQ(100, ConstantInt::get(Int8Ty, 100, true)->getSExtValue()); EXPECT_EQ(100, ConstantInt::getSigned(Int8Ty, 100)->getSExtValue()); @@ -110,9 +110,9 @@ TEST(ConstantsTest, IntSigns) { } TEST(ConstantsTest, FP128Test) { - const Type *FP128Ty = Type::getFP128Ty(getGlobalContext()); + Type *FP128Ty = Type::getFP128Ty(getGlobalContext()); - const IntegerType *Int128Ty = Type::getIntNTy(getGlobalContext(), 128); + IntegerType *Int128Ty = Type::getIntNTy(getGlobalContext(), 128); Constant *Zero128 = Constant::getNullValue(Int128Ty); Constant *X = ConstantExpr::getUIToFP(Zero128, FP128Ty); EXPECT_TRUE(isa<ConstantFP>(X)); diff --git a/unittests/VMCore/InstructionsTest.cpp b/unittests/VMCore/InstructionsTest.cpp index 9624b81..f0197bb 100644 --- a/unittests/VMCore/InstructionsTest.cpp +++ b/unittests/VMCore/InstructionsTest.cpp @@ -26,16 +26,16 @@ TEST(InstructionsTest, ReturnInst) { EXPECT_EQ(r0->getNumOperands(), 0U); EXPECT_EQ(r0->op_begin(), r0->op_end()); - const IntegerType* Int1 = IntegerType::get(C, 1); + IntegerType* Int1 = IntegerType::get(C, 1); Constant* One = ConstantInt::get(Int1, 1, true); const ReturnInst* r1 = ReturnInst::Create(C, One); - EXPECT_EQ(r1->getNumOperands(), 1U); + EXPECT_EQ(1U, r1->getNumOperands()); User::const_op_iterator b(r1->op_begin()); - EXPECT_NE(b, r1->op_end()); - EXPECT_EQ(*b, One); - EXPECT_EQ(r1->getOperand(0), One); + EXPECT_NE(r1->op_end(), b); + EXPECT_EQ(One, *b); + EXPECT_EQ(One, r1->getOperand(0)); ++b; - EXPECT_EQ(b, r1->op_end()); + EXPECT_EQ(r1->op_end(), b); // clean up delete r0; @@ -54,17 +54,17 @@ TEST(InstructionsTest, BranchInst) { EXPECT_TRUE(b0->isUnconditional()); EXPECT_FALSE(b0->isConditional()); - EXPECT_EQ(b0->getNumSuccessors(), 1U); + EXPECT_EQ(1U, b0->getNumSuccessors()); // check num operands - EXPECT_EQ(b0->getNumOperands(), 1U); + EXPECT_EQ(1U, b0->getNumOperands()); EXPECT_NE(b0->op_begin(), b0->op_end()); - EXPECT_EQ(llvm::next(b0->op_begin()), b0->op_end()); + EXPECT_EQ(b0->op_end(), llvm::next(b0->op_begin())); - EXPECT_EQ(llvm::next(b0->op_begin()), b0->op_end()); + EXPECT_EQ(b0->op_end(), llvm::next(b0->op_begin())); - const IntegerType* Int1 = IntegerType::get(C, 1); + IntegerType* Int1 = IntegerType::get(C, 1); Constant* One = ConstantInt::get(Int1, 1, true); // Conditional BranchInst @@ -72,33 +72,33 @@ TEST(InstructionsTest, BranchInst) { EXPECT_FALSE(b1->isUnconditional()); EXPECT_TRUE(b1->isConditional()); - EXPECT_EQ(b1->getNumSuccessors(), 2U); + EXPECT_EQ(2U, b1->getNumSuccessors()); // check num operands - EXPECT_EQ(b1->getNumOperands(), 3U); + EXPECT_EQ(3U, b1->getNumOperands()); User::const_op_iterator b(b1->op_begin()); // check COND EXPECT_NE(b, b1->op_end()); - EXPECT_EQ(*b, One); - EXPECT_EQ(b1->getOperand(0), One); - EXPECT_EQ(b1->getCondition(), One); + EXPECT_EQ(One, *b); + EXPECT_EQ(One, b1->getOperand(0)); + EXPECT_EQ(One, b1->getCondition()); ++b; // check ELSE - EXPECT_EQ(*b, bb1); - EXPECT_EQ(b1->getOperand(1), bb1); - EXPECT_EQ(b1->getSuccessor(1), bb1); + EXPECT_EQ(bb1, *b); + EXPECT_EQ(bb1, b1->getOperand(1)); + EXPECT_EQ(bb1, b1->getSuccessor(1)); ++b; // check THEN - EXPECT_EQ(*b, bb0); - EXPECT_EQ(b1->getOperand(2), bb0); - EXPECT_EQ(b1->getSuccessor(0), bb0); + EXPECT_EQ(bb0, *b); + EXPECT_EQ(bb0, b1->getOperand(2)); + EXPECT_EQ(bb0, b1->getSuccessor(0)); ++b; - EXPECT_EQ(b, b1->op_end()); + EXPECT_EQ(b1->op_end(), b); // clean up delete b0; @@ -111,11 +111,11 @@ TEST(InstructionsTest, BranchInst) { TEST(InstructionsTest, CastInst) { LLVMContext &C(getGlobalContext()); - const Type* Int8Ty = Type::getInt8Ty(C); - const Type* Int64Ty = Type::getInt64Ty(C); - const Type* V8x8Ty = VectorType::get(Int8Ty, 8); - const Type* V8x64Ty = VectorType::get(Int64Ty, 8); - const Type* X86MMXTy = Type::getX86_MMXTy(C); + Type* Int8Ty = Type::getInt8Ty(C); + Type* Int64Ty = Type::getInt64Ty(C); + Type* V8x8Ty = VectorType::get(Int8Ty, 8); + Type* V8x64Ty = VectorType::get(Int64Ty, 8); + Type* X86MMXTy = Type::getX86_MMXTy(C); const Constant* c8 = Constant::getNullValue(V8x8Ty); const Constant* c64 = Constant::getNullValue(V8x64Ty); @@ -125,8 +125,8 @@ TEST(InstructionsTest, CastInst) { EXPECT_FALSE(CastInst::isCastable(Int64Ty, X86MMXTy)); EXPECT_TRUE(CastInst::isCastable(V8x64Ty, V8x8Ty)); EXPECT_TRUE(CastInst::isCastable(V8x8Ty, V8x64Ty)); - EXPECT_EQ(CastInst::getCastOpcode(c64, true, V8x8Ty, true), CastInst::Trunc); - EXPECT_EQ(CastInst::getCastOpcode(c8, true, V8x64Ty, true), CastInst::SExt); + EXPECT_EQ(CastInst::Trunc, CastInst::getCastOpcode(c64, true, V8x8Ty, true)); + EXPECT_EQ(CastInst::SExt, CastInst::getCastOpcode(c8, true, V8x64Ty, true)); } } // end anonymous namespace diff --git a/unittests/VMCore/MetadataTest.cpp b/unittests/VMCore/MetadataTest.cpp index 0b2c012..12ac2e7 100644 --- a/unittests/VMCore/MetadataTest.cpp +++ b/unittests/VMCore/MetadataTest.cpp @@ -63,7 +63,7 @@ TEST_F(MDStringTest, PrintingSimple) { // Test printing of MDString with non-printable characters. TEST_F(MDStringTest, PrintingComplex) { - char str[5] = {0, '\n', '"', '\\', -1}; + char str[5] = {0, '\n', '"', '\\', (char)-1}; MDString *s = MDString::get(Context, StringRef(str+0, 5)); std::string Str; raw_string_ostream oss(Str); diff --git a/unittests/VMCore/VerifierTest.cpp b/unittests/VMCore/VerifierTest.cpp index 1924661..324b4e1 100644 --- a/unittests/VMCore/VerifierTest.cpp +++ b/unittests/VMCore/VerifierTest.cpp @@ -47,7 +47,7 @@ TEST(VerifierTest, Branch_i1) { TEST(VerifierTest, AliasUnnamedAddr) { LLVMContext &C = getGlobalContext(); Module M("M", C); - const Type *Ty = Type::getInt8Ty(C); + Type *Ty = Type::getInt8Ty(C); Constant *Init = Constant::getNullValue(Ty); GlobalVariable *Aliasee = new GlobalVariable(M, Ty, true, GlobalValue::ExternalLinkage, |