Bump version to 19.1.0-rc3
[llvm-project.git] / llvm / unittests / IR / AbstractCallSiteTest.cpp
blobddb10911ad0284371efa92555fb970e5637babc1
1 //===----- AbstractCallSiteTest.cpp - AbstractCallSite Unittests ----------===//
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/AsmParser/Parser.h"
10 #include "llvm/IR/AbstractCallSite.h"
11 #include "llvm/IR/Function.h"
12 #include "llvm/IR/Module.h"
13 #include "llvm/Support/SourceMgr.h"
14 #include "gtest/gtest.h"
16 using namespace llvm;
18 static std::unique_ptr<Module> parseIR(LLVMContext &C, const char *IR) {
19 SMDiagnostic Err;
20 std::unique_ptr<Module> Mod = parseAssemblyString(IR, Err, C);
21 if (!Mod)
22 Err.print("AbstractCallSiteTests", errs());
23 return Mod;
26 TEST(AbstractCallSite, CallbackCall) {
27 LLVMContext C;
29 const char *IR =
30 "define void @callback(i8* %X, i32* %A) {\n"
31 " ret void\n"
32 "}\n"
33 "define void @foo(i32* %A) {\n"
34 " call void (i32, void (i8*, ...)*, ...) @broker(i32 1, void (i8*, ...)* bitcast (void (i8*, i32*)* @callback to void (i8*, ...)*), i32* %A)\n"
35 " ret void\n"
36 "}\n"
37 "declare !callback !0 void @broker(i32, void (i8*, ...)*, ...)\n"
38 "!0 = !{!1}\n"
39 "!1 = !{i64 1, i64 -1, i1 true}";
41 std::unique_ptr<Module> M = parseIR(C, IR);
42 ASSERT_TRUE(M);
44 Function *Callback = M->getFunction("callback");
45 ASSERT_NE(Callback, nullptr);
47 const Use *CallbackUse = Callback->getSingleUndroppableUse();
48 ASSERT_NE(CallbackUse, nullptr);
50 AbstractCallSite ACS(CallbackUse);
51 EXPECT_TRUE(ACS);
52 EXPECT_TRUE(ACS.isCallbackCall());
53 EXPECT_TRUE(ACS.isCallee(CallbackUse));
54 EXPECT_EQ(ACS.getCalledFunction(), Callback);