mmc: bcm2835: Fix DMA channel leak on probe error
[linux/fpc-iii.git] / tools / perf / util / c++ / clang-test.cpp
blob7b042a5ebc688104e11f2c11cc1548be43494c7c
1 // SPDX-License-Identifier: GPL-2.0
2 #include "clang.h"
3 #include "clang-c.h"
4 #include "llvm/IR/Function.h"
5 #include "llvm/IR/LLVMContext.h"
7 #include <util-cxx.h>
8 #include <tests/llvm.h>
9 #include <string>
11 class perf_clang_scope {
12 public:
13 explicit perf_clang_scope() {perf_clang__init();}
14 ~perf_clang_scope() {perf_clang__cleanup();}
17 static std::unique_ptr<llvm::Module>
18 __test__clang_to_IR(void)
20 unsigned int kernel_version;
22 if (fetch_kernel_version(&kernel_version, NULL, 0))
23 return std::unique_ptr<llvm::Module>(nullptr);
25 std::string cflag_kver("-DLINUX_VERSION_CODE=" +
26 std::to_string(kernel_version));
28 std::unique_ptr<llvm::Module> M =
29 perf::getModuleFromSource({cflag_kver.c_str()},
30 "perf-test.c",
31 test_llvm__bpf_base_prog);
32 return M;
35 extern "C" {
36 int test__clang_to_IR(void)
38 perf_clang_scope _scope;
40 auto M = __test__clang_to_IR();
41 if (!M)
42 return -1;
43 for (llvm::Function& F : *M)
44 if (F.getName() == "bpf_func__SyS_epoll_pwait")
45 return 0;
46 return -1;
49 int test__clang_to_obj(void)
51 perf_clang_scope _scope;
53 auto M = __test__clang_to_IR();
54 if (!M)
55 return -1;
57 auto Buffer = perf::getBPFObjectFromModule(&*M);
58 if (!Buffer)
59 return -1;
60 return 0;