blob: 4d2671c06c1d9ffa4d6a96cfe2927c82f9d1ac7e [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
Gabor Greif9a5f90a2012-11-12 10:01:17 +000022TEST(WaymarkTest, NativeArray) {
Mehdi Amini8be77072016-04-14 21:59:01 +000023 LLVMContext Context;
Gabor Greif9a5f90a2012-11-12 10:01:17 +000024 static uint8_t tail[22] = "s02s33s30y2y0s1x0syxS";
25 Value * values[22];
Mehdi Amini8be77072016-04-14 21:59:01 +000026 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);
Rafael Espindola1871cba2014-12-23 17:20:23 +000030 std::unique_ptr<Function> F(
31 Function::Create(FT, GlobalValue::ExternalLinkage));
32 const CallInst *A = CallInst::Create(F.get(), makeArrayRef(values));
Craig Topperb1770412014-06-08 22:29:17 +000033 ASSERT_NE(A, (const CallInst*)nullptr);
Gabor Greif9a5f90a2012-11-12 10:01:17 +000034 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 }
NAKAMURA Takumid422e9f2013-01-23 08:33:05 +000041 delete A;
Gabor Greif9a5f90a2012-11-12 10:01:17 +000042}
43
44TEST(WaymarkTest, TwoBit) {
Gabor Greifd5439312012-11-12 13:34:59 +000045 Use* many = (Use*)calloc(sizeof(Use), 8212 + 1);
Gabor Greif9a5f90a2012-11-12 10:01:17 +000046 ASSERT_TRUE(many);
NAKAMURA Takumibde0f0f2013-01-23 08:30:21 +000047 Use::initTags(many, many + 8212);
Dmitri Gribenko31659fa2013-01-14 21:23:37 +000048 for (Use *U = many, *Ue = many + 8212 - 1; U != Ue; ++U)
Gabor Greif9a5f90a2012-11-12 10:01:17 +000049 {
Dmitri Gribenko31659fa2013-01-14 21:23:37 +000050 EXPECT_EQ(reinterpret_cast<User *>(Ue + 1), U->getUser());
Gabor Greif9a5f90a2012-11-12 10:01:17 +000051 }
NAKAMURA Takumid422e9f2013-01-23 08:33:05 +000052 free(many);
Gabor Greif9a5f90a2012-11-12 10:01:17 +000053}
54
55} // end anonymous namespace
56} // end namespace llvm