1 //===- llvm/unittest/IR/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 #include "llvm/IR/Constants.h" 13 #include "llvm/IR/Function.h" 14 #include "llvm/IR/Instructions.h" 15 #include "llvm/IR/LLVMContext.h" 16 #include "gtest/gtest.h" 17 #include <algorithm> 18 19 namespace llvm { 20 namespace { 21 22 TEST(WaymarkTest, NativeArray) { 23 LLVMContext Context; 24 static uint8_t tail[22] = "s02s33s30y2y0s1x0syxS"; 25 Value * values[22]; 26 std::transform(tail, tail + 22, values, [&](char c) { 27 return ConstantInt::get(Type::getInt8Ty(Context), c); 28 }); 29 FunctionType *FT = FunctionType::get(Type::getVoidTy(Context), true); 30 std::unique_ptr<Function> F( 31 Function::Create(FT, GlobalValue::ExternalLinkage)); 32 const CallInst *A = CallInst::Create(F.get(), makeArrayRef(values)); 33 ASSERT_NE(A, (const CallInst*)nullptr); 34 ASSERT_EQ(1U + 22, A->getNumOperands()); 35 const Use *U = &A->getOperandUse(0); 36 const Use *Ue = &A->getOperandUse(22); 37 for (; U != Ue; ++U) 38 { 39 EXPECT_EQ(A, U->getUser()); 40 } 41 delete A; 42 } 43 44 TEST(WaymarkTest, TwoBit) { 45 Use* many = (Use*)calloc(sizeof(Use), 8212 + 1); 46 ASSERT_TRUE(many); 47 Use::initTags(many, many + 8212); 48 for (Use *U = many, *Ue = many + 8212 - 1; U != Ue; ++U) 49 { 50 EXPECT_EQ(reinterpret_cast<User *>(Ue + 1), U->getUser()); 51 } 52 free(many); 53 } 54 55 } // end anonymous namespace 56 } // end namespace llvm 57