IndirectionUtilsTest.cpp 1.9 KB

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