Chandler Carruth | 74b6a77 | 2013-01-07 15:35:46 +0000 | [diff] [blame] | 1 | //===- llvm/unittest/IR/WaymarkTest.cpp - getUser() unit tests ------------===// |
Gabor Greif | fea6a55 | 2012-11-12 10:01:17 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
Gabor Greif | fea6a55 | 2012-11-12 10:01:17 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // we perform white-box tests |
| 10 | // |
Bob Wilson | e407736 | 2013-09-09 19:14:35 +0000 | [diff] [blame] | 11 | #include "llvm/IR/Constants.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 12 | #include "llvm/IR/Function.h" |
| 13 | #include "llvm/IR/Instructions.h" |
| 14 | #include "llvm/IR/LLVMContext.h" |
Gabor Greif | fea6a55 | 2012-11-12 10:01:17 +0000 | [diff] [blame] | 15 | #include "gtest/gtest.h" |
| 16 | #include <algorithm> |
| 17 | |
| 18 | namespace llvm { |
| 19 | namespace { |
| 20 | |
Gabor Greif | fea6a55 | 2012-11-12 10:01:17 +0000 | [diff] [blame] | 21 | TEST(WaymarkTest, NativeArray) { |
Mehdi Amini | 03b42e4 | 2016-04-14 21:59:01 +0000 | [diff] [blame] | 22 | LLVMContext Context; |
Gabor Greif | fea6a55 | 2012-11-12 10:01:17 +0000 | [diff] [blame] | 23 | static uint8_t tail[22] = "s02s33s30y2y0s1x0syxS"; |
| 24 | Value * values[22]; |
Mehdi Amini | 03b42e4 | 2016-04-14 21:59:01 +0000 | [diff] [blame] | 25 | 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 Espindola | 5c014f5 | 2014-12-23 17:20:23 +0000 | [diff] [blame] | 29 | std::unique_ptr<Function> F( |
| 30 | Function::Create(FT, GlobalValue::ExternalLinkage)); |
| 31 | const CallInst *A = CallInst::Create(F.get(), makeArrayRef(values)); |
Craig Topper | 66f09ad | 2014-06-08 22:29:17 +0000 | [diff] [blame] | 32 | ASSERT_NE(A, (const CallInst*)nullptr); |
Gabor Greif | fea6a55 | 2012-11-12 10:01:17 +0000 | [diff] [blame] | 33 | ASSERT_EQ(1U + 22, A->getNumOperands()); |
NAKAMURA Takumi | 773f74c | 2013-01-23 08:30:21 +0000 | [diff] [blame] | 34 | const Use *U = &A->getOperandUse(0); |
| 35 | const Use *Ue = &A->getOperandUse(22); |
Gabor Greif | fea6a55 | 2012-11-12 10:01:17 +0000 | [diff] [blame] | 36 | for (; U != Ue; ++U) |
| 37 | { |
Gabor Greif | ea5fa10 | 2012-11-12 13:34:59 +0000 | [diff] [blame] | 38 | EXPECT_EQ(A, U->getUser()); |
Gabor Greif | fea6a55 | 2012-11-12 10:01:17 +0000 | [diff] [blame] | 39 | } |
NAKAMURA Takumi | 6d951b7 | 2013-01-23 08:33:05 +0000 | [diff] [blame] | 40 | delete A; |
Gabor Greif | fea6a55 | 2012-11-12 10:01:17 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | TEST(WaymarkTest, TwoBit) { |
Gabor Greif | ea5fa10 | 2012-11-12 13:34:59 +0000 | [diff] [blame] | 44 | Use* many = (Use*)calloc(sizeof(Use), 8212 + 1); |
Gabor Greif | fea6a55 | 2012-11-12 10:01:17 +0000 | [diff] [blame] | 45 | ASSERT_TRUE(many); |
NAKAMURA Takumi | 773f74c | 2013-01-23 08:30:21 +0000 | [diff] [blame] | 46 | Use::initTags(many, many + 8212); |
Dmitri Gribenko | fb37aca | 2013-01-14 21:23:37 +0000 | [diff] [blame] | 47 | for (Use *U = many, *Ue = many + 8212 - 1; U != Ue; ++U) |
Gabor Greif | fea6a55 | 2012-11-12 10:01:17 +0000 | [diff] [blame] | 48 | { |
Dmitri Gribenko | fb37aca | 2013-01-14 21:23:37 +0000 | [diff] [blame] | 49 | EXPECT_EQ(reinterpret_cast<User *>(Ue + 1), U->getUser()); |
Gabor Greif | fea6a55 | 2012-11-12 10:01:17 +0000 | [diff] [blame] | 50 | } |
NAKAMURA Takumi | 6d951b7 | 2013-01-23 08:33:05 +0000 | [diff] [blame] | 51 | free(many); |
Gabor Greif | fea6a55 | 2012-11-12 10:01:17 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | } // end anonymous namespace |
| 55 | } // end namespace llvm |