[yaml2obj/obj2yaml] - Add support for .stack_sizes sections.
[llvm-complete.git] / unittests / Analysis / GlobalsModRefTest.cpp
blob113d73fd84d8bf5784001634fefcbdb1a68c1490
1 //===--- GlobalsModRefTest.cpp - Mixed TBAA unit tests --------------------===//
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/GlobalsModRef.h"
10 #include "llvm/AsmParser/Parser.h"
11 #include "llvm/Support/SourceMgr.h"
12 #include "gtest/gtest.h"
14 using namespace llvm;
16 TEST(GlobalsModRef, OptNone) {
17 StringRef Assembly = R"(
18 define void @f1() optnone {
19 ret void
21 define void @f2() optnone readnone {
22 ret void
24 define void @f3() optnone readonly {
25 ret void
27 )";
29 LLVMContext Context;
30 SMDiagnostic Error;
31 auto M = parseAssemblyString(Assembly, Error, Context);
32 ASSERT_TRUE(M) << "Bad assembly?";
34 const auto &funcs = M->functions();
35 auto I = funcs.begin();
36 ASSERT_NE(I, funcs.end());
37 const Function &F1 = *I;
38 ASSERT_NE(++I, funcs.end());
39 const Function &F2 = *I;
40 ASSERT_NE(++I, funcs.end());
41 const Function &F3 = *I;
42 EXPECT_EQ(++I, funcs.end());
44 Triple Trip(M->getTargetTriple());
45 TargetLibraryInfoImpl TLII(Trip);
46 TargetLibraryInfo TLI(TLII);
47 auto GetTLI = [&TLI](Function &F) -> TargetLibraryInfo & { return TLI; };
48 llvm::CallGraph CG(*M);
50 auto AAR = GlobalsAAResult::analyzeModule(*M, GetTLI, CG);
52 EXPECT_EQ(FMRB_UnknownModRefBehavior, AAR.getModRefBehavior(&F1));
53 EXPECT_EQ(FMRB_DoesNotAccessMemory, AAR.getModRefBehavior(&F2));
54 EXPECT_EQ(FMRB_OnlyReadsMemory, AAR.getModRefBehavior(&F3));