blob: a8924efed3f5fc72e0595deab247fc6d4359c5a6 [file] [log] [blame]
Chandler Carruth74b6a772013-01-07 15:35:46 +00001//===- llvm/unittest/IR/WaymarkTest.cpp - getUser() unit tests ------------===//
Gabor Greiffea6a552012-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 Wilsone4077362013-09-09 19:14:35 +000012#include "llvm/IR/Constants.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000013#include "llvm/IR/Function.h"
14#include "llvm/IR/Instructions.h"
15#include "llvm/IR/LLVMContext.h"
Gabor Greiffea6a552012-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 Greifea5fa102012-11-12 13:34:59 +000025
Gabor Greiffea6a552012-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 Takumi773f74c2013-01-23 08:30:21 +000031 FunctionType *FT = FunctionType::get(Type::getVoidTy(getGlobalContext()), true);
Rafael Espindola5c014f52014-12-23 17:20:23 +000032 std::unique_ptr<Function> F(
33 Function::Create(FT, GlobalValue::ExternalLinkage));
34 const CallInst *A = CallInst::Create(F.get(), makeArrayRef(values));
Craig Topper66f09ad2014-06-08 22:29:17 +000035 ASSERT_NE(A, (const CallInst*)nullptr);
Gabor Greiffea6a552012-11-12 10:01:17 +000036 ASSERT_EQ(1U + 22, A->getNumOperands());
NAKAMURA Takumi773f74c2013-01-23 08:30:21 +000037 const Use *U = &A->getOperandUse(0);
38 const Use *Ue = &A->getOperandUse(22);
Gabor Greiffea6a552012-11-12 10:01:17 +000039 for (; U != Ue; ++U)
40 {
Gabor Greifea5fa102012-11-12 13:34:59 +000041 EXPECT_EQ(A, U->getUser());
Gabor Greiffea6a552012-11-12 10:01:17 +000042 }
NAKAMURA Takumi6d951b72013-01-23 08:33:05 +000043 delete A;
Gabor Greiffea6a552012-11-12 10:01:17 +000044}
45
46TEST(WaymarkTest, TwoBit) {
Gabor Greifea5fa102012-11-12 13:34:59 +000047 Use* many = (Use*)calloc(sizeof(Use), 8212 + 1);
Gabor Greiffea6a552012-11-12 10:01:17 +000048 ASSERT_TRUE(many);
NAKAMURA Takumi773f74c2013-01-23 08:30:21 +000049 Use::initTags(many, many + 8212);
Dmitri Gribenkofb37aca2013-01-14 21:23:37 +000050 for (Use *U = many, *Ue = many + 8212 - 1; U != Ue; ++U)
Gabor Greiffea6a552012-11-12 10:01:17 +000051 {
Dmitri Gribenkofb37aca2013-01-14 21:23:37 +000052 EXPECT_EQ(reinterpret_cast<User *>(Ue + 1), U->getUser());
Gabor Greiffea6a552012-11-12 10:01:17 +000053 }
NAKAMURA Takumi6d951b72013-01-23 08:33:05 +000054 free(many);
Gabor Greiffea6a552012-11-12 10:01:17 +000055}
56
57} // end anonymous namespace
58} // end namespace llvm