Coverage Report

Created: 2018-02-28 10:36

/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/Twine.h"
14
#include "llvm/Demangle/Demangle.h"
15
#include <algorithm>
16
#include <cstring>
17
18
using namespace llvm;
19
using namespace lld;
20
using namespace lld::elf;
21
22
229k
StringMatcher::StringMatcher(ArrayRef<StringRef> Pat) {
23
229k
  for (StringRef S : Pat) {
24
229k
    Expected<GlobPattern> Pat = GlobPattern::create(S);
25
229k
    if (!Pat)
26
1
      error(toString(Pat.takeError()));
27
229k
    else
28
229k
      Patterns.push_back(*Pat);
29
229k
  }
30
229k
}
31
32
424k
bool StringMatcher::match(StringRef S) const {
33
424k
  for (const GlobPattern &Pat : Patterns)
34
283k
    if (Pat.match(S))
35
142k
      return true;
36
424k
  
return false282k
;
37
424k
}
38
39
// Converts a hex string (e.g. "deadbeef") to a vector.
40
3
std::vector<uint8_t> elf::parseHex(StringRef S) {
41
3
  std::vector<uint8_t> Hex;
42
15
  while (!S.empty()) {
43
12
    StringRef B = S.substr(0, 2);
44
12
    S = S.substr(2);
45
12
    uint8_t H;
46
12
    if (!to_integer(B, H, 16)) {
47
0
      error("not a hexadecimal value: " + B);
48
0
      return {};
49
0
    }
50
12
    Hex.push_back(H);
51
12
  }
52
3
  return Hex;
53
3
}
54
55
// Returns true if S is valid as a C language identifier.
56
228k
bool elf::isValidCIdentifier(StringRef S) {
57
228k
  return !S.empty() && 
(228k
isAlpha(S[0])228k
||
S[0] == '_'32.1k
) &&
58
228k
         std::all_of(S.begin() + 1, S.end(),
59
2.55M
                     [](char C) { return C == '_' || 
isAlnum(C)2.55M
; });
60
228k
}