1 //===- llvm/unittest/IR/WaymarkTest.cpp - getUser() unit tests ------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // we perform white-box tests
11 #include "llvm/IR/Constants.h"
12 #include "llvm/IR/Function.h"
13 #include "llvm/IR/Instructions.h"
14 #include "llvm/IR/LLVMContext.h"
15 #include "gtest/gtest.h"
21 TEST(WaymarkTest
, NativeArray
) {
23 static uint8_t tail
[22] = "s02s33s30y2y0s1x0syxS";
25 std::transform(tail
, tail
+ 22, values
, [&](char c
) {
26 return ConstantInt::get(Type::getInt8Ty(Context
), c
);
28 FunctionType
*FT
= FunctionType::get(Type::getVoidTy(Context
), true);
29 std::unique_ptr
<Function
> F(
30 Function::Create(FT
, GlobalValue::ExternalLinkage
));
31 const CallInst
*A
= CallInst::Create(F
.get(), makeArrayRef(values
));
32 ASSERT_NE(A
, (const CallInst
*)nullptr);
33 ASSERT_EQ(1U + 22, A
->getNumOperands());
34 const Use
*U
= &A
->getOperandUse(0);
35 const Use
*Ue
= &A
->getOperandUse(22);
38 EXPECT_EQ(A
, U
->getUser());
43 TEST(WaymarkTest
, TwoBit
) {
44 Use
* many
= (Use
*)calloc(sizeof(Use
), 8212 + 1);
46 Use::initTags(many
, many
+ 8212);
47 for (Use
*U
= many
, *Ue
= many
+ 8212 - 1; U
!= Ue
; ++U
)
49 EXPECT_EQ(reinterpret_cast<User
*>(Ue
+ 1), U
->getUser());
54 } // end anonymous namespace
55 } // end namespace llvm