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