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 15using namespace llvm; 16 17namespace { 18 19TEST(IndirectionUtilsTest, MakeStub) { 20 LLVMContext Context; 21 ModuleBuilder MB(Context, "x86_64-apple-macosx10.10", ""); 22 Function *F = MB.createFunctionDecl<void(DummyStruct, DummyStruct)>(""); 23 SmallVector<AttributeSet, 4> Attrs; 24 Attrs.push_back( 25 AttributeSet::get(MB.getModule()->getContext(), 1U, 26 AttrBuilder().addAttribute(Attribute::StructRet))); 27 Attrs.push_back( 28 AttributeSet::get(MB.getModule()->getContext(), 2U, 29 AttrBuilder().addAttribute(Attribute::ByVal))); 30 Attrs.push_back( 31 AttributeSet::get(MB.getModule()->getContext(), ~0U, 32 AttrBuilder().addAttribute(Attribute::NoUnwind))); 33 F->setAttributes(AttributeSet::get(MB.getModule()->getContext(), Attrs)); 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(2U, Attribute::ByVal)) 46 << "makeStub should propagate byval attr on 2nd argument."; 47} 48 49} 50