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