1 //===- LazyEmittingLayerTest.cpp - Unit tests for the lazy emitting layer -===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/ExecutionEngine/Orc/IndirectionUtils.h"
10 #include "OrcTestCommon.h"
11 #include "llvm/ADT/SmallVector.h"
12 #include "gtest/gtest.h"
18 TEST(IndirectionUtilsTest
, MakeStub
) {
20 ModuleBuilder
MB(Context
, "x86_64-apple-macosx10.10", "");
21 StructType
*ArgTy
= getDummyStructTy(Context
);
22 Type
*ArgPtrTy
= PointerType::getUnqual(ArgTy
);
23 FunctionType
*FTy
= FunctionType::get(
24 Type::getVoidTy(Context
), {ArgPtrTy
, ArgPtrTy
}, false);
25 Function
*F
= MB
.createFunctionDecl(FTy
, "");
26 AttributeSet FnAttrs
= AttributeSet::get(
27 Context
, AttrBuilder(Context
).addAttribute(Attribute::NoUnwind
));
28 AttributeSet RetAttrs
; // None
29 AttributeSet ArgAttrs
[2] = {
30 AttributeSet::get(Context
, AttrBuilder(Context
).addStructRetAttr(ArgTy
)),
31 AttributeSet::get(Context
, AttrBuilder(Context
).addByValAttr(ArgTy
)),
33 F
->setAttributes(AttributeList::get(Context
, FnAttrs
, RetAttrs
, ArgAttrs
));
35 auto ImplPtr
= orc::createImplPointer(*F
->getType(), *MB
.getModule(), "", nullptr);
36 orc::makeStub(*F
, *ImplPtr
);
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.";