brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · f4b22e7 Raw
50 lines · cpp
1//===- LazyEmittingLayerTest.cpp - Unit tests for the lazy emitting layer -===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/ExecutionEngine/Orc/IndirectionUtils.h"10#include "OrcTestCommon.h"11#include "llvm/ADT/SmallVector.h"12#include "gtest/gtest.h"13 14using namespace llvm;15 16namespace {17 18TEST(IndirectionUtilsTest, MakeStub) {19  LLVMContext Context;20  ModuleBuilder MB(Context, "x86_64-apple-macosx10.10", "");21  StructType *ArgTy = getDummyStructTy(Context);22  Type *ArgPtrTy = PointerType::getUnqual(Context);23  FunctionType *FTy = FunctionType::get(24      Type::getVoidTy(Context), {ArgPtrTy, ArgPtrTy}, false);25  Function *F = MB.createFunctionDecl(FTy, "");26  AttributeSet FnAttrs = AttributeSet::get(27      Context, AttrBuilder(Context).addAttribute(Attribute::NoUnwind));28  AttributeSet RetAttrs; // None29  AttributeSet ArgAttrs[2] = {30      AttributeSet::get(Context, AttrBuilder(Context).addStructRetAttr(ArgTy)),31      AttributeSet::get(Context, AttrBuilder(Context).addByValAttr(ArgTy)),32  };33  F->setAttributes(AttributeList::get(Context, FnAttrs, RetAttrs, ArgAttrs));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(1U, Attribute::ByVal))46    << "makeStub should propagate byval attr on 2nd argument.";47}48 49}50