1 //===----- AbstractCallSiteTest.cpp - AbstractCallSite Unittests ----------===//
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
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"
18 static std::unique_ptr
<Module
> parseIR(LLVMContext
&C
, const char *IR
) {
20 std::unique_ptr
<Module
> Mod
= parseAssemblyString(IR
, Err
, C
);
22 Err
.print("AbstractCallSiteTests", errs());
26 TEST(AbstractCallSite
, CallbackCall
) {
30 "define void @callback(i8* %X, i32* %A) {\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"
37 "declare !callback !0 void @broker(i32, void (i8*, ...)*, ...)\n"
39 "!1 = !{i64 1, i64 -1, i1 true}";
41 std::unique_ptr
<Module
> M
= parseIR(C
, IR
);
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
);
52 EXPECT_TRUE(ACS
.isCallbackCall());
53 EXPECT_TRUE(ACS
.isCallee(CallbackUse
));
54 EXPECT_EQ(ACS
.getCalledFunction(), Callback
);