blob: 4af3aa707a90e2325c7b339970a518c0051b462b [file] [log] [blame]
Lang Hamesdc4260d2015-04-20 20:41:45 +00001//===- 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) {
Mehdi Amini03b42e42016-04-14 21:59:01 +000020 LLVMContext Context;
21 ModuleBuilder MB(Context, "x86_64-apple-macosx10.10", "");
Lang Hames130a7c42015-10-28 02:40:04 +000022 Function *F = MB.createFunctionDecl<void(DummyStruct, DummyStruct)>("");
Reid Klecknerb5180542017-03-21 16:57:19 +000023 SmallVector<AttributeList, 4> Attrs;
Lang Hamesdc4260d2015-04-20 20:41:45 +000024 Attrs.push_back(
Reid Klecknerb5180542017-03-21 16:57:19 +000025 AttributeList::get(MB.getModule()->getContext(), 1U,
26 AttrBuilder().addAttribute(Attribute::StructRet)));
Lang Hamesdc4260d2015-04-20 20:41:45 +000027 Attrs.push_back(
Reid Klecknerb5180542017-03-21 16:57:19 +000028 AttributeList::get(MB.getModule()->getContext(), 2U,
29 AttrBuilder().addAttribute(Attribute::ByVal)));
Lang Hamesdc4260d2015-04-20 20:41:45 +000030 Attrs.push_back(
Reid Klecknerb5180542017-03-21 16:57:19 +000031 AttributeList::get(MB.getModule()->getContext(), ~0U,
32 AttrBuilder().addAttribute(Attribute::NoUnwind)));
33 F->setAttributes(AttributeList::get(MB.getModule()->getContext(), Attrs));
Lang Hamesdc4260d2015-04-20 20:41:45 +000034
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.";
Reid Klecknerfb502d22017-04-14 20:19:02 +000045 EXPECT_TRUE(Call->paramHasAttr(1U, Attribute::ByVal))
Lang Hamesdc4260d2015-04-20 20:41:45 +000046 << "makeStub should propagate byval attr on 2nd argument.";
47}
48
49}