IndirectionUtilsTest.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //===- LazyEmittingLayerTest.cpp - Unit tests for the lazy emitting layer -===//
  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 "OrcTestCommon.h"
  10. #include "llvm/ADT/SmallVector.h"
  11. #include "llvm/ExecutionEngine/Orc/IndirectionUtils.h"
  12. #include "gtest/gtest.h"
  13. using namespace llvm;
  14. namespace {
  15. TEST(IndirectionUtilsTest, MakeStub) {
  16. ModuleBuilder MB(getGlobalContext(), "x86_64-apple-macosx10.10", "");
  17. Function *F = MB.createFunctionDecl<void(DummyStruct, DummyStruct)>(MB.getModule(), "");
  18. SmallVector<AttributeSet, 4> Attrs;
  19. Attrs.push_back(
  20. AttributeSet::get(MB.getModule()->getContext(), 1U,
  21. AttrBuilder().addAttribute(Attribute::StructRet)));
  22. Attrs.push_back(
  23. AttributeSet::get(MB.getModule()->getContext(), 2U,
  24. AttrBuilder().addAttribute(Attribute::ByVal)));
  25. Attrs.push_back(
  26. AttributeSet::get(MB.getModule()->getContext(), ~0U,
  27. AttrBuilder().addAttribute(Attribute::NoUnwind)));
  28. F->setAttributes(AttributeSet::get(MB.getModule()->getContext(), Attrs));
  29. auto ImplPtr = orc::createImplPointer(*F->getType(), *MB.getModule(), "", nullptr);
  30. orc::makeStub(*F, *ImplPtr);
  31. auto II = F->getEntryBlock().begin();
  32. EXPECT_TRUE(isa<LoadInst>(*II)) << "First instruction of stub should be a load.";
  33. auto *Call = dyn_cast<CallInst>(std::next(II));
  34. EXPECT_TRUE(Call != nullptr) << "Second instruction of stub should be a call.";
  35. EXPECT_TRUE(Call->isTailCall()) << "Indirect call from stub should be tail call.";
  36. EXPECT_TRUE(Call->hasStructRetAttr())
  37. << "makeStub should propagate sret attr on 1st argument.";
  38. EXPECT_TRUE(Call->paramHasAttr(2U, Attribute::ByVal))
  39. << "makeStub should propagate byval attr on 2nd argument.";
  40. }
  41. }