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