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 //===----------------------------------------------------------------------===// 8 9 #include "llvm/Analysis/GlobalsModRef.h" 10 #include "llvm/ADT/Triple.h" 11 #include "llvm/Analysis/CallGraph.h" 12 #include "llvm/AsmParser/Parser.h" 13 #include "llvm/Support/SourceMgr.h" 14 #include "gtest/gtest.h" 15 16 using namespace llvm; 17 18 TEST(GlobalsModRef, OptNone) { 19 StringRef Assembly = R"( 20 define void @f1() optnone { 21 ret void 22 } 23 define void @f2() optnone readnone { 24 ret void 25 } 26 define void @f3() optnone readonly { 27 ret void 28 } 29 )"; 30 31 LLVMContext Context; 32 SMDiagnostic Error; 33 auto M = parseAssemblyString(Assembly, Error, Context); 34 ASSERT_TRUE(M) << "Bad assembly?"; 35 36 const auto &funcs = M->functions(); 37 auto I = funcs.begin(); 38 ASSERT_NE(I, funcs.end()); 39 const Function &F1 = *I; 40 ASSERT_NE(++I, funcs.end()); 41 const Function &F2 = *I; 42 ASSERT_NE(++I, funcs.end()); 43 const Function &F3 = *I; 44 EXPECT_EQ(++I, funcs.end()); 45 46 Triple Trip(M->getTargetTriple()); 47 TargetLibraryInfoImpl TLII(Trip); 48 TargetLibraryInfo TLI(TLII); 49 auto GetTLI = [&TLI](Function &F) -> TargetLibraryInfo & { return TLI; }; 50 llvm::CallGraph CG(*M); 51 52 auto AAR = GlobalsAAResult::analyzeModule(*M, GetTLI, CG); 53 54 EXPECT_EQ(FMRB_UnknownModRefBehavior, AAR.getModRefBehavior(&F1)); 55 EXPECT_EQ(FMRB_DoesNotAccessMemory, AAR.getModRefBehavior(&F2)); 56 EXPECT_EQ(FMRB_OnlyReadsMemory, AAR.getModRefBehavior(&F3)); 57 } 58