Lang Hames | dc4260d | 2015-04-20 20:41:45 +0000 | [diff] [blame] | 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 | |
Chandler Carruth | 9a67b07 | 2017-06-06 11:06:56 +0000 | [diff] [blame] | 10 | #include "llvm/ExecutionEngine/Orc/IndirectionUtils.h" |
Lang Hames | dc4260d | 2015-04-20 20:41:45 +0000 | [diff] [blame] | 11 | #include "OrcTestCommon.h" |
| 12 | #include "llvm/ADT/SmallVector.h" |
Lang Hames | dc4260d | 2015-04-20 20:41:45 +0000 | [diff] [blame] | 13 | #include "gtest/gtest.h" |
| 14 | |
| 15 | using namespace llvm; |
| 16 | |
| 17 | namespace { |
| 18 | |
| 19 | TEST(IndirectionUtilsTest, MakeStub) { |
Mehdi Amini | 03b42e4 | 2016-04-14 21:59:01 +0000 | [diff] [blame] | 20 | LLVMContext Context; |
| 21 | ModuleBuilder MB(Context, "x86_64-apple-macosx10.10", ""); |
Lang Hames | 130a7c4 | 2015-10-28 02:40:04 +0000 | [diff] [blame] | 22 | Function *F = MB.createFunctionDecl<void(DummyStruct, DummyStruct)>(""); |
Reid Kleckner | a0b45f4 | 2017-05-03 18:17:31 +0000 | [diff] [blame] | 23 | AttributeSet FnAttrs = AttributeSet::get( |
| 24 | Context, AttrBuilder().addAttribute(Attribute::NoUnwind)); |
| 25 | AttributeSet RetAttrs; // None |
| 26 | AttributeSet ArgAttrs[2] = { |
| 27 | AttributeSet::get(Context, |
| 28 | AttrBuilder().addAttribute(Attribute::StructRet)), |
| 29 | AttributeSet::get(Context, AttrBuilder().addAttribute(Attribute::ByVal)), |
| 30 | }; |
| 31 | F->setAttributes(AttributeList::get(Context, FnAttrs, RetAttrs, ArgAttrs)); |
Lang Hames | dc4260d | 2015-04-20 20:41:45 +0000 | [diff] [blame] | 32 | |
| 33 | auto ImplPtr = orc::createImplPointer(*F->getType(), *MB.getModule(), "", nullptr); |
| 34 | orc::makeStub(*F, *ImplPtr); |
| 35 | |
| 36 | auto II = F->getEntryBlock().begin(); |
| 37 | EXPECT_TRUE(isa<LoadInst>(*II)) << "First instruction of stub should be a load."; |
| 38 | auto *Call = dyn_cast<CallInst>(std::next(II)); |
| 39 | EXPECT_TRUE(Call != nullptr) << "Second instruction of stub should be a call."; |
| 40 | EXPECT_TRUE(Call->isTailCall()) << "Indirect call from stub should be tail call."; |
| 41 | EXPECT_TRUE(Call->hasStructRetAttr()) |
| 42 | << "makeStub should propagate sret attr on 1st argument."; |
Reid Kleckner | fb502d2 | 2017-04-14 20:19:02 +0000 | [diff] [blame] | 43 | EXPECT_TRUE(Call->paramHasAttr(1U, Attribute::ByVal)) |
Lang Hames | dc4260d | 2015-04-20 20:41:45 +0000 | [diff] [blame] | 44 | << "makeStub should propagate byval attr on 2nd argument."; |
| 45 | } |
| 46 | |
| 47 | } |