WaymarkTest.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //===- llvm/unittest/IR/WaymarkTest.cpp - getUser() unit tests ------------===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // we perform white-box tests
  9. //
  10. #include "llvm/IR/Constants.h"
  11. #include "llvm/IR/Function.h"
  12. #include "llvm/IR/Instructions.h"
  13. #include "llvm/IR/LLVMContext.h"
  14. #include "gtest/gtest.h"
  15. #include <algorithm>
  16. namespace llvm {
  17. namespace {
  18. TEST(WaymarkTest, NativeArray) {
  19. LLVMContext Context;
  20. static uint8_t tail[22] = "s02s33s30y2y0s1x0syxS";
  21. Value * values[22];
  22. std::transform(tail, tail + 22, values, [&](char c) {
  23. return ConstantInt::get(Type::getInt8Ty(Context), c);
  24. });
  25. FunctionType *FT = FunctionType::get(Type::getVoidTy(Context), true);
  26. std::unique_ptr<Function> F(
  27. Function::Create(FT, GlobalValue::ExternalLinkage));
  28. const CallInst *A = CallInst::Create(F.get(), makeArrayRef(values));
  29. ASSERT_NE(A, (const CallInst*)nullptr);
  30. ASSERT_EQ(1U + 22, A->getNumOperands());
  31. const Use *U = &A->getOperandUse(0);
  32. const Use *Ue = &A->getOperandUse(22);
  33. for (; U != Ue; ++U)
  34. {
  35. EXPECT_EQ(A, U->getUser());
  36. }
  37. delete A;
  38. }
  39. TEST(WaymarkTest, TwoBit) {
  40. Use* many = (Use*)calloc(sizeof(Use), 8212 + 1);
  41. ASSERT_TRUE(many);
  42. Use::initTags(many, many + 8212);
  43. for (Use *U = many, *Ue = many + 8212 - 1; U != Ue; ++U)
  44. {
  45. EXPECT_EQ(reinterpret_cast<User *>(Ue + 1), U->getUser());
  46. }
  47. free(many);
  48. }
  49. } // end anonymous namespace
  50. } // end namespace llvm