[ARM] Masked load and store and predicate tests. NFC
[llvm-complete.git] / unittests / Analysis / MemoryBuiltinsTest.cpp
blob575b7f32047372e4af1e1aab05023ce197039242
1 //===- MemoryBuiltinsTest.cpp - Tests for utilities in MemoryBuiltins.h ---===//
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-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "llvm/Analysis/MemoryBuiltins.h"
10 #include "llvm/IR/Attributes.h"
11 #include "llvm/IR/Constants.h"
12 #include "llvm/IR/Function.h"
13 #include "llvm/IR/LLVMContext.h"
14 #include "llvm/IR/Module.h"
15 #include "gtest/gtest.h"
17 using namespace llvm;
19 namespace {
20 // allocsize should not imply that a function is a traditional allocation
21 // function (e.g. that can be optimized out/...); it just tells us how many
22 // bytes exist at the pointer handed back by the function.
23 TEST(AllocSize, AllocationBuiltinsTest) {
24 LLVMContext Context;
25 Module M("", Context);
26 IntegerType *ArgTy = Type::getInt32Ty(Context);
28 Function *AllocSizeFn = Function::Create(
29 FunctionType::get(Type::getInt8PtrTy(Context), {ArgTy}, false),
30 GlobalValue::ExternalLinkage, "F", &M);
32 AllocSizeFn->addFnAttr(Attribute::getWithAllocSizeArgs(Context, 1, None));
34 // 100 is arbitrary.
35 std::unique_ptr<CallInst> Caller(
36 CallInst::Create(AllocSizeFn, {ConstantInt::get(ArgTy, 100)}));
38 const TargetLibraryInfo *TLI = nullptr;
39 EXPECT_FALSE(isNoAliasFn(Caller.get(), TLI));
40 EXPECT_FALSE(isMallocLikeFn(Caller.get(), TLI));
41 EXPECT_FALSE(isCallocLikeFn(Caller.get(), TLI));
42 EXPECT_FALSE(isAllocLikeFn(Caller.get(), TLI));
44 // FIXME: We might be able to treat allocsize functions as general allocation
45 // functions. For the moment, being conservative seems better (and we'd have
46 // to plumb stuff around `isNoAliasFn`).
47 EXPECT_FALSE(isAllocationFn(Caller.get(), TLI));