Gabor Greif | fea6a55 | 2012-11-12 10:01:17 +0000 | [diff] [blame^] | 1 | //===- llvm/unittest/VMCore/WaymarkTest.cpp - getUser() unit tests --------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // we perform white-box tests |
| 11 | // |
| 12 | #define private public |
| 13 | #include "llvm/Use.h" |
| 14 | #undef private |
| 15 | #include "llvm/Function.h" |
| 16 | #include "llvm/Instructions.h" |
| 17 | #include "llvm/LLVMContext.h" |
| 18 | #include "gtest/gtest.h" |
| 19 | #include <algorithm> |
| 20 | |
| 21 | namespace llvm { |
| 22 | namespace { |
| 23 | |
| 24 | Constant *char2constant(char c) { |
| 25 | return ConstantInt::get(Type::getInt8Ty(getGlobalContext()), c); |
| 26 | } |
| 27 | |
| 28 | |
| 29 | TEST(WaymarkTest, NativeArray) { |
| 30 | static uint8_t tail[22] = "s02s33s30y2y0s1x0syxS"; |
| 31 | Value * values[22]; |
| 32 | std::transform(tail, tail + 22, values, char2constant); |
| 33 | FunctionType *FT = FunctionType::get(Type::getVoidTy(getGlobalContext()), true); |
| 34 | Function *F = Function::Create(FT, GlobalValue::ExternalLinkage); |
| 35 | const CallInst *A = CallInst::Create(F, makeArrayRef(values)); |
| 36 | ASSERT_NE(A, (const CallInst*)NULL); |
| 37 | ASSERT_EQ(1U + 22, A->getNumOperands()); |
| 38 | const Use *U = &A->getOperandUse(0); |
| 39 | const Use *Ue = &A->getOperandUse(22); |
| 40 | for (; U != Ue; ++U) |
| 41 | { |
| 42 | EXPECT_EQ(Ue + 1, U->getImpliedUser()); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | TEST(WaymarkTest, TwoBit) { |
| 47 | Use* many = (Use*)calloc(sizeof(Use), 8212); |
| 48 | ASSERT_TRUE(many); |
| 49 | Use::initTags(many, many + 8212); |
| 50 | for (const Use *U = many, *Ue = many + 8212 - 1; U != Ue; ++U) |
| 51 | { |
| 52 | EXPECT_EQ(Ue + 1, U->getImpliedUser()); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | } // end anonymous namespace |
| 57 | } // end namespace llvm |