WaymarkTest.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //===- llvm/unittest/IR/WaymarkTest.cpp - getUser() unit tests ------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #include "llvm/IR/Constants.h"
  10. #include "llvm/IR/Function.h"
  11. #include "llvm/IR/Instructions.h"
  12. #include "llvm/IR/LLVMContext.h"
  13. #include "gtest/gtest.h"
  14. #include <algorithm>
  15. namespace llvm {
  16. namespace {
  17. Constant *char2constant(char c) {
  18. return ConstantInt::get(Type::getInt8Ty(getGlobalContext()), c);
  19. }
  20. TEST(WaymarkTest, NativeArray) {
  21. static uint8_t tail[22] = "s02s33s30y2y0s1x0syxS";
  22. Value * values[22];
  23. std::transform(tail, tail + 22, values, char2constant);
  24. FunctionType *FT = FunctionType::get(Type::getVoidTy(getGlobalContext()), true);
  25. std::unique_ptr<Function> F(
  26. Function::Create(FT, GlobalValue::ExternalLinkage));
  27. const CallInst *A = CallInst::Create(F.get(), makeArrayRef(values));
  28. ASSERT_NE(A, (const CallInst*)nullptr);
  29. ASSERT_EQ(1U + 22, A->getNumOperands());
  30. const Use *U = &A->getOperandUse(0);
  31. const Use *Ue = &A->getOperandUse(22);
  32. for (; U != Ue; ++U)
  33. {
  34. EXPECT_EQ(A, U->getUser());
  35. }
  36. delete A;
  37. }
  38. TEST(WaymarkTest, TwoBit) {
  39. Use* many = (Use*)calloc(sizeof(Use), 8212 + 1);
  40. ASSERT_TRUE(many);
  41. Use::initTags(many, many + 8212);
  42. for (Use *U = many, *Ue = many + 8212 - 1; U != Ue; ++U)
  43. {
  44. EXPECT_EQ(reinterpret_cast<User *>(Ue + 1), U->getUser());
  45. }
  46. free(many);
  47. }
  48. } // end anonymous namespace
  49. } // end namespace llvm