Fix test failures introduced by PR #113697 (#116941)
[llvm-project.git] / llvm / unittests / Analysis / GlobalsModRefTest.cpp
blob755997f4d494fc88ebb7a8be46a5bc4658204dd0
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/Analysis/CallGraph.h"
11 #include "llvm/Analysis/TargetLibraryInfo.h"
12 #include "llvm/AsmParser/Parser.h"
13 #include "llvm/IR/Module.h"
14 #include "llvm/Support/SourceMgr.h"
15 #include "llvm/TargetParser/Triple.h"
16 #include "gtest/gtest.h"
18 using namespace llvm;
20 TEST(GlobalsModRef, OptNone) {
21 StringRef Assembly = R"(
22 define void @f1() optnone {
23 ret void
25 define void @f2() optnone readnone {
26 ret void
28 define void @f3() optnone readonly {
29 ret void
31 )";
33 LLVMContext Context;
34 SMDiagnostic Error;
35 auto M = parseAssemblyString(Assembly, Error, Context);
36 ASSERT_TRUE(M) << "Bad assembly?";
38 const auto &funcs = M->functions();
39 auto I = funcs.begin();
40 ASSERT_NE(I, funcs.end());
41 const Function &F1 = *I;
42 ASSERT_NE(++I, funcs.end());
43 const Function &F2 = *I;
44 ASSERT_NE(++I, funcs.end());
45 const Function &F3 = *I;
46 EXPECT_EQ(++I, funcs.end());
48 Triple Trip(M->getTargetTriple());
49 TargetLibraryInfoImpl TLII(Trip);
50 TargetLibraryInfo TLI(TLII);
51 auto GetTLI = [&TLI](Function &F) -> TargetLibraryInfo & { return TLI; };
52 llvm::CallGraph CG(*M);
54 auto AAR = GlobalsAAResult::analyzeModule(*M, GetTLI, CG);
56 EXPECT_EQ(MemoryEffects::unknown(), AAR.getMemoryEffects(&F1));
57 EXPECT_EQ(MemoryEffects::none(), AAR.getMemoryEffects(&F2));
58 EXPECT_EQ(MemoryEffects::readOnly(), AAR.getMemoryEffects(&F3));