Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/MC/MCSymbol.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- lib/MC/MCSymbol.cpp - MCSymbol implementation ----------------------===//
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/MC/MCSymbol.h"
10
#include "llvm/ADT/StringRef.h"
11
#include "llvm/Config/llvm-config.h"
12
#include "llvm/MC/MCAsmInfo.h"
13
#include "llvm/MC/MCContext.h"
14
#include "llvm/MC/MCExpr.h"
15
#include "llvm/MC/MCFragment.h"
16
#include "llvm/Support/Compiler.h"
17
#include "llvm/Support/Debug.h"
18
#include "llvm/Support/ErrorHandling.h"
19
#include "llvm/Support/raw_ostream.h"
20
#include <cassert>
21
#include <cstddef>
22
23
using namespace llvm;
24
25
// Only the address of this fragment is ever actually used.
26
static MCDummyFragment SentinelFragment(nullptr);
27
28
// Sentinel value for the absolute pseudo fragment.
29
MCFragment *MCSymbol::AbsolutePseudoFragment = &SentinelFragment;
30
31
void *MCSymbol::operator new(size_t s, const StringMapEntry<bool> *Name,
32
9.47M
                             MCContext &Ctx) {
33
9.47M
  // We may need more space for a Name to account for alignment.  So allocate
34
9.47M
  // space for the storage type and not the name pointer.
35
9.47M
  size_t Size = s + (Name ? 
sizeof(NameEntryStorageTy)5.07M
:
04.39M
);
36
9.47M
37
9.47M
  // For safety, ensure that the alignment of a pointer is enough for an
38
9.47M
  // MCSymbol.  This also ensures we don't need padding between the name and
39
9.47M
  // symbol.
40
9.47M
  static_assert((unsigned)alignof(MCSymbol) <= alignof(NameEntryStorageTy),
41
9.47M
                "Bad alignment of MCSymbol");
42
9.47M
  void *Storage = Ctx.allocate(Size, alignof(NameEntryStorageTy));
43
9.47M
  NameEntryStorageTy *Start = static_cast<NameEntryStorageTy*>(Storage);
44
9.47M
  NameEntryStorageTy *End = Start + (Name ? 
15.07M
:
04.39M
);
45
9.47M
  return End;
46
9.47M
}
47
48
543k
void MCSymbol::setVariableValue(const MCExpr *Value) {
49
543k
  assert(!IsUsed && "Cannot set a variable that has already been used.");
50
543k
  assert(Value && "Invalid variable value!");
51
543k
  assert((SymbolContents == SymContentsUnset ||
52
543k
          SymbolContents == SymContentsVariable) &&
53
543k
         "Cannot give common/offset symbol a variable value");
54
543k
  this->Value = Value;
55
543k
  SymbolContents = SymContentsVariable;
56
543k
  setUndefined();
57
543k
}
58
59
1.83M
void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
60
1.83M
  // The name for this MCSymbol is required to be a valid target name.  However,
61
1.83M
  // some targets support quoting names with funny characters.  If the name
62
1.83M
  // contains a funny character, then print it quoted.
63
1.83M
  StringRef Name = getName();
64
1.83M
  if (!MAI || 
MAI->isValidUnquotedName(Name)1.82M
) {
65
1.83M
    OS << Name;
66
1.83M
    return;
67
1.83M
  }
68
4.34k
69
4.34k
  if (MAI && !MAI->supportsNameQuoting())
70
0
    report_fatal_error("Symbol name with unsupported characters");
71
4.34k
72
4.34k
  OS << '"';
73
88.7k
  for (char C : Name) {
74
88.7k
    if (C == '\n')
75
4
      OS << "\\n";
76
88.7k
    else if (C == '"')
77
4
      OS << "\\\"";
78
88.7k
    else
79
88.7k
      OS << C;
80
88.7k
  }
81
4.34k
  OS << '"';
82
4.34k
}
83
84
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
85
LLVM_DUMP_METHOD void MCSymbol::dump() const {
86
  dbgs() << *this;
87
}
88
#endif