Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Passes/PassPlugin.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- lib/Passes/PassPluginLoader.cpp - Load Plugins for New PM Passes ---===//
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/Passes/PassPlugin.h"
10
#include "llvm/Support/raw_ostream.h"
11
12
#include <cstdint>
13
14
using namespace llvm;
15
16
1
Expected<PassPlugin> PassPlugin::Load(const std::string &Filename) {
17
1
  std::string Error;
18
1
  auto Library =
19
1
      sys::DynamicLibrary::getPermanentLibrary(Filename.c_str(), &Error);
20
1
  if (!Library.isValid())
21
0
    return make_error<StringError>(Twine("Could not load library '") +
22
0
                                       Filename + "': " + Error,
23
0
                                   inconvertibleErrorCode());
24
1
25
1
  PassPlugin P{Filename, Library};
26
1
  intptr_t getDetailsFn =
27
1
      (intptr_t)Library.SearchForAddressOfSymbol("llvmGetPassPluginInfo");
28
1
29
1
  if (!getDetailsFn)
30
0
    // If the symbol isn't found, this is probably a legacy plugin, which is an
31
0
    // error
32
0
    return make_error<StringError>(Twine("Plugin entry point not found in '") +
33
0
                                       Filename + "'. Is this a legacy plugin?",
34
0
                                   inconvertibleErrorCode());
35
1
36
1
  P.Info = reinterpret_cast<decltype(llvmGetPassPluginInfo) *>(getDetailsFn)();
37
1
38
1
  if (P.Info.APIVersion != LLVM_PLUGIN_API_VERSION)
39
1
    return make_error<StringError>(
40
0
        Twine("Wrong API version on plugin '") + Filename + "'. Got version " +
41
0
            Twine(P.Info.APIVersion) + ", supported version is " +
42
0
            Twine(LLVM_PLUGIN_API_VERSION) + ".",
43
0
        inconvertibleErrorCode());
44
1
45
1
  if (!P.Info.RegisterPassBuilderCallbacks)
46
0
    return make_error<StringError>(Twine("Empty entry callback in plugin '") +
47
0
                                       Filename + "'.'",
48
0
                                   inconvertibleErrorCode());
49
1
50
1
  return P;
51
1
}