Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Demangle/MicrosoftDemangle.h
Line
Count
Source
1
//===------------------------- MicrosoftDemangle.h --------------*- C++ -*-===//
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
#ifndef LLVM_DEMANGLE_MICROSOFT_DEMANGLE_H
10
#define LLVM_DEMANGLE_MICROSOFT_DEMANGLE_H
11
12
#include "llvm/Demangle/DemangleConfig.h"
13
#include "llvm/Demangle/MicrosoftDemangleNodes.h"
14
#include "llvm/Demangle/StringView.h"
15
#include "llvm/Demangle/Utility.h"
16
17
#include <utility>
18
19
namespace llvm {
20
namespace ms_demangle {
21
// This memory allocator is extremely fast, but it doesn't call dtors
22
// for allocated objects. That means you can't use STL containers
23
// (such as std::vector) with this allocator. But it pays off --
24
// the demangler is 3x faster with this allocator compared to one with
25
// STL containers.
26
constexpr size_t AllocUnit = 4096;
27
28
class ArenaAllocator {
29
  struct AllocatorNode {
30
    uint8_t *Buf = nullptr;
31
    size_t Used = 0;
32
    size_t Capacity = 0;
33
    AllocatorNode *Next = nullptr;
34
  };
35
36
1.31k
  void addNode(size_t Capacity) {
37
1.31k
    AllocatorNode *NewHead = new AllocatorNode;
38
1.31k
    NewHead->Buf = new uint8_t[Capacity];
39
1.31k
    NewHead->Next = Head;
40
1.31k
    NewHead->Capacity = Capacity;
41
1.31k
    Head = NewHead;
42
1.31k
    NewHead->Used = 0;
43
1.31k
  }
44
45
public:
46
1.30k
  ArenaAllocator() { addNode(AllocUnit); }
47
48
1.30k
  ~ArenaAllocator() {
49
2.61k
    while (Head) {
50
1.31k
      assert(Head->Buf);
51
1.31k
      delete[] Head->Buf;
52
1.31k
      AllocatorNode *Next = Head->Next;
53
1.31k
      delete Head;
54
1.31k
      Head = Next;
55
1.31k
    }
56
1.30k
  }
57
58
681
  char *allocUnalignedBuffer(size_t Size) {
59
681
    assert(Head && Head->Buf);
60
681
61
681
    uint8_t *P = Head->Buf + Head->Used;
62
681
63
681
    Head->Used += Size;
64
681
    if (Head->Used <= Head->Capacity)
65
680
      return reinterpret_cast<char *>(P);
66
1
67
1
    addNode(std::max(AllocUnit, Size));
68
1
    Head->Used = Size;
69
1
    return reinterpret_cast<char *>(Head->Buf);
70
1
  }
71
72
2.16k
  template <typename T, typename... Args> T *allocArray(size_t Count) {
73
2.16k
    size_t Size = Count * sizeof(T);
74
2.16k
    assert(Head && Head->Buf);
75
2.16k
76
2.16k
    size_t P = (size_t)Head->Buf + Head->Used;
77
2.16k
    uintptr_t AlignedP =
78
2.16k
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
79
2.16k
    uint8_t *PP = (uint8_t *)AlignedP;
80
2.16k
    size_t Adjustment = AlignedP - P;
81
2.16k
82
2.16k
    Head->Used += Size + Adjustment;
83
2.16k
    if (Head->Used <= Head->Capacity)
84
2.16k
      return new (PP) T[Count]();
85
1
86
1
    addNode(std::max(AllocUnit, Size));
87
1
    Head->Used = Size;
88
1
    return new (Head->Buf) T[Count]();
89
1
  }
90
91
16.3k
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
16.3k
    constexpr size_t Size = sizeof(T);
93
16.3k
    assert(Head && Head->Buf);
94
16.3k
95
16.3k
    size_t P = (size_t)Head->Buf + Head->Used;
96
16.3k
    uintptr_t AlignedP =
97
16.3k
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
16.3k
    uint8_t *PP = (uint8_t *)AlignedP;
99
16.3k
    size_t Adjustment = AlignedP - P;
100
16.3k
101
16.3k
    Head->Used += Size + Adjustment;
102
16.3k
    if (Head->Used <= Head->Capacity)
103
16.3k
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
8
105
8
    static_assert(Size < AllocUnit, "");
106
8
    addNode(AllocUnit);
107
8
    Head->Used = Size;
108
8
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
8
  }
llvm::ms_demangle::NodeArrayNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::NodeArrayNode>()
Line
Count
Source
91
2.16k
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
2.16k
    constexpr size_t Size = sizeof(T);
93
2.16k
    assert(Head && Head->Buf);
94
2.16k
95
2.16k
    size_t P = (size_t)Head->Buf + Head->Used;
96
2.16k
    uintptr_t AlignedP =
97
2.16k
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
2.16k
    uint8_t *PP = (uint8_t *)AlignedP;
99
2.16k
    size_t Adjustment = AlignedP - P;
100
2.16k
101
2.16k
    Head->Used += Size + Adjustment;
102
2.16k
    if (Head->Used <= Head->Capacity)
103
2.16k
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::NamedIdentifierNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::NamedIdentifierNode>()
Line
Count
Source
91
4.03k
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
4.03k
    constexpr size_t Size = sizeof(T);
93
4.03k
    assert(Head && Head->Buf);
94
4.03k
95
4.03k
    size_t P = (size_t)Head->Buf + Head->Used;
96
4.03k
    uintptr_t AlignedP =
97
4.03k
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
4.03k
    uint8_t *PP = (uint8_t *)AlignedP;
99
4.03k
    size_t Adjustment = AlignedP - P;
100
4.03k
101
4.03k
    Head->Used += Size + Adjustment;
102
4.03k
    if (Head->Used <= Head->Capacity)
103
4.03k
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
7
105
7
    static_assert(Size < AllocUnit, "");
106
7
    addNode(AllocUnit);
107
7
    Head->Used = Size;
108
7
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
7
  }
llvm::ms_demangle::SpecialTableSymbolNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::SpecialTableSymbolNode>()
Line
Count
Source
91
9
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
9
    constexpr size_t Size = sizeof(T);
93
9
    assert(Head && Head->Buf);
94
9
95
9
    size_t P = (size_t)Head->Buf + Head->Used;
96
9
    uintptr_t AlignedP =
97
9
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
9
    uint8_t *PP = (uint8_t *)AlignedP;
99
9
    size_t Adjustment = AlignedP - P;
100
9
101
9
    Head->Used += Size + Adjustment;
102
9
    if (Head->Used <= Head->Capacity)
103
9
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::LocalStaticGuardIdentifierNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::LocalStaticGuardIdentifierNode>()
Line
Count
Source
91
3
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
3
    constexpr size_t Size = sizeof(T);
93
3
    assert(Head && Head->Buf);
94
3
95
3
    size_t P = (size_t)Head->Buf + Head->Used;
96
3
    uintptr_t AlignedP =
97
3
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
3
    uint8_t *PP = (uint8_t *)AlignedP;
99
3
    size_t Adjustment = AlignedP - P;
100
3
101
3
    Head->Used += Size + Adjustment;
102
3
    if (Head->Used <= Head->Capacity)
103
3
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::LocalStaticGuardVariableNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::LocalStaticGuardVariableNode>()
Line
Count
Source
91
3
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
3
    constexpr size_t Size = sizeof(T);
93
3
    assert(Head && Head->Buf);
94
3
95
3
    size_t P = (size_t)Head->Buf + Head->Used;
96
3
    uintptr_t AlignedP =
97
3
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
3
    uint8_t *PP = (uint8_t *)AlignedP;
99
3
    size_t Adjustment = AlignedP - P;
100
3
101
3
    Head->Used += Size + Adjustment;
102
3
    if (Head->Used <= Head->Capacity)
103
3
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::QualifiedNameNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::QualifiedNameNode>()
Line
Count
Source
91
1.38k
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
1.38k
    constexpr size_t Size = sizeof(T);
93
1.38k
    assert(Head && Head->Buf);
94
1.38k
95
1.38k
    size_t P = (size_t)Head->Buf + Head->Used;
96
1.38k
    uintptr_t AlignedP =
97
1.38k
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
1.38k
    uint8_t *PP = (uint8_t *)AlignedP;
99
1.38k
    size_t Adjustment = AlignedP - P;
100
1.38k
101
1.38k
    Head->Used += Size + Adjustment;
102
1.38k
    if (Head->Used <= Head->Capacity)
103
1.38k
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::VariableSymbolNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::VariableSymbolNode>()
Line
Count
Source
91
194
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
194
    constexpr size_t Size = sizeof(T);
93
194
    assert(Head && Head->Buf);
94
194
95
194
    size_t P = (size_t)Head->Buf + Head->Used;
96
194
    uintptr_t AlignedP =
97
194
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
194
    uint8_t *PP = (uint8_t *)AlignedP;
99
194
    size_t Adjustment = AlignedP - P;
100
194
101
194
    Head->Used += Size + Adjustment;
102
194
    if (Head->Used <= Head->Capacity)
103
193
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
1
105
1
    static_assert(Size < AllocUnit, "");
106
1
    addNode(AllocUnit);
107
1
    Head->Used = Size;
108
1
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
1
  }
llvm::ms_demangle::RttiBaseClassDescriptorNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::RttiBaseClassDescriptorNode>()
Line
Count
Source
91
2
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
2
    constexpr size_t Size = sizeof(T);
93
2
    assert(Head && Head->Buf);
94
2
95
2
    size_t P = (size_t)Head->Buf + Head->Used;
96
2
    uintptr_t AlignedP =
97
2
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
2
    uint8_t *PP = (uint8_t *)AlignedP;
99
2
    size_t Adjustment = AlignedP - P;
100
2
101
2
    Head->Used += Size + Adjustment;
102
2
    if (Head->Used <= Head->Capacity)
103
2
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::DynamicStructorIdentifierNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::DynamicStructorIdentifierNode>()
Line
Count
Source
91
9
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
9
    constexpr size_t Size = sizeof(T);
93
9
    assert(Head && Head->Buf);
94
9
95
9
    size_t P = (size_t)Head->Buf + Head->Used;
96
9
    uintptr_t AlignedP =
97
9
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
9
    uint8_t *PP = (uint8_t *)AlignedP;
99
9
    size_t Adjustment = AlignedP - P;
100
9
101
9
    Head->Used += Size + Adjustment;
102
9
    if (Head->Used <= Head->Capacity)
103
9
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::StructorIdentifierNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::StructorIdentifierNode>()
Line
Count
Source
91
77
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
77
    constexpr size_t Size = sizeof(T);
93
77
    assert(Head && Head->Buf);
94
77
95
77
    size_t P = (size_t)Head->Buf + Head->Used;
96
77
    uintptr_t AlignedP =
97
77
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
77
    uint8_t *PP = (uint8_t *)AlignedP;
99
77
    size_t Adjustment = AlignedP - P;
100
77
101
77
    Head->Used += Size + Adjustment;
102
77
    if (Head->Used <= Head->Capacity)
103
77
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::ConversionOperatorIdentifierNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::ConversionOperatorIdentifierNode>()
Line
Count
Source
91
22
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
22
    constexpr size_t Size = sizeof(T);
93
22
    assert(Head && Head->Buf);
94
22
95
22
    size_t P = (size_t)Head->Buf + Head->Used;
96
22
    uintptr_t AlignedP =
97
22
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
22
    uint8_t *PP = (uint8_t *)AlignedP;
99
22
    size_t Adjustment = AlignedP - P;
100
22
101
22
    Head->Used += Size + Adjustment;
102
22
    if (Head->Used <= Head->Capacity)
103
22
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::LiteralOperatorIdentifierNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::LiteralOperatorIdentifierNode>()
Line
Count
Source
91
2
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
2
    constexpr size_t Size = sizeof(T);
93
2
    assert(Head && Head->Buf);
94
2
95
2
    size_t P = (size_t)Head->Buf + Head->Used;
96
2
    uintptr_t AlignedP =
97
2
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
2
    uint8_t *PP = (uint8_t *)AlignedP;
99
2
    size_t Adjustment = AlignedP - P;
100
2
101
2
    Head->Used += Size + Adjustment;
102
2
    if (Head->Used <= Head->Capacity)
103
2
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::IntrinsicFunctionIdentifierNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::IntrinsicFunctionIdentifierNode, llvm::ms_demangle::IntrinsicFunctionKind>(llvm::ms_demangle::IntrinsicFunctionKind&&)
Line
Count
Source
91
139
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
139
    constexpr size_t Size = sizeof(T);
93
139
    assert(Head && Head->Buf);
94
139
95
139
    size_t P = (size_t)Head->Buf + Head->Used;
96
139
    uintptr_t AlignedP =
97
139
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
139
    uint8_t *PP = (uint8_t *)AlignedP;
99
139
    size_t Adjustment = AlignedP - P;
100
139
101
139
    Head->Used += Size + Adjustment;
102
139
    if (Head->Used <= Head->Capacity)
103
139
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::SymbolNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::SymbolNode, llvm::ms_demangle::NodeKind>(llvm::ms_demangle::NodeKind&&)
Line
Count
Source
91
3
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
3
    constexpr size_t Size = sizeof(T);
93
3
    assert(Head && Head->Buf);
94
3
95
3
    size_t P = (size_t)Head->Buf + Head->Used;
96
3
    uintptr_t AlignedP =
97
3
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
3
    uint8_t *PP = (uint8_t *)AlignedP;
99
3
    size_t Adjustment = AlignedP - P;
100
3
101
3
    Head->Used += Size + Adjustment;
102
3
    if (Head->Used <= Head->Capacity)
103
3
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::FunctionSymbolNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::FunctionSymbolNode>()
Line
Count
Source
91
717
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
717
    constexpr size_t Size = sizeof(T);
93
717
    assert(Head && Head->Buf);
94
717
95
717
    size_t P = (size_t)Head->Buf + Head->Used;
96
717
    uintptr_t AlignedP =
97
717
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
717
    uint8_t *PP = (uint8_t *)AlignedP;
99
717
    size_t Adjustment = AlignedP - P;
100
717
101
717
    Head->Used += Size + Adjustment;
102
717
    if (Head->Used <= Head->Capacity)
103
717
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::VcallThunkIdentifierNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::VcallThunkIdentifierNode>()
Line
Count
Source
91
9
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
9
    constexpr size_t Size = sizeof(T);
93
9
    assert(Head && Head->Buf);
94
9
95
9
    size_t P = (size_t)Head->Buf + Head->Used;
96
9
    uintptr_t AlignedP =
97
9
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
9
    uint8_t *PP = (uint8_t *)AlignedP;
99
9
    size_t Adjustment = AlignedP - P;
100
9
101
9
    Head->Used += Size + Adjustment;
102
9
    if (Head->Used <= Head->Capacity)
103
9
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::ThunkSignatureNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::ThunkSignatureNode>()
Line
Count
Source
91
14
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
14
    constexpr size_t Size = sizeof(T);
93
14
    assert(Head && Head->Buf);
94
14
95
14
    size_t P = (size_t)Head->Buf + Head->Used;
96
14
    uintptr_t AlignedP =
97
14
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
14
    uint8_t *PP = (uint8_t *)AlignedP;
99
14
    size_t Adjustment = AlignedP - P;
100
14
101
14
    Head->Used += Size + Adjustment;
102
14
    if (Head->Used <= Head->Capacity)
103
14
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::EncodedStringLiteralNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::EncodedStringLiteralNode>()
Line
Count
Source
91
392
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
392
    constexpr size_t Size = sizeof(T);
93
392
    assert(Head && Head->Buf);
94
392
95
392
    size_t P = (size_t)Head->Buf + Head->Used;
96
392
    uintptr_t AlignedP =
97
392
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
392
    uint8_t *PP = (uint8_t *)AlignedP;
99
392
    size_t Adjustment = AlignedP - P;
100
392
101
392
    Head->Used += Size + Adjustment;
102
392
    if (Head->Used <= Head->Capacity)
103
392
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
NodeList* llvm::ms_demangle::ArenaAllocator::alloc<NodeList>()
Line
Count
Source
91
4.08k
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
4.08k
    constexpr size_t Size = sizeof(T);
93
4.08k
    assert(Head && Head->Buf);
94
4.08k
95
4.08k
    size_t P = (size_t)Head->Buf + Head->Used;
96
4.08k
    uintptr_t AlignedP =
97
4.08k
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
4.08k
    uint8_t *PP = (uint8_t *)AlignedP;
99
4.08k
    size_t Adjustment = AlignedP - P;
100
4.08k
101
4.08k
    Head->Used += Size + Adjustment;
102
4.08k
    if (Head->Used <= Head->Capacity)
103
4.08k
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::FunctionSignatureNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::FunctionSignatureNode>()
Line
Count
Source
91
821
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
821
    constexpr size_t Size = sizeof(T);
93
821
    assert(Head && Head->Buf);
94
821
95
821
    size_t P = (size_t)Head->Buf + Head->Used;
96
821
    uintptr_t AlignedP =
97
821
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
821
    uint8_t *PP = (uint8_t *)AlignedP;
99
821
    size_t Adjustment = AlignedP - P;
100
821
101
821
    Head->Used += Size + Adjustment;
102
821
    if (Head->Used <= Head->Capacity)
103
821
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::CustomTypeNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::CustomTypeNode>()
Line
Count
Source
91
11
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
11
    constexpr size_t Size = sizeof(T);
93
11
    assert(Head && Head->Buf);
94
11
95
11
    size_t P = (size_t)Head->Buf + Head->Used;
96
11
    uintptr_t AlignedP =
97
11
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
11
    uint8_t *PP = (uint8_t *)AlignedP;
99
11
    size_t Adjustment = AlignedP - P;
100
11
101
11
    Head->Used += Size + Adjustment;
102
11
    if (Head->Used <= Head->Capacity)
103
11
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::PrimitiveTypeNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::PrimitiveTypeNode, llvm::ms_demangle::PrimitiveKind>(llvm::ms_demangle::PrimitiveKind&&)
Line
Count
Source
91
1.19k
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
1.19k
    constexpr size_t Size = sizeof(T);
93
1.19k
    assert(Head && Head->Buf);
94
1.19k
95
1.19k
    size_t P = (size_t)Head->Buf + Head->Used;
96
1.19k
    uintptr_t AlignedP =
97
1.19k
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
1.19k
    uint8_t *PP = (uint8_t *)AlignedP;
99
1.19k
    size_t Adjustment = AlignedP - P;
100
1.19k
101
1.19k
    Head->Used += Size + Adjustment;
102
1.19k
    if (Head->Used <= Head->Capacity)
103
1.19k
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::TagTypeNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::TagTypeNode, llvm::ms_demangle::TagKind>(llvm::ms_demangle::TagKind&&)
Line
Count
Source
91
401
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
401
    constexpr size_t Size = sizeof(T);
93
401
    assert(Head && Head->Buf);
94
401
95
401
    size_t P = (size_t)Head->Buf + Head->Used;
96
401
    uintptr_t AlignedP =
97
401
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
401
    uint8_t *PP = (uint8_t *)AlignedP;
99
401
    size_t Adjustment = AlignedP - P;
100
401
101
401
    Head->Used += Size + Adjustment;
102
401
    if (Head->Used <= Head->Capacity)
103
401
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::PointerTypeNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::PointerTypeNode>()
Line
Count
Source
91
483
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
483
    constexpr size_t Size = sizeof(T);
93
483
    assert(Head && Head->Buf);
94
483
95
483
    size_t P = (size_t)Head->Buf + Head->Used;
96
483
    uintptr_t AlignedP =
97
483
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
483
    uint8_t *PP = (uint8_t *)AlignedP;
99
483
    size_t Adjustment = AlignedP - P;
100
483
101
483
    Head->Used += Size + Adjustment;
102
483
    if (Head->Used <= Head->Capacity)
103
483
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::ArrayTypeNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::ArrayTypeNode>()
Line
Count
Source
91
40
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
40
    constexpr size_t Size = sizeof(T);
93
40
    assert(Head && Head->Buf);
94
40
95
40
    size_t P = (size_t)Head->Buf + Head->Used;
96
40
    uintptr_t AlignedP =
97
40
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
40
    uint8_t *PP = (uint8_t *)AlignedP;
99
40
    size_t Adjustment = AlignedP - P;
100
40
101
40
    Head->Used += Size + Adjustment;
102
40
    if (Head->Used <= Head->Capacity)
103
40
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::IntegerLiteralNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::IntegerLiteralNode, unsigned long long&, bool&>(unsigned long long&&&, bool&&&)
Line
Count
Source
91
111
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
111
    constexpr size_t Size = sizeof(T);
93
111
    assert(Head && Head->Buf);
94
111
95
111
    size_t P = (size_t)Head->Buf + Head->Used;
96
111
    uintptr_t AlignedP =
97
111
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
111
    uint8_t *PP = (uint8_t *)AlignedP;
99
111
    size_t Adjustment = AlignedP - P;
100
111
101
111
    Head->Used += Size + Adjustment;
102
111
    if (Head->Used <= Head->Capacity)
103
111
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
llvm::ms_demangle::TemplateParameterReferenceNode* llvm::ms_demangle::ArenaAllocator::alloc<llvm::ms_demangle::TemplateParameterReferenceNode>()
Line
Count
Source
91
39
  template <typename T, typename... Args> T *alloc(Args &&... ConstructorArgs) {
92
39
    constexpr size_t Size = sizeof(T);
93
39
    assert(Head && Head->Buf);
94
39
95
39
    size_t P = (size_t)Head->Buf + Head->Used;
96
39
    uintptr_t AlignedP =
97
39
        (((size_t)P + alignof(T) - 1) & ~(size_t)(alignof(T) - 1));
98
39
    uint8_t *PP = (uint8_t *)AlignedP;
99
39
    size_t Adjustment = AlignedP - P;
100
39
101
39
    Head->Used += Size + Adjustment;
102
39
    if (Head->Used <= Head->Capacity)
103
39
      return new (PP) T(std::forward<Args>(ConstructorArgs)...);
104
0
105
0
    static_assert(Size < AllocUnit, "");
106
0
    addNode(AllocUnit);
107
0
    Head->Used = Size;
108
0
    return new (Head->Buf) T(std::forward<Args>(ConstructorArgs)...);
109
0
  }
110
111
private:
112
  AllocatorNode *Head = nullptr;
113
};
114
115
struct BackrefContext {
116
  static constexpr size_t Max = 10;
117
118
  TypeNode *FunctionParams[Max];
119
  size_t FunctionParamCount = 0;
120
121
  // The first 10 BackReferences in a mangled name can be back-referenced by
122
  // special name @[0-9]. This is a storage for the first 10 BackReferences.
123
  NamedIdentifierNode *Names[Max];
124
  size_t NamesCount = 0;
125
};
126
127
enum class QualifierMangleMode { Drop, Mangle, Result };
128
129
enum NameBackrefBehavior : uint8_t {
130
  NBB_None = 0,          // don't save any names as backrefs.
131
  NBB_Template = 1 << 0, // save template instanations.
132
  NBB_Simple = 1 << 1,   // save simple names.
133
};
134
135
enum class FunctionIdentifierCodeGroup { Basic, Under, DoubleUnder };
136
137
// Demangler class takes the main role in demangling symbols.
138
// It has a set of functions to parse mangled symbols into Type instances.
139
// It also has a set of functions to convert Type instances to strings.
140
class Demangler {
141
public:
142
1.30k
  Demangler() = default;
143
1.30k
  virtual ~Demangler() = default;
144
145
  // You are supposed to call parse() first and then check if error is true.  If
146
  // it is false, call output() to write the formatted name to the given stream.
147
  SymbolNode *parse(StringView &MangledName);
148
149
  TagTypeNode *parseTagUniqueName(StringView &MangledName);
150
151
  // True if an error occurred.
152
  bool Error = false;
153
154
  void dumpBackReferences();
155
156
private:
157
  SymbolNode *demangleEncodedSymbol(StringView &MangledName,
158
                                    QualifiedNameNode *QN);
159
  SymbolNode *demangleDeclarator(StringView &MangledName);
160
  SymbolNode *demangleMD5Name(StringView &MangledName);
161
162
  VariableSymbolNode *demangleVariableEncoding(StringView &MangledName,
163
                                               StorageClass SC);
164
  FunctionSymbolNode *demangleFunctionEncoding(StringView &MangledName);
165
166
  Qualifiers demanglePointerExtQualifiers(StringView &MangledName);
167
168
  // Parser functions. This is a recursive-descent parser.
169
  TypeNode *demangleType(StringView &MangledName, QualifierMangleMode QMM);
170
  PrimitiveTypeNode *demanglePrimitiveType(StringView &MangledName);
171
  CustomTypeNode *demangleCustomType(StringView &MangledName);
172
  TagTypeNode *demangleClassType(StringView &MangledName);
173
  PointerTypeNode *demanglePointerType(StringView &MangledName);
174
  PointerTypeNode *demangleMemberPointerType(StringView &MangledName);
175
  FunctionSignatureNode *demangleFunctionType(StringView &MangledName,
176
                                              bool HasThisQuals);
177
178
  ArrayTypeNode *demangleArrayType(StringView &MangledName);
179
180
  NodeArrayNode *demangleFunctionParameterList(StringView &MangledName,
181
                                               bool &IsVariadic);
182
  NodeArrayNode *demangleTemplateParameterList(StringView &MangledName);
183
184
  std::pair<uint64_t, bool> demangleNumber(StringView &MangledName);
185
  uint64_t demangleUnsigned(StringView &MangledName);
186
  int64_t demangleSigned(StringView &MangledName);
187
188
  void memorizeString(StringView s);
189
  void memorizeIdentifier(IdentifierNode *Identifier);
190
191
  /// Allocate a copy of \p Borrowed into memory that we own.
192
  StringView copyString(StringView Borrowed);
193
194
  QualifiedNameNode *demangleFullyQualifiedTypeName(StringView &MangledName);
195
  QualifiedNameNode *demangleFullyQualifiedSymbolName(StringView &MangledName);
196
197
  IdentifierNode *demangleUnqualifiedTypeName(StringView &MangledName,
198
                                              bool Memorize);
199
  IdentifierNode *demangleUnqualifiedSymbolName(StringView &MangledName,
200
                                                NameBackrefBehavior NBB);
201
202
  QualifiedNameNode *demangleNameScopeChain(StringView &MangledName,
203
                                            IdentifierNode *UnqualifiedName);
204
  IdentifierNode *demangleNameScopePiece(StringView &MangledName);
205
206
  NamedIdentifierNode *demangleBackRefName(StringView &MangledName);
207
  IdentifierNode *demangleTemplateInstantiationName(StringView &MangledName,
208
                                                    NameBackrefBehavior NBB);
209
  IntrinsicFunctionKind
210
  translateIntrinsicFunctionCode(char CH, FunctionIdentifierCodeGroup Group);
211
  IdentifierNode *demangleFunctionIdentifierCode(StringView &MangledName);
212
  IdentifierNode *
213
  demangleFunctionIdentifierCode(StringView &MangledName,
214
                                 FunctionIdentifierCodeGroup Group);
215
  StructorIdentifierNode *demangleStructorIdentifier(StringView &MangledName,
216
                                                     bool IsDestructor);
217
  ConversionOperatorIdentifierNode *
218
  demangleConversionOperatorIdentifier(StringView &MangledName);
219
  LiteralOperatorIdentifierNode *
220
  demangleLiteralOperatorIdentifier(StringView &MangledName);
221
222
  SymbolNode *demangleSpecialIntrinsic(StringView &MangledName);
223
  SpecialTableSymbolNode *
224
  demangleSpecialTableSymbolNode(StringView &MangledName,
225
                                 SpecialIntrinsicKind SIK);
226
  LocalStaticGuardVariableNode *
227
  demangleLocalStaticGuard(StringView &MangledName, bool IsThread);
228
  VariableSymbolNode *demangleUntypedVariable(ArenaAllocator &Arena,
229
                                              StringView &MangledName,
230
                                              StringView VariableName);
231
  VariableSymbolNode *
232
  demangleRttiBaseClassDescriptorNode(ArenaAllocator &Arena,
233
                                      StringView &MangledName);
234
  FunctionSymbolNode *demangleInitFiniStub(StringView &MangledName,
235
                                           bool IsDestructor);
236
237
  NamedIdentifierNode *demangleSimpleName(StringView &MangledName,
238
                                          bool Memorize);
239
  NamedIdentifierNode *demangleAnonymousNamespaceName(StringView &MangledName);
240
  NamedIdentifierNode *demangleLocallyScopedNamePiece(StringView &MangledName);
241
  EncodedStringLiteralNode *demangleStringLiteral(StringView &MangledName);
242
  FunctionSymbolNode *demangleVcallThunkNode(StringView &MangledName);
243
244
  StringView demangleSimpleString(StringView &MangledName, bool Memorize);
245
246
  FuncClass demangleFunctionClass(StringView &MangledName);
247
  CallingConv demangleCallingConvention(StringView &MangledName);
248
  StorageClass demangleVariableStorageClass(StringView &MangledName);
249
  bool demangleThrowSpecification(StringView &MangledName);
250
  wchar_t demangleWcharLiteral(StringView &MangledName);
251
  uint8_t demangleCharLiteral(StringView &MangledName);
252
253
  std::pair<Qualifiers, bool> demangleQualifiers(StringView &MangledName);
254
255
  // Memory allocator.
256
  ArenaAllocator Arena;
257
258
  // A single type uses one global back-ref table for all function params.
259
  // This means back-refs can even go "into" other types.  Examples:
260
  //
261
  //  // Second int* is a back-ref to first.
262
  //  void foo(int *, int*);
263
  //
264
  //  // Second int* is not a back-ref to first (first is not a function param).
265
  //  int* foo(int*);
266
  //
267
  //  // Second int* is a back-ref to first (ALL function types share the same
268
  //  // back-ref map.
269
  //  using F = void(*)(int*);
270
  //  F G(int *);
271
  BackrefContext Backrefs;
272
};
273
274
} // namespace ms_demangle
275
} // namespace llvm
276
277
#endif // LLVM_DEMANGLE_MICROSOFT_DEMANGLE_H