blob: ed425449784cbff36d28336b83e40b82b5aba720 [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
Chandler Carruth9a67b072017-06-06 11:06:56 +000010#include "llvm/ExecutionEngine/Orc/IndirectionUtils.h"
Lang Hamesdc4260d2015-04-20 20:41:45 +000011#include "OrcTestCommon.h"
12#include "llvm/ADT/SmallVector.h"
Lang Hamesdc4260d2015-04-20 20:41:45 +000013#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 Klecknera0b45f42017-05-03 18:17:31 +000023 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 Hamesdc4260d2015-04-20 20:41:45 +000032
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 Klecknerfb502d22017-04-14 20:19:02 +000043 EXPECT_TRUE(Call->paramHasAttr(1U, Attribute::ByVal))
Lang Hamesdc4260d2015-04-20 20:41:45 +000044 << "makeStub should propagate byval attr on 2nd argument.";
45}
46
47}