2013-01-07 23:35:46 +08:00
|
|
|
//===- llvm/unittest/IR/WaymarkTest.cpp - getUser() unit tests ------------===//
|
2012-11-12 18:01:17 +08:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
2012-11-12 18:01:17 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
Constant *char2constant(char c) {
|
|
|
|
return ConstantInt::get(Type::getInt8Ty(getGlobalContext()), c);
|
|
|
|
}
|
2012-11-12 21:34:59 +08:00
|
|
|
|
2012-11-12 18:01:17 +08:00
|
|
|
|
|
|
|
TEST(WaymarkTest, NativeArray) {
|
|
|
|
static uint8_t tail[22] = "s02s33s30y2y0s1x0syxS";
|
|
|
|
Value * values[22];
|
|
|
|
std::transform(tail, tail + 22, values, char2constant);
|
2013-01-23 16:30:21 +08:00
|
|
|
FunctionType *FT = FunctionType::get(Type::getVoidTy(getGlobalContext()), true);
|
2012-11-12 18:01:17 +08:00
|
|
|
Function *F = Function::Create(FT, GlobalValue::ExternalLinkage);
|
2013-01-23 16:30:21 +08:00
|
|
|
const CallInst *A = CallInst::Create(F, makeArrayRef(values));
|
2012-11-12 18:01:17 +08:00
|
|
|
ASSERT_NE(A, (const CallInst*)NULL);
|
|
|
|
ASSERT_EQ(1U + 22, A->getNumOperands());
|
2013-01-23 16:30:21 +08:00
|
|
|
const Use *U = &A->getOperandUse(0);
|
|
|
|
const Use *Ue = &A->getOperandUse(22);
|
2012-11-12 18:01:17 +08:00
|
|
|
for (; U != Ue; ++U)
|
|
|
|
{
|
2012-11-12 21:34:59 +08:00
|
|
|
EXPECT_EQ(A, U->getUser());
|
2012-11-12 18:01:17 +08:00
|
|
|
}
|
2013-01-23 16:33:05 +08:00
|
|
|
delete A;
|
2012-11-12 18:01:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(WaymarkTest, TwoBit) {
|
2012-11-12 21:34:59 +08:00
|
|
|
Use* many = (Use*)calloc(sizeof(Use), 8212 + 1);
|
2012-11-12 18:01:17 +08:00
|
|
|
ASSERT_TRUE(many);
|
2013-01-23 16:30:21 +08:00
|
|
|
Use::initTags(many, many + 8212);
|
2013-01-15 05:23:37 +08:00
|
|
|
for (Use *U = many, *Ue = many + 8212 - 1; U != Ue; ++U)
|
2012-11-12 18:01:17 +08:00
|
|
|
{
|
2013-01-15 05:23:37 +08:00
|
|
|
EXPECT_EQ(reinterpret_cast<User *>(Ue + 1), U->getUser());
|
2012-11-12 18:01:17 +08:00
|
|
|
}
|
2013-01-23 16:33:05 +08:00
|
|
|
free(many);
|
2012-11-12 18:01:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
} // end namespace llvm
|