Coverage Report

Created: 2018-01-17 17:22

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/lld/ELF/Strings.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- Strings.cpp -------------------------------------------------------===//
2
//
3
//                             The LLVM Linker
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#include "Strings.h"
11
#include "Config.h"
12
#include "lld/Common/ErrorHandler.h"
13
#include "llvm/ADT/ArrayRef.h"
14
#include "llvm/ADT/StringRef.h"
15
#include "llvm/ADT/Twine.h"
16
#include "llvm/Demangle/Demangle.h"
17
#include <algorithm>
18
#include <cstring>
19
20
using namespace llvm;
21
using namespace lld;
22
using namespace lld::elf;
23
24
227k
StringMatcher::StringMatcher(ArrayRef<StringRef> Pat) {
25
227k
  for (StringRef S : Pat) {
26
227k
    Expected<GlobPattern> Pat = GlobPattern::create(S);
27
227k
    if (!Pat)
28
1
      error(toString(Pat.takeError()));
29
227k
    else
30
227k
      Patterns.push_back(*Pat);
31
227k
  }
32
227k
}
33
34
421k
bool StringMatcher::match(StringRef S) const {
35
421k
  for (const GlobPattern &Pat : Patterns)
36
281k
    if (Pat.match(S))
37
141k
      return true;
38
421k
  
return false280k
;
39
421k
}
40
41
// Converts a hex string (e.g. "deadbeef") to a vector.
42
1
std::vector<uint8_t> elf::parseHex(StringRef S) {
43
1
  std::vector<uint8_t> Hex;
44
5
  while (!S.empty()) {
45
4
    StringRef B = S.substr(0, 2);
46
4
    S = S.substr(2);
47
4
    uint8_t H;
48
4
    if (!to_integer(B, H, 16)) {
49
0
      error("not a hexadecimal value: " + B);
50
0
      return {};
51
0
    }
52
4
    Hex.push_back(H);
53
4
  }
54
1
  return Hex;
55
1
}
56
57
// Returns true if S is valid as a C language identifier.
58
226k
bool elf::isValidCIdentifier(StringRef S) {
59
226k
  return !S.empty() && 
(226k
isAlpha(S[0])226k
||
S[0] == '_'30.0k
) &&
60
226k
         std::all_of(S.begin() + 1, S.end(),
61
2.55M
                     [](char C) { return C == '_' || 
isAlnum(C)2.55M
; });
62
226k
}