Coverage Report

Created: 2018-11-16 02:38

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/Mangle.h
Line
Count
Source (jump to first uncovered line)
1
//===--- Mangle.h - Mangle C++ Names ----------------------------*- C++ -*-===//
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
// Defines the C++ name mangling interface.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_MANGLE_H
15
#define LLVM_CLANG_AST_MANGLE_H
16
17
#include "clang/AST/Type.h"
18
#include "clang/Basic/ABI.h"
19
#include "llvm/ADT/DenseMap.h"
20
#include "llvm/Support/Casting.h"
21
22
namespace llvm {
23
  class raw_ostream;
24
}
25
26
namespace clang {
27
  class ASTContext;
28
  class BlockDecl;
29
  class CXXConstructorDecl;
30
  class CXXDestructorDecl;
31
  class CXXMethodDecl;
32
  class FunctionDecl;
33
  struct MethodVFTableLocation;
34
  class NamedDecl;
35
  class ObjCMethodDecl;
36
  class StringLiteral;
37
  struct ThisAdjustment;
38
  struct ThunkInfo;
39
  class VarDecl;
40
41
/// MangleContext - Context for tracking state which persists across multiple
42
/// calls to the C++ name mangler.
43
class MangleContext {
44
public:
45
  enum ManglerKind {
46
    MK_Itanium,
47
    MK_Microsoft
48
  };
49
50
private:
51
  virtual void anchor();
52
53
  ASTContext &Context;
54
  DiagnosticsEngine &Diags;
55
  const ManglerKind Kind;
56
57
  llvm::DenseMap<const BlockDecl*, unsigned> GlobalBlockIds;
58
  llvm::DenseMap<const BlockDecl*, unsigned> LocalBlockIds;
59
  llvm::DenseMap<const TagDecl*, uint64_t> AnonStructIds;
60
61
public:
62
0
  ManglerKind getKind() const { return Kind; }
63
64
  explicit MangleContext(ASTContext &Context,
65
                         DiagnosticsEngine &Diags,
66
                         ManglerKind Kind)
67
17.3k
      : Context(Context), Diags(Diags), Kind(Kind) {}
68
69
17.3k
  virtual ~MangleContext() { }
70
71
19.1M
  ASTContext &getASTContext() const { return Context; }
72
73
4
  DiagnosticsEngine &getDiags() const { return Diags; }
74
75
351k
  virtual void startNewFunction() { LocalBlockIds.clear(); }
76
77
1.22k
  unsigned getBlockId(const BlockDecl *BD, bool Local) {
78
1.22k
    llvm::DenseMap<const BlockDecl *, unsigned> &BlockIds
79
1.22k
      = Local? 
LocalBlockIds1.08k
:
GlobalBlockIds141
;
80
1.22k
    std::pair<llvm::DenseMap<const BlockDecl *, unsigned>::iterator, bool>
81
1.22k
      Result = BlockIds.insert(std::make_pair(BD, BlockIds.size()));
82
1.22k
    return Result.first->second;
83
1.22k
  }
84
85
2.70k
  uint64_t getAnonymousStructId(const TagDecl *TD) {
86
2.70k
    std::pair<llvm::DenseMap<const TagDecl *, uint64_t>::iterator, bool>
87
2.70k
        Result = AnonStructIds.insert(std::make_pair(TD, AnonStructIds.size()));
88
2.70k
    return Result.first->second;
89
2.70k
  }
90
91
  /// @name Mangler Entry Points
92
  /// @{
93
94
  bool shouldMangleDeclName(const NamedDecl *D);
95
  virtual bool shouldMangleCXXName(const NamedDecl *D) = 0;
96
  virtual bool shouldMangleStringLiteral(const StringLiteral *SL) = 0;
97
98
  // FIXME: consider replacing raw_ostream & with something like SmallString &.
99
  void mangleName(const NamedDecl *D, raw_ostream &);
100
  virtual void mangleCXXName(const NamedDecl *D, raw_ostream &) = 0;
101
  virtual void mangleThunk(const CXXMethodDecl *MD,
102
                          const ThunkInfo &Thunk,
103
                          raw_ostream &) = 0;
104
  virtual void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type,
105
                                  const ThisAdjustment &ThisAdjustment,
106
                                  raw_ostream &) = 0;
107
  virtual void mangleReferenceTemporary(const VarDecl *D,
108
                                        unsigned ManglingNumber,
109
                                        raw_ostream &) = 0;
110
  virtual void mangleCXXRTTI(QualType T, raw_ostream &) = 0;
111
  virtual void mangleCXXRTTIName(QualType T, raw_ostream &) = 0;
112
  virtual void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
113
                             raw_ostream &) = 0;
114
  virtual void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
115
                             raw_ostream &) = 0;
116
  virtual void mangleStringLiteral(const StringLiteral *SL, raw_ostream &) = 0;
117
118
  void mangleGlobalBlock(const BlockDecl *BD,
119
                         const NamedDecl *ID,
120
                         raw_ostream &Out);
121
  void mangleCtorBlock(const CXXConstructorDecl *CD, CXXCtorType CT,
122
                       const BlockDecl *BD, raw_ostream &Out);
123
  void mangleDtorBlock(const CXXDestructorDecl *CD, CXXDtorType DT,
124
                       const BlockDecl *BD, raw_ostream &Out);
125
  void mangleBlock(const DeclContext *DC, const BlockDecl *BD,
126
                   raw_ostream &Out);
127
128
  void mangleObjCMethodNameWithoutSize(const ObjCMethodDecl *MD, raw_ostream &);
129
  void mangleObjCMethodName(const ObjCMethodDecl *MD, raw_ostream &);
130
131
  virtual void mangleStaticGuardVariable(const VarDecl *D, raw_ostream &) = 0;
132
133
  virtual void mangleDynamicInitializer(const VarDecl *D, raw_ostream &) = 0;
134
135
  virtual void mangleDynamicAtExitDestructor(const VarDecl *D,
136
                                             raw_ostream &) = 0;
137
138
  virtual void mangleSEHFilterExpression(const NamedDecl *EnclosingDecl,
139
                                         raw_ostream &Out) = 0;
140
141
  virtual void mangleSEHFinallyBlock(const NamedDecl *EnclosingDecl,
142
                                     raw_ostream &Out) = 0;
143
144
  /// Generates a unique string for an externally visible type for use with TBAA
145
  /// or type uniquing.
146
  /// TODO: Extend this to internal types by generating names that are unique
147
  /// across translation units so it can be used with LTO.
148
  virtual void mangleTypeName(QualType T, raw_ostream &) = 0;
149
150
  /// @}
151
};
152
153
class ItaniumMangleContext : public MangleContext {
154
public:
155
  explicit ItaniumMangleContext(ASTContext &C, DiagnosticsEngine &D)
156
16.6k
      : MangleContext(C, D, MK_Itanium) {}
157
158
  virtual void mangleCXXVTable(const CXXRecordDecl *RD, raw_ostream &) = 0;
159
  virtual void mangleCXXVTT(const CXXRecordDecl *RD, raw_ostream &) = 0;
160
  virtual void mangleCXXCtorVTable(const CXXRecordDecl *RD, int64_t Offset,
161
                                   const CXXRecordDecl *Type,
162
                                   raw_ostream &) = 0;
163
  virtual void mangleItaniumThreadLocalInit(const VarDecl *D,
164
                                            raw_ostream &) = 0;
165
  virtual void mangleItaniumThreadLocalWrapper(const VarDecl *D,
166
                                               raw_ostream &) = 0;
167
168
  virtual void mangleCXXCtorComdat(const CXXConstructorDecl *D,
169
                                   raw_ostream &) = 0;
170
  virtual void mangleCXXDtorComdat(const CXXDestructorDecl *D,
171
                                   raw_ostream &) = 0;
172
173
0
  static bool classof(const MangleContext *C) {
174
0
    return C->getKind() == MK_Itanium;
175
0
  }
176
177
  static ItaniumMangleContext *create(ASTContext &Context,
178
                                      DiagnosticsEngine &Diags);
179
};
180
181
class MicrosoftMangleContext : public MangleContext {
182
public:
183
  explicit MicrosoftMangleContext(ASTContext &C, DiagnosticsEngine &D)
184
627
      : MangleContext(C, D, MK_Microsoft) {}
185
186
  /// Mangle vftable symbols.  Only a subset of the bases along the path
187
  /// to the vftable are included in the name.  It's up to the caller to pick
188
  /// them correctly.
189
  virtual void mangleCXXVFTable(const CXXRecordDecl *Derived,
190
                                ArrayRef<const CXXRecordDecl *> BasePath,
191
                                raw_ostream &Out) = 0;
192
193
  /// Mangle vbtable symbols.  Only a subset of the bases along the path
194
  /// to the vbtable are included in the name.  It's up to the caller to pick
195
  /// them correctly.
196
  virtual void mangleCXXVBTable(const CXXRecordDecl *Derived,
197
                                ArrayRef<const CXXRecordDecl *> BasePath,
198
                                raw_ostream &Out) = 0;
199
200
  virtual void mangleThreadSafeStaticGuardVariable(const VarDecl *VD,
201
                                                   unsigned GuardNum,
202
                                                   raw_ostream &Out) = 0;
203
204
  virtual void mangleVirtualMemPtrThunk(const CXXMethodDecl *MD,
205
                                        const MethodVFTableLocation &ML,
206
                                        raw_ostream &Out) = 0;
207
208
  virtual void mangleCXXVirtualDisplacementMap(const CXXRecordDecl *SrcRD,
209
                                               const CXXRecordDecl *DstRD,
210
                                               raw_ostream &Out) = 0;
211
212
  virtual void mangleCXXThrowInfo(QualType T, bool IsConst, bool IsVolatile,
213
                                  bool IsUnaligned, uint32_t NumEntries,
214
                                  raw_ostream &Out) = 0;
215
216
  virtual void mangleCXXCatchableTypeArray(QualType T, uint32_t NumEntries,
217
                                           raw_ostream &Out) = 0;
218
219
  virtual void mangleCXXCatchableType(QualType T, const CXXConstructorDecl *CD,
220
                                      CXXCtorType CT, uint32_t Size,
221
                                      uint32_t NVOffset, int32_t VBPtrOffset,
222
                                      uint32_t VBIndex, raw_ostream &Out) = 0;
223
224
  virtual void mangleCXXRTTIBaseClassDescriptor(
225
      const CXXRecordDecl *Derived, uint32_t NVOffset, int32_t VBPtrOffset,
226
      uint32_t VBTableOffset, uint32_t Flags, raw_ostream &Out) = 0;
227
228
  virtual void mangleCXXRTTIBaseClassArray(const CXXRecordDecl *Derived,
229
                                           raw_ostream &Out) = 0;
230
  virtual void
231
  mangleCXXRTTIClassHierarchyDescriptor(const CXXRecordDecl *Derived,
232
                                        raw_ostream &Out) = 0;
233
234
  virtual void
235
  mangleCXXRTTICompleteObjectLocator(const CXXRecordDecl *Derived,
236
                                     ArrayRef<const CXXRecordDecl *> BasePath,
237
                                     raw_ostream &Out) = 0;
238
239
0
  static bool classof(const MangleContext *C) {
240
0
    return C->getKind() == MK_Microsoft;
241
0
  }
242
243
  static MicrosoftMangleContext *create(ASTContext &Context,
244
                                        DiagnosticsEngine &Diags);
245
};
246
}
247
248
#endif