aboutsummaryrefslogtreecommitdiffstats
path: root/unittests/IR/WaymarkTest.cpp
blob: a8924efed3f5fc72e0595deab247fc6d4359c5a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//===- llvm/unittest/IR/WaymarkTest.cpp - getUser() unit tests ------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

// we perform white-box tests
//
#include "llvm/IR/Constants.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "gtest/gtest.h"
#include <algorithm>

namespace llvm {
namespace {

Constant *char2constant(char c) {
  return ConstantInt::get(Type::getInt8Ty(getGlobalContext()), c);
}


TEST(WaymarkTest, NativeArray) {
  static uint8_t tail[22] = "s02s33s30y2y0s1x0syxS";
  Value * values[22];
  std::transform(tail, tail + 22, values, char2constant);
  FunctionType *FT = FunctionType::get(Type::getVoidTy(getGlobalContext()), true);
  std::unique_ptr<Function> F(
      Function::Create(FT, GlobalValue::ExternalLinkage));
  const CallInst *A = CallInst::Create(F.get(), makeArrayRef(values));
  ASSERT_NE(A, (const CallInst*)nullptr);
  ASSERT_EQ(1U + 22, A->getNumOperands());
  const Use *U = &A->getOperandUse(0);
  const Use *Ue = &A->getOperandUse(22);
  for (; U != Ue; ++U)
  {
    EXPECT_EQ(A, U->getUser());
  }
  delete A;
}

TEST(WaymarkTest, TwoBit) {
  Use* many = (Use*)calloc(sizeof(Use), 8212 + 1);
  ASSERT_TRUE(many);
  Use::initTags(many, many + 8212);
  for (Use *U = many, *Ue = many + 8212 - 1; U != Ue; ++U)
  {
    EXPECT_EQ(reinterpret_cast<User *>(Ue + 1), U->getUser());
  }
  free(many);
}

}  // end anonymous namespace
}  // end namespace llvm