Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Support/PluginLoader.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- PluginLoader.cpp - Implement -load command line option ------------===//
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
// This file implements the -load <plugin> command line option handler.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#define DONT_GET_PLUGIN_LOADER_OPTION
14
#include "llvm/Support/PluginLoader.h"
15
#include "llvm/Support/DynamicLibrary.h"
16
#include "llvm/Support/ManagedStatic.h"
17
#include "llvm/Support/Mutex.h"
18
#include "llvm/Support/raw_ostream.h"
19
#include <vector>
20
using namespace llvm;
21
22
static ManagedStatic<std::vector<std::string> > Plugins;
23
static ManagedStatic<sys::SmartMutex<true> > PluginsLock;
24
25
107
void PluginLoader::operator=(const std::string &Filename) {
26
107
  sys::SmartScopedLock<true> Lock(*PluginsLock);
27
107
  std::string Error;
28
107
  if (sys::DynamicLibrary::LoadLibraryPermanently(Filename.c_str(), &Error)) {
29
0
    errs() << "Error opening '" << Filename << "': " << Error
30
0
           << "\n  -load request ignored.\n";
31
107
  } else {
32
107
    Plugins->push_back(Filename);
33
107
  }
34
107
}
35
36
253
unsigned PluginLoader::getNumPlugins() {
37
253
  sys::SmartScopedLock<true> Lock(*PluginsLock);
38
253
  return Plugins.isConstructed() ? Plugins->size() : 
00
;
39
253
}
40
41
253
std::string &PluginLoader::getPlugin(unsigned num) {
42
253
  sys::SmartScopedLock<true> Lock(*PluginsLock);
43
253
  assert(Plugins.isConstructed() && num < Plugins->size() &&
44
253
         "Asking for an out of bounds plugin");
45
253
  return (*Plugins)[num];
46
253
}