Coverage Report

Created: 2026-07-25 06:13

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