blob: 9a9b4a2ad4e7b052424faf8186831d58195166f2 [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//
Bob Wilsondb3a9e62013-09-09 19:14:35 +000012#include "llvm/IR/Constants.h"
Chandler Carruth0b8c9a82013-01-02 11:36:10 +000013#include "llvm/IR/Function.h"
14#include "llvm/IR/Instructions.h"
15#include "llvm/IR/LLVMContext.h"
Gabor Greif9a5f90a2012-11-12 10:01:17 +000016#include "gtest/gtest.h"
17#include <algorithm>
18
19namespace llvm {
20namespace {
21
22Constant *char2constant(char c) {
23 return ConstantInt::get(Type::getInt8Ty(getGlobalContext()), c);
24}
Gabor Greifd5439312012-11-12 13:34:59 +000025
Gabor Greif9a5f90a2012-11-12 10:01:17 +000026
27TEST(WaymarkTest, NativeArray) {
28 static uint8_t tail[22] = "s02s33s30y2y0s1x0syxS";
29 Value * values[22];
30 std::transform(tail, tail + 22, values, char2constant);
NAKAMURA Takumibde0f0f2013-01-23 08:30:21 +000031 FunctionType *FT = FunctionType::get(Type::getVoidTy(getGlobalContext()), true);
Gabor Greif9a5f90a2012-11-12 10:01:17 +000032 Function *F = Function::Create(FT, GlobalValue::ExternalLinkage);
NAKAMURA Takumibde0f0f2013-01-23 08:30:21 +000033 const CallInst *A = CallInst::Create(F, makeArrayRef(values));
Gabor Greif9a5f90a2012-11-12 10:01:17 +000034 ASSERT_NE(A, (const CallInst*)NULL);
35 ASSERT_EQ(1U + 22, A->getNumOperands());
NAKAMURA Takumibde0f0f2013-01-23 08:30:21 +000036 const Use *U = &A->getOperandUse(0);
37 const Use *Ue = &A->getOperandUse(22);
Gabor Greif9a5f90a2012-11-12 10:01:17 +000038 for (; U != Ue; ++U)
39 {
Gabor Greifd5439312012-11-12 13:34:59 +000040 EXPECT_EQ(A, U->getUser());
Gabor Greif9a5f90a2012-11-12 10:01:17 +000041 }
NAKAMURA Takumid422e9f2013-01-23 08:33:05 +000042 delete A;
Gabor Greif9a5f90a2012-11-12 10:01:17 +000043}
44
45TEST(WaymarkTest, TwoBit) {
Gabor Greifd5439312012-11-12 13:34:59 +000046 Use* many = (Use*)calloc(sizeof(Use), 8212 + 1);
Gabor Greif9a5f90a2012-11-12 10:01:17 +000047 ASSERT_TRUE(many);
NAKAMURA Takumibde0f0f2013-01-23 08:30:21 +000048 Use::initTags(many, many + 8212);
Dmitri Gribenko31659fa2013-01-14 21:23:37 +000049 for (Use *U = many, *Ue = many + 8212 - 1; U != Ue; ++U)
Gabor Greif9a5f90a2012-11-12 10:01:17 +000050 {
Dmitri Gribenko31659fa2013-01-14 21:23:37 +000051 EXPECT_EQ(reinterpret_cast<User *>(Ue + 1), U->getUser());
Gabor Greif9a5f90a2012-11-12 10:01:17 +000052 }
NAKAMURA Takumid422e9f2013-01-23 08:33:05 +000053 free(many);
Gabor Greif9a5f90a2012-11-12 10:01:17 +000054}
55
56} // end anonymous namespace
57} // end namespace llvm