blob: dd91704d137e16db0aef07e34cafcf41089e3045 [file] [log] [blame]
Chandler Carruthc779e962013-01-07 15:35:46 +00001//===- llvm/unittest/IR/WaymarkTest.cpp - getUser() unit tests ------------===//
Gabor Greif9a5f90a2012-11-12 10:01:17 +00002//
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//
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000012#include "llvm/IR/Function.h"
13#include "llvm/IR/Instructions.h"
14#include "llvm/IR/LLVMContext.h"
Gabor Greif9a5f90a2012-11-12 10:01:17 +000015#include "gtest/gtest.h"
16#include <algorithm>
17
18namespace llvm {
19namespace {
20
21Constant *char2constant(char c) {
22 return ConstantInt::get(Type::getInt8Ty(getGlobalContext()), c);
23}
Gabor Greifd5439312012-11-12 13:34:59 +000024
Gabor Greif9a5f90a2012-11-12 10:01:17 +000025
26TEST(WaymarkTest, NativeArray) {
27 static uint8_t tail[22] = "s02s33s30y2y0s1x0syxS";
28 Value * values[22];
29 std::transform(tail, tail + 22, values, char2constant);
NAKAMURA Takumibde0f0f2013-01-23 08:30:21 +000030 FunctionType *FT = FunctionType::get(Type::getVoidTy(getGlobalContext()), true);
Gabor Greif9a5f90a2012-11-12 10:01:17 +000031 Function *F = Function::Create(FT, GlobalValue::ExternalLinkage);
NAKAMURA Takumibde0f0f2013-01-23 08:30:21 +000032 const CallInst *A = CallInst::Create(F, makeArrayRef(values));
Gabor Greif9a5f90a2012-11-12 10:01:17 +000033 ASSERT_NE(A, (const CallInst*)NULL);
34 ASSERT_EQ(1U + 22, A->getNumOperands());
NAKAMURA Takumibde0f0f2013-01-23 08:30:21 +000035 const Use *U = &A->getOperandUse(0);
36 const Use *Ue = &A->getOperandUse(22);
Gabor Greif9a5f90a2012-11-12 10:01:17 +000037 for (; U != Ue; ++U)
38 {
Gabor Greifd5439312012-11-12 13:34:59 +000039 EXPECT_EQ(A, U->getUser());
Gabor Greif9a5f90a2012-11-12 10:01:17 +000040 }
41}
42
43TEST(WaymarkTest, TwoBit) {
Gabor Greifd5439312012-11-12 13:34:59 +000044 Use* many = (Use*)calloc(sizeof(Use), 8212 + 1);
Gabor Greif9a5f90a2012-11-12 10:01:17 +000045 ASSERT_TRUE(many);
NAKAMURA Takumibde0f0f2013-01-23 08:30:21 +000046 Use::initTags(many, many + 8212);
Dmitri Gribenko31659fa2013-01-14 21:23:37 +000047 for (Use *U = many, *Ue = many + 8212 - 1; U != Ue; ++U)
Gabor Greif9a5f90a2012-11-12 10:01:17 +000048 {
Dmitri Gribenko31659fa2013-01-14 21:23:37 +000049 EXPECT_EQ(reinterpret_cast<User *>(Ue + 1), U->getUser());
Gabor Greif9a5f90a2012-11-12 10:01:17 +000050 }
51}
52
53} // end anonymous namespace
54} // end namespace llvm