clang  12.0.0git
Mangle.cpp
Go to the documentation of this file.
1 //===--- Mangle.cpp - Mangle C++ Names --------------------------*- 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 // Implements generic name mangling support for blocks and Objective-C.
10 //
11 //===----------------------------------------------------------------------===//
12 #include "clang/AST/Attr.h"
13 #include "clang/AST/ASTContext.h"
14 #include "clang/AST/Decl.h"
15 #include "clang/AST/DeclCXX.h"
16 #include "clang/AST/DeclObjC.h"
17 #include "clang/AST/DeclTemplate.h"
18 #include "clang/AST/ExprCXX.h"
19 #include "clang/AST/Mangle.h"
21 #include "clang/Basic/ABI.h"
23 #include "clang/Basic/TargetInfo.h"
24 #include "llvm/ADT/StringExtras.h"
25 #include "llvm/IR/DataLayout.h"
26 #include "llvm/IR/Mangler.h"
27 #include "llvm/Support/ErrorHandling.h"
28 #include "llvm/Support/Format.h"
29 #include "llvm/Support/raw_ostream.h"
30 
31 using namespace clang;
32 
33 // FIXME: For blocks we currently mimic GCC's mangling scheme, which leaves
34 // much to be desired. Come up with a better mangling scheme.
35 
36 static void mangleFunctionBlock(MangleContext &Context,
37  StringRef Outer,
38  const BlockDecl *BD,
39  raw_ostream &Out) {
40  unsigned discriminator = Context.getBlockId(BD, true);
41  if (discriminator == 0)
42  Out << "__" << Outer << "_block_invoke";
43  else
44  Out << "__" << Outer << "_block_invoke_" << discriminator+1;
45 }
46 
47 void MangleContext::anchor() { }
48 
49 enum CCMangling {
56 };
57 
58 static bool isExternC(const NamedDecl *ND) {
59  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND))
60  return FD->isExternC();
61  if (const VarDecl *VD = dyn_cast<VarDecl>(ND))
62  return VD->isExternC();
63  return false;
64 }
65 
67  const NamedDecl *ND) {
68  const TargetInfo &TI = Context.getTargetInfo();
69  const llvm::Triple &Triple = TI.getTriple();
70 
71  // On wasm, the argc/argv form of "main" is renamed so that the startup code
72  // can call it with the correct function signature.
73  // On Emscripten, users may be exporting "main" and expecting to call it
74  // themselves, so we can't mangle it.
75  if (Triple.isWasm() && !Triple.isOSEmscripten())
76  if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND))
77  if (FD->isMain() && FD->hasPrototype() && FD->param_size() == 2)
78  return CCM_WasmMainArgcArgv;
79 
80  if (!Triple.isOSWindows() || !Triple.isX86())
81  return CCM_Other;
82 
83  if (Context.getLangOpts().CPlusPlus && !isExternC(ND) &&
85  return CCM_Other;
86 
87  const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND);
88  if (!FD)
89  return CCM_Other;
90  QualType T = FD->getType();
91 
92  const FunctionType *FT = T->castAs<FunctionType>();
93 
94  CallingConv CC = FT->getCallConv();
95  switch (CC) {
96  default:
97  return CCM_Other;
98  case CC_X86FastCall:
99  return CCM_Fast;
100  case CC_X86StdCall:
101  return CCM_Std;
102  case CC_X86VectorCall:
103  return CCM_Vector;
104  }
105 }
106 
109 
111  if (CC != CCM_Other)
112  return true;
113 
114  // If the declaration has an owning module for linkage purposes that needs to
115  // be mangled, we must mangle its name.
117  return true;
118 
119  // In C, functions with no attributes never need to be mangled. Fastpath them.
120  if (!getASTContext().getLangOpts().CPlusPlus && !D->hasAttrs())
121  return false;
122 
123  // Any decl can be declared with __asm("foo") on it, and this takes precedence
124  // over all other naming in the .o file.
125  if (D->hasAttr<AsmLabelAttr>())
126  return true;
127 
128  // Declarations that don't have identifier names always need to be mangled.
129  if (isa<MSGuidDecl>(D))
130  return true;
131 
132  return shouldMangleCXXName(D);
133 }
134 
135 void MangleContext::mangleName(GlobalDecl GD, raw_ostream &Out) {
136  const NamedDecl *D = cast<NamedDecl>(GD.getDecl());
137  // Any decl can be declared with __asm("foo") on it, and this takes precedence
138  // over all other naming in the .o file.
139  if (const AsmLabelAttr *ALA = D->getAttr<AsmLabelAttr>()) {
140  // If we have an asm name, then we use it as the mangling.
141 
142  // If the label isn't literal, or if this is an alias for an LLVM intrinsic,
143  // do not add a "\01" prefix.
144  if (!ALA->getIsLiteralLabel() || ALA->getLabel().startswith("llvm.")) {
145  Out << ALA->getLabel();
146  return;
147  }
148 
149  // Adding the prefix can cause problems when one file has a "foo" and
150  // another has a "\01foo". That is known to happen on ELF with the
151  // tricks normally used for producing aliases (PR9177). Fortunately the
152  // llvm mangler on ELF is a nop, so we can just avoid adding the \01
153  // marker.
154  char GlobalPrefix =
155  getASTContext().getTargetInfo().getDataLayout().getGlobalPrefix();
156  if (GlobalPrefix)
157  Out << '\01'; // LLVM IR Marker for __asm("foo")
158 
159  Out << ALA->getLabel();
160  return;
161  }
162 
163  if (auto *GD = dyn_cast<MSGuidDecl>(D))
164  return mangleMSGuidDecl(GD, Out);
165 
168 
169  if (CC == CCM_WasmMainArgcArgv) {
170  Out << "__main_argc_argv";
171  return;
172  }
173 
174  bool MCXX = shouldMangleCXXName(D);
175  const TargetInfo &TI = Context.getTargetInfo();
176  if (CC == CCM_Other || (MCXX && TI.getCXXABI() == TargetCXXABI::Microsoft)) {
177  if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D))
179  else
180  mangleCXXName(GD, Out);
181  return;
182  }
183 
184  Out << '\01';
185  if (CC == CCM_Std)
186  Out << '_';
187  else if (CC == CCM_Fast)
188  Out << '@';
189  else if (CC == CCM_RegCall)
190  Out << "__regcall3__";
191 
192  if (!MCXX)
193  Out << D->getIdentifier()->getName();
194  else if (const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D))
196  else
197  mangleCXXName(GD, Out);
198 
199  const FunctionDecl *FD = cast<FunctionDecl>(D);
200  const FunctionType *FT = FD->getType()->castAs<FunctionType>();
201  const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(FT);
202  if (CC == CCM_Vector)
203  Out << '@';
204  Out << '@';
205  if (!Proto) {
206  Out << '0';
207  return;
208  }
209  assert(!Proto->isVariadic());
210  unsigned ArgWords = 0;
211  if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD))
212  if (!MD->isStatic())
213  ++ArgWords;
214  for (const auto &AT : Proto->param_types())
215  // Size should be aligned to pointer size.
216  ArgWords +=
217  llvm::alignTo(ASTContext.getTypeSize(AT), TI.getPointerWidth(0)) /
218  TI.getPointerWidth(0);
219  Out << ((TI.getPointerWidth(0) / 8) * ArgWords);
220 }
221 
222 void MangleContext::mangleMSGuidDecl(const MSGuidDecl *GD, raw_ostream &Out) {
223  // For now, follow the MSVC naming convention for GUID objects on all
224  // targets.
225  MSGuidDecl::Parts P = GD->getParts();
226  Out << llvm::format("_GUID_%08" PRIx32 "_%04" PRIx32 "_%04" PRIx32 "_",
227  P.Part1, P.Part2, P.Part3);
228  unsigned I = 0;
229  for (uint8_t C : P.Part4And5) {
230  Out << llvm::format("%02" PRIx8, C);
231  if (++I == 2)
232  Out << "_";
233  }
234 }
235 
237  const NamedDecl *ID,
238  raw_ostream &Out) {
239  unsigned discriminator = getBlockId(BD, false);
240  if (ID) {
242  mangleName(ID, Out);
243  else {
244  Out << ID->getIdentifier()->getName();
245  }
246  }
247  if (discriminator == 0)
248  Out << "_block_invoke";
249  else
250  Out << "_block_invoke_" << discriminator+1;
251 }
252 
254  CXXCtorType CT, const BlockDecl *BD,
255  raw_ostream &ResStream) {
256  SmallString<64> Buffer;
257  llvm::raw_svector_ostream Out(Buffer);
258  mangleName(GlobalDecl(CD, CT), Out);
259  mangleFunctionBlock(*this, Buffer, BD, ResStream);
260 }
261 
263  CXXDtorType DT, const BlockDecl *BD,
264  raw_ostream &ResStream) {
265  SmallString<64> Buffer;
266  llvm::raw_svector_ostream Out(Buffer);
267  mangleName(GlobalDecl(DD, DT), Out);
268  mangleFunctionBlock(*this, Buffer, BD, ResStream);
269 }
270 
272  raw_ostream &Out) {
273  assert(!isa<CXXConstructorDecl>(DC) && !isa<CXXDestructorDecl>(DC));
274 
275  SmallString<64> Buffer;
276  llvm::raw_svector_ostream Stream(Buffer);
277  if (const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(DC)) {
278  mangleObjCMethodNameAsSourceName(Method, Stream);
279  } else {
280  assert((isa<NamedDecl>(DC) || isa<BlockDecl>(DC)) &&
281  "expected a NamedDecl or BlockDecl");
282  if (isa<BlockDecl>(DC))
283  for (; DC && isa<BlockDecl>(DC); DC = DC->getParent())
284  (void) getBlockId(cast<BlockDecl>(DC), true);
285  assert((isa<TranslationUnitDecl>(DC) || isa<NamedDecl>(DC)) &&
286  "expected a TranslationUnitDecl or a NamedDecl");
287  if (const auto *CD = dyn_cast<CXXConstructorDecl>(DC))
288  mangleCtorBlock(CD, /*CT*/ Ctor_Complete, BD, Out);
289  else if (const auto *DD = dyn_cast<CXXDestructorDecl>(DC))
290  mangleDtorBlock(DD, /*DT*/ Dtor_Complete, BD, Out);
291  else if (auto ND = dyn_cast<NamedDecl>(DC)) {
292  if (!shouldMangleDeclName(ND) && ND->getIdentifier())
293  Stream << ND->getIdentifier()->getName();
294  else {
295  // FIXME: We were doing a mangleUnqualifiedName() before, but that's
296  // a private member of a class that will soon itself be private to the
297  // Itanium C++ ABI object. What should we do now? Right now, I'm just
298  // calling the mangleName() method on the MangleContext; is there a
299  // better way?
300  mangleName(ND, Stream);
301  }
302  }
303  }
304  mangleFunctionBlock(*this, Buffer, BD, Out);
305 }
306 
308  raw_ostream &OS,
309  bool includePrefixByte,
310  bool includeCategoryNamespace) {
311  if (getASTContext().getLangOpts().ObjCRuntime.isGNUFamily()) {
312  // This is the mangling we've always used on the GNU runtimes, but it
313  // has obvious collisions in the face of underscores within class
314  // names, category names, and selectors; maybe we should improve it.
315 
316  OS << (MD->isClassMethod() ? "_c_" : "_i_")
317  << MD->getClassInterface()->getName() << '_';
318 
319  if (includeCategoryNamespace) {
320  if (auto category = MD->getCategory())
321  OS << category->getName();
322  }
323  OS << '_';
324 
325  auto selector = MD->getSelector();
326  for (unsigned slotIndex = 0,
327  numArgs = selector.getNumArgs(),
328  slotEnd = std::max(numArgs, 1U);
329  slotIndex != slotEnd; ++slotIndex) {
330  if (auto name = selector.getIdentifierInfoForSlot(slotIndex))
331  OS << name->getName();
332 
333  // Replace all the positions that would've been ':' with '_'.
334  // That's after each slot except that a unary selector doesn't
335  // end in ':'.
336  if (numArgs)
337  OS << '_';
338  }
339 
340  return;
341  }
342 
343  // \01+[ContainerName(CategoryName) SelectorName]
344  if (includePrefixByte) {
345  OS << '\01';
346  }
347  OS << (MD->isInstanceMethod() ? '-' : '+') << '[';
348  if (const auto *CID = MD->getCategory()) {
349  OS << CID->getClassInterface()->getName();
350  if (includeCategoryNamespace) {
351  OS << '(' << *CID << ')';
352  }
353  } else if (const auto *CD =
354  dyn_cast<ObjCContainerDecl>(MD->getDeclContext())) {
355  OS << CD->getName();
356  } else {
357  llvm_unreachable("Unexpected ObjC method decl context");
358  }
359  OS << ' ';
360  MD->getSelector().print(OS);
361  OS << ']';
362 }
363 
365  raw_ostream &Out) {
366  SmallString<64> Name;
367  llvm::raw_svector_ostream OS(Name);
368 
369  mangleObjCMethodName(MD, OS, /*includePrefixByte=*/false,
370  /*includeCategoryNamespace=*/true);
371  Out << OS.str().size() << OS.str();
372 }
373 
375  std::unique_ptr<MangleContext> MC;
376  llvm::DataLayout DL;
377 
378 public:
379  explicit Implementation(ASTContext &Ctx)
380  : MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {
381  }
382 
383  bool writeName(const Decl *D, raw_ostream &OS) {
384  // First apply frontend mangling.
385  SmallString<128> FrontendBuf;
386  llvm::raw_svector_ostream FrontendBufOS(FrontendBuf);
387  if (auto *FD = dyn_cast<FunctionDecl>(D)) {
388  if (FD->isDependentContext())
389  return true;
390  if (writeFuncOrVarName(FD, FrontendBufOS))
391  return true;
392  } else if (auto *VD = dyn_cast<VarDecl>(D)) {
393  if (writeFuncOrVarName(VD, FrontendBufOS))
394  return true;
395  } else if (auto *MD = dyn_cast<ObjCMethodDecl>(D)) {
396  MC->mangleObjCMethodName(MD, OS, /*includePrefixByte=*/false,
397  /*includeCategoryNamespace=*/true);
398  return false;
399  } else if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
400  writeObjCClassName(ID, FrontendBufOS);
401  } else {
402  return true;
403  }
404 
405  // Now apply backend mangling.
406  llvm::Mangler::getNameWithPrefix(OS, FrontendBufOS.str(), DL);
407  return false;
408  }
409 
410  std::string getName(const Decl *D) {
411  std::string Name;
412  {
413  llvm::raw_string_ostream OS(Name);
414  writeName(D, OS);
415  }
416  return Name;
417  }
418 
419  enum ObjCKind {
422  };
423 
425  const ASTContext &Context) {
426  if (Context.getLangOpts().ObjCRuntime.isGNUFamily())
427  return Kind == ObjCMetaclass ? "_OBJC_METACLASS_" : "_OBJC_CLASS_";
428  return Kind == ObjCMetaclass ? "OBJC_METACLASS_$_" : "OBJC_CLASS_$_";
429  }
430 
431  std::vector<std::string> getAllManglings(const ObjCContainerDecl *OCD) {
432  StringRef ClassName;
433  if (const auto *OID = dyn_cast<ObjCInterfaceDecl>(OCD))
434  ClassName = OID->getObjCRuntimeNameAsString();
435  else if (const auto *OID = dyn_cast<ObjCImplementationDecl>(OCD))
436  ClassName = OID->getObjCRuntimeNameAsString();
437 
438  if (ClassName.empty())
439  return {};
440 
441  auto Mangle = [&](ObjCKind Kind, StringRef ClassName) -> std::string {
442  SmallString<40> Mangled;
443  auto Prefix = getClassSymbolPrefix(Kind, OCD->getASTContext());
444  llvm::Mangler::getNameWithPrefix(Mangled, Prefix + ClassName, DL);
445  return std::string(Mangled.str());
446  };
447 
448  return {
449  Mangle(ObjCClass, ClassName),
450  Mangle(ObjCMetaclass, ClassName),
451  };
452  }
453 
454  std::vector<std::string> getAllManglings(const Decl *D) {
455  if (const auto *OCD = dyn_cast<ObjCContainerDecl>(D))
456  return getAllManglings(OCD);
457 
458  if (!(isa<CXXRecordDecl>(D) || isa<CXXMethodDecl>(D)))
459  return {};
460 
461  const NamedDecl *ND = cast<NamedDecl>(D);
462 
463  ASTContext &Ctx = ND->getASTContext();
464  std::unique_ptr<MangleContext> M(Ctx.createMangleContext());
465 
466  std::vector<std::string> Manglings;
467 
468  auto hasDefaultCXXMethodCC = [](ASTContext &C, const CXXMethodDecl *MD) {
469  auto DefaultCC = C.getDefaultCallingConvention(/*IsVariadic=*/false,
470  /*IsCXXMethod=*/true);
471  auto CC = MD->getType()->castAs<FunctionProtoType>()->getCallConv();
472  return CC == DefaultCC;
473  };
474 
475  if (const auto *CD = dyn_cast_or_null<CXXConstructorDecl>(ND)) {
476  Manglings.emplace_back(getMangledStructor(CD, Ctor_Base));
477 
479  if (!CD->getParent()->isAbstract())
480  Manglings.emplace_back(getMangledStructor(CD, Ctor_Complete));
481 
482  if (Ctx.getTargetInfo().getCXXABI().isMicrosoft())
483  if (CD->hasAttr<DLLExportAttr>() && CD->isDefaultConstructor())
484  if (!(hasDefaultCXXMethodCC(Ctx, CD) && CD->getNumParams() == 0))
485  Manglings.emplace_back(getMangledStructor(CD, Ctor_DefaultClosure));
486  } else if (const auto *DD = dyn_cast_or_null<CXXDestructorDecl>(ND)) {
487  Manglings.emplace_back(getMangledStructor(DD, Dtor_Base));
488  if (Ctx.getTargetInfo().getCXXABI().isItaniumFamily()) {
489  Manglings.emplace_back(getMangledStructor(DD, Dtor_Complete));
490  if (DD->isVirtual())
491  Manglings.emplace_back(getMangledStructor(DD, Dtor_Deleting));
492  }
493  } else if (const auto *MD = dyn_cast_or_null<CXXMethodDecl>(ND)) {
494  Manglings.emplace_back(getName(ND));
495  if (MD->isVirtual())
496  if (const auto *TIV = Ctx.getVTableContext()->getThunkInfo(MD))
497  for (const auto &T : *TIV)
498  Manglings.emplace_back(getMangledThunk(MD, T));
499  }
500 
501  return Manglings;
502  }
503 
504 private:
505  bool writeFuncOrVarName(const NamedDecl *D, raw_ostream &OS) {
506  if (MC->shouldMangleDeclName(D)) {
507  GlobalDecl GD;
508  if (const auto *CtorD = dyn_cast<CXXConstructorDecl>(D))
509  GD = GlobalDecl(CtorD, Ctor_Complete);
510  else if (const auto *DtorD = dyn_cast<CXXDestructorDecl>(D))
511  GD = GlobalDecl(DtorD, Dtor_Complete);
512  else if (D->hasAttr<CUDAGlobalAttr>())
513  GD = GlobalDecl(cast<FunctionDecl>(D));
514  else
515  GD = GlobalDecl(D);
516  MC->mangleName(GD, OS);
517  return false;
518  } else {
519  IdentifierInfo *II = D->getIdentifier();
520  if (!II)
521  return true;
522  OS << II->getName();
523  return false;
524  }
525  }
526 
527  void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream &OS) {
530  }
531 
532  std::string getMangledStructor(const NamedDecl *ND, unsigned StructorType) {
533  std::string FrontendBuf;
534  llvm::raw_string_ostream FOS(FrontendBuf);
535 
536  GlobalDecl GD;
537  if (const auto *CD = dyn_cast_or_null<CXXConstructorDecl>(ND))
538  GD = GlobalDecl(CD, static_cast<CXXCtorType>(StructorType));
539  else if (const auto *DD = dyn_cast_or_null<CXXDestructorDecl>(ND))
540  GD = GlobalDecl(DD, static_cast<CXXDtorType>(StructorType));
541  MC->mangleName(GD, FOS);
542 
543  std::string BackendBuf;
544  llvm::raw_string_ostream BOS(BackendBuf);
545 
546  llvm::Mangler::getNameWithPrefix(BOS, FOS.str(), DL);
547 
548  return BOS.str();
549  }
550 
551  std::string getMangledThunk(const CXXMethodDecl *MD, const ThunkInfo &T) {
552  std::string FrontendBuf;
553  llvm::raw_string_ostream FOS(FrontendBuf);
554 
555  MC->mangleThunk(MD, T, FOS);
556 
557  std::string BackendBuf;
558  llvm::raw_string_ostream BOS(BackendBuf);
559 
560  llvm::Mangler::getNameWithPrefix(BOS, FOS.str(), DL);
561 
562  return BOS.str();
563  }
564 };
565 
567  : Impl(std::make_unique<Implementation>(Ctx)) {}
568 
570 
571 bool ASTNameGenerator::writeName(const Decl *D, raw_ostream &OS) {
572  return Impl->writeName(D, OS);
573 }
574 
575 std::string ASTNameGenerator::getName(const Decl *D) {
576  return Impl->getName(D);
577 }
578 
579 std::vector<std::string> ASTNameGenerator::getAllManglings(const Decl *D) {
580  return Impl->getAllManglings(D);
581 }
Defines the clang::ASTContext interface.
bool isClassMethod() const
Definition: DeclObjC.h:439
Represents a function declaration or definition.
Definition: Decl.h:1805
Complete object ctor.
Definition: ABI.h:25
A (possibly-)qualified type.
Definition: Type.h:661
ObjCInterfaceDecl * getClassInterface()
Definition: DeclObjC.cpp:1159
MangleContext * createMangleContext(const TargetInfo *T=nullptr)
If T is null pointer, assume the target in ASTContext.
Module * getOwningModuleForLinkage(bool IgnoreLinkage=false) const
Get the module that owns this declaration for linkage purposes.
Definition: Decl.cpp:1496
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: Type.h:3537
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1067
Defines the SourceManager interface.
__DEVICE__ int max(int __a, int __b)
std::vector< std::string > getAllManglings(const Decl *D)
Definition: Mangle.cpp:454
virtual const ThunkInfoVectorTy * getThunkInfo(GlobalDecl GD)
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:89
Defines the C++ template declaration subclasses.
StringRef P
const TargetInfo & getTargetInfo() const
Definition: ASTContext.h:658
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2379
Default closure variant of a ctor.
Definition: ABI.h:29
void mangleName(GlobalDecl GD, raw_ostream &)
Definition: Mangle.cpp:135
Represents a variable declaration or definition.
Definition: Decl.h:834
ObjCMethodDecl - Represents an instance or class method declaration.
Definition: DeclObjC.h:139
Defines the clang::Expr interface and subclasses for C++ expressions.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition: Decl.h:244
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
Definition: TargetInfo.h:399
static CCMangling getCallingConvMangling(const ASTContext &Context, const NamedDecl *ND)
Definition: Mangle.cpp:66
One of these records is kept for each identifier that is lexed.
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
Definition: TargetInfo.h:1146
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:185
bool writeName(const Decl *D, raw_ostream &OS)
Writes name for D to OS.
Definition: Mangle.cpp:571
Definition: Format.h:2835
Parts getParts() const
Get the decomposed parts of this declaration.
Definition: DeclCXX.h:4018
std::string getName(const Decl *D)
Definition: Mangle.cpp:575
The this pointer adjustment as well as an optional return adjustment for a thunk.
Definition: ABI.h:178
bool shouldMangleDeclName(const NamedDecl *D)
Definition: Mangle.cpp:107
Base object ctor.
Definition: ABI.h:26
ObjCContainerDecl - Represents a container for method declarations.
Definition: DeclObjC.h:967
bool isItaniumFamily() const
Does this ABI generally fall into the Itanium family of ABIs?
Definition: TargetCXXABI.h:148
The Microsoft ABI is the ABI used by Microsoft Visual Studio (and compatible compilers).
Definition: TargetCXXABI.h:126
Deleting dtor.
Definition: ABI.h:34
RangeSelector name(std::string ID)
Given a node with a "name", (like NamedDecl, DeclRefExpr or CxxCtorInitializer) selects the name's to...
static bool hasDefaultCXXMethodCC(ASTContext &Context, const CXXMethodDecl *MD)
Enums/classes describing ABI related information about constructors, destructors and thunks.
Represents an ObjC class declaration.
Definition: DeclObjC.h:1170
void mangleObjCMethodName(const ObjCMethodDecl *MD, raw_ostream &OS, bool includePrefixByte=true, bool includeCategoryNamespace=true)
Definition: Mangle.cpp:307
virtual void mangleCXXName(GlobalDecl GD, raw_ostream &)=0
bool writeName(const Decl *D, raw_ostream &OS)
Definition: Mangle.cpp:383
virtual void mangleMSGuidDecl(const MSGuidDecl *GD, raw_ostream &)
Definition: Mangle.cpp:222
bool hasAttr() const
Definition: DeclBase.h:547
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3876
std::vector< std::string > getAllManglings(const ObjCContainerDecl *OCD)
Definition: Mangle.cpp:431
Exposes information about the current target.
Definition: TargetInfo.h:179
CXXDtorType
C++ destructor types.
Definition: ABI.h:33
ASTContext & getASTContext() const
Definition: Mangle.h:72
bool isGNUFamily() const
Is this runtime basically of the GNU family of runtimes?
Definition: ObjCRuntime.h:118
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Definition: Decl.h:4094
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7181
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2645
DeclContext * getDeclContext()
Definition: DeclBase.h:439
Base object dtor.
Definition: ABI.h:36
void print(llvm::raw_ostream &OS) const
Prints the full selector name (e.g. "foo:bar:").
clang::ObjCRuntime ObjCRuntime
Definition: LangOptions.h:271
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1815
bool isInstanceMethod() const
Definition: DeclObjC.h:431
Selector getSelector() const
Definition: DeclObjC.h:330
Parts of a decomposed MSGuidDecl.
Definition: DeclCXX.h:3964
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:253
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:55
bool hasAttrs() const
Definition: DeclBase.h:489
static StringRef getClassSymbolPrefix(ObjCKind Kind, const ASTContext &Context)
Definition: Mangle.cpp:424
Kind
unsigned getBlockId(const BlockDecl *BD, bool Local)
Definition: Mangle.h:78
A global _GUID constant.
Definition: DeclCXX.h:3987
ASTContext & getASTContext() const LLVM_READONLY
Definition: DeclBase.cpp:414
const Decl * getDecl() const
Definition: GlobalDecl.h:102
void mangleDtorBlock(const CXXDestructorDecl *CD, CXXDtorType DT, const BlockDecl *BD, raw_ostream &Out)
Definition: Mangle.cpp:262
virtual bool shouldMangleCXXName(const NamedDecl *D)=0
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1926
MangleContext - Context for tracking state which persists across multiple calls to the C++ name mangl...
Definition: Mangle.h:44
void mangleObjCMethodNameAsSourceName(const ObjCMethodDecl *MD, raw_ostream &)
Definition: Mangle.cpp:364
std::vector< std::string > getAllManglings(const Decl *D)
Definition: Mangle.cpp:579
const llvm::DataLayout & getDataLayout() const
Definition: TargetInfo.h:1074
Complete object dtor.
Definition: ABI.h:35
CXXCtorType
C++ constructor types.
Definition: ABI.h:24
StringRef getName() const
Return the actual identifier string.
void mangleGlobalBlock(const BlockDecl *BD, const NamedDecl *ID, raw_ostream &Out)
Definition: Mangle.cpp:236
void mangleBlock(const DeclContext *DC, const BlockDecl *BD, raw_ostream &Out)
Definition: Mangle.cpp:271
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1302
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:27
StringRef getObjCRuntimeNameAsString() const
Produce a name to be used for class's metadata.
Definition: DeclObjC.cpp:1569
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
T * getAttr() const
Definition: DeclBase.h:543
static void mangleFunctionBlock(MangleContext &Context, StringRef Outer, const BlockDecl *BD, raw_ostream &Out)
Definition: Mangle.cpp:36
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
Definition: ASTContext.h:2121
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
CallingConv getCallConv() const
Definition: Type.h:3811
VTableContextBase * getVTableContext()
Defines the clang::TargetInfo interface.
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
Definition: TargetCXXABI.h:169
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:250
QualType getType() const
Definition: Decl.h:645
This represents a decl that may have a name.
Definition: Decl.h:223
std::string getName(const Decl *D)
Definition: Mangle.cpp:410
CCMangling
Definition: Mangle.cpp:49
void mangleCtorBlock(const CXXConstructorDecl *CD, CXXCtorType CT, const BlockDecl *BD, raw_ostream &Out)
Definition: Mangle.cpp:253
const LangOptions & getLangOpts() const
Definition: ASTContext.h:675
ObjCCategoryDecl * getCategory()
If this method is declared or implemented in a category, return that category.
Definition: DeclObjC.cpp:1171
ASTNameGenerator(ASTContext &Ctx)
Definition: Mangle.cpp:566
bool hasExternalFormalLinkage() const
True if this decl has external linkage.
Definition: Decl.h:373
static bool isExternC(const NamedDecl *ND)
Definition: Mangle.cpp:58