blob: 2f64fe0ae99e73f7d3d22948d8f80d4587cbf090 [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//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Gabor Greiffea6a552012-11-12 10:01:17 +00006//
7//===----------------------------------------------------------------------===//
8
9// we perform white-box tests
10//
Bob Wilsone4077362013-09-09 19:14:35 +000011#include "llvm/IR/Constants.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000012#include "llvm/IR/Function.h"
13#include "llvm/IR/Instructions.h"
14#include "llvm/IR/LLVMContext.h"
Gabor Greiffea6a552012-11-12 10:01:17 +000015#include "gtest/gtest.h"
16#include <algorithm>
17
18namespace llvm {
19namespace {
20
Gabor Greiffea6a552012-11-12 10:01:17 +000021TEST(WaymarkTest, NativeArray) {
Mehdi Amini03b42e42016-04-14 21:59:01 +000022 LLVMContext Context;
Gabor Greiffea6a552012-11-12 10:01:17 +000023 static uint8_t tail[22] = "s02s33s30y2y0s1x0syxS";
24 Value * values[22];
Mehdi Amini03b42e42016-04-14 21:59:01 +000025 std::transform(tail, tail + 22, values, [&](char c) {
26 return ConstantInt::get(Type::getInt8Ty(Context), c);
27 });
28 FunctionType *FT = FunctionType::get(Type::getVoidTy(Context), true);
Rafael Espindola5c014f52014-12-23 17:20:23 +000029 std::unique_ptr<Function> F(
30 Function::Create(FT, GlobalValue::ExternalLinkage));
31 const CallInst *A = CallInst::Create(F.get(), makeArrayRef(values));
Craig Topper66f09ad2014-06-08 22:29:17 +000032 ASSERT_NE(A, (const CallInst*)nullptr);
Gabor Greiffea6a552012-11-12 10:01:17 +000033 ASSERT_EQ(1U + 22, A->getNumOperands());
NAKAMURA Takumi773f74c2013-01-23 08:30:21 +000034 const Use *U = &A->getOperandUse(0);
35 const Use *Ue = &A->getOperandUse(22);
Gabor Greiffea6a552012-11-12 10:01:17 +000036 for (; U != Ue; ++U)
37 {
Gabor Greifea5fa102012-11-12 13:34:59 +000038 EXPECT_EQ(A, U->getUser());
Gabor Greiffea6a552012-11-12 10:01:17 +000039 }
NAKAMURA Takumi6d951b72013-01-23 08:33:05 +000040 delete A;
Gabor Greiffea6a552012-11-12 10:01:17 +000041}
42
43TEST(WaymarkTest, TwoBit) {
Gabor Greifea5fa102012-11-12 13:34:59 +000044 Use* many = (Use*)calloc(sizeof(Use), 8212 + 1);
Gabor Greiffea6a552012-11-12 10:01:17 +000045 ASSERT_TRUE(many);
NAKAMURA Takumi773f74c2013-01-23 08:30:21 +000046 Use::initTags(many, many + 8212);
Dmitri Gribenkofb37aca2013-01-14 21:23:37 +000047 for (Use *U = many, *Ue = many + 8212 - 1; U != Ue; ++U)
Gabor Greiffea6a552012-11-12 10:01:17 +000048 {
Dmitri Gribenkofb37aca2013-01-14 21:23:37 +000049 EXPECT_EQ(reinterpret_cast<User *>(Ue + 1), U->getUser());
Gabor Greiffea6a552012-11-12 10:01:17 +000050 }
NAKAMURA Takumi6d951b72013-01-23 08:33:05 +000051 free(many);
Gabor Greiffea6a552012-11-12 10:01:17 +000052}
53
54} // end anonymous namespace
55} // end namespace llvm