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