Lines 32-37
Link Here
|
32 |
#include "llvm/Support/ErrorHandling.h" |
32 |
#include "llvm/Support/ErrorHandling.h" |
33 |
#include "llvm/Support/raw_ostream.h" |
33 |
#include "llvm/Support/raw_ostream.h" |
34 |
|
34 |
|
|
|
35 |
#include <set> |
36 |
|
35 |
#define MANGLE_CHECKER 0 |
37 |
#define MANGLE_CHECKER 0 |
36 |
|
38 |
|
37 |
#if MANGLE_CHECKER |
39 |
#if MANGLE_CHECKER |
Lines 214-219
public:
Link Here
|
214 |
class CXXNameMangler { |
216 |
class CXXNameMangler { |
215 |
ItaniumMangleContextImpl &Context; |
217 |
ItaniumMangleContextImpl &Context; |
216 |
raw_ostream &Out; |
218 |
raw_ostream &Out; |
|
|
219 |
bool NullOut = false; |
220 |
bool DisableDerivedAbiTags = false; |
217 |
|
221 |
|
218 |
/// The "structor" is the top-level declaration being mangled, if |
222 |
/// The "structor" is the top-level declaration being mangled, if |
219 |
/// that's not a template specialization; otherwise it's the pattern |
223 |
/// that's not a template specialization; otherwise it's the pattern |
Lines 263-268
class CXXNameMangler {
Link Here
|
263 |
|
267 |
|
264 |
} FunctionTypeDepth; |
268 |
} FunctionTypeDepth; |
265 |
|
269 |
|
|
|
270 |
// abi_tag is a gcc attribute, taking one or more strings called "tags". |
271 |
// |
272 |
// the goal is to annotage against which version of a library an object was |
273 |
// build and to be able to provide backwards compatibility ("dual abi"). |
274 |
// |
275 |
// for this the emitted mangled names have to be different, while you don't |
276 |
// want the user to have to use different names in the source. |
277 |
// |
278 |
// the abi_tag can be present on Struct, Var and Function declarations as |
279 |
// "explicit" tag, and on inline Namespace as "implicit" tag. Explicit tags |
280 |
// are always emitted after the unqualified name, and (implicit) tags on |
281 |
// namespace are not. |
282 |
// |
283 |
// For functions and variables there is a set of "implicitly available" |
284 |
// tags. These tags are: all tags from the namespace/structs the name is |
285 |
// embedded in, all tags from any template arguments of the name, and, for |
286 |
// functions, alls tags used anywhere in the <bare-function-type> (i.e. |
287 |
// parameters and sometimes the return type). |
288 |
// |
289 |
// For functions this is basically the list of all tags from the signature |
290 |
// without the unqualified name and usually without the return type of the |
291 |
// function. In `operator Type()` Type is NOT part of that list, as it is |
292 |
// part of the unqualified name! |
293 |
// |
294 |
// Now all tags from the function return type/variable type which are not |
295 |
// "implicitly available" must be added to the explicit list of tags, and |
296 |
// are emitted after the unqualified name. |
297 |
// |
298 |
// Example: |
299 |
// namespace std { |
300 |
// inline namespace __cxx11 __attribute__((__abi_tag__("cxx11"))) { } |
301 |
// inline namespace __cxx11 { |
302 |
// struct string { }; |
303 |
// } |
304 |
// } |
305 |
// |
306 |
// std::string foo(); // needs abi tag "cxx11" on foo |
307 |
// std::string foo(std::string); // does NOT need abi tag "cxx11" on foo |
308 |
// __attribute__((__abi_tag__("cxx11"))) |
309 |
// std::string foo2(std::string); // emit abi tag "cxx11" on foo anyway |
310 |
// |
311 |
// The tags are sorted by name before emitting, and are serialized as |
312 |
// <abitag> ::= B <"tag" source-name> |
313 |
|
314 |
typedef SmallVector<StringRef, 4> AbiTagList; |
315 |
|
316 |
// state to gather all implicit and explicit tags used in a mangled name. |
317 |
// must always have an instance of this while emitting any name to keep |
318 |
// track. |
319 |
// |
320 |
// TODO(abitags): how to handle substituted names? they should add the tags used in |
321 |
// the substitution to the list of available tags. |
322 |
class AbiTagState final { |
323 |
public: |
324 |
//! all abi tags used implicitly or explicitly |
325 |
std::set<StringRef> UsedAbiTags; |
326 |
//! all explicit abi tags (i.e. not from namespace) |
327 |
std::set<StringRef> EmittedAbiTags; |
328 |
|
329 |
AbiTagState* &LinkHead; |
330 |
AbiTagState *Parent{nullptr}; |
331 |
|
332 |
bool LinkActive{false}; |
333 |
|
334 |
explicit AbiTagState(AbiTagState* &linkHead) |
335 |
: LinkHead(linkHead) { |
336 |
Parent = LinkHead; |
337 |
LinkHead = this; |
338 |
LinkActive = true; |
339 |
} |
340 |
|
341 |
// no copy, no move |
342 |
AbiTagState(AbiTagState const&) = delete; |
343 |
AbiTagState& operator=(AbiTagState const&) = delete; |
344 |
|
345 |
~AbiTagState() { |
346 |
pop(); |
347 |
} |
348 |
|
349 |
void pop() { |
350 |
if (!LinkActive) return; |
351 |
|
352 |
assert(LinkHead == this && "abi tag link head must point to us on destruction"); |
353 |
LinkActive = false; |
354 |
if (Parent) { |
355 |
Parent->UsedAbiTags.insert(UsedAbiTags.begin(), UsedAbiTags.end()); |
356 |
Parent->EmittedAbiTags.insert(EmittedAbiTags.begin(), EmittedAbiTags.end()); |
357 |
} |
358 |
LinkHead = Parent; |
359 |
} |
360 |
|
361 |
void write(raw_ostream &Out, const NamedDecl *ND, const AbiTagList *AdditionalAbiTags) { |
362 |
ND = cast<NamedDecl>(ND->getCanonicalDecl()); |
363 |
|
364 |
if (dyn_cast<FunctionDecl>(ND) || dyn_cast<VarDecl>(ND)) { |
365 |
// assert(AdditionalAbiTags && "function and variables need a list of additional abi tags"); |
366 |
} else { |
367 |
assert(!AdditionalAbiTags && "only function and variables need a list of additional abi tags"); |
368 |
if (const auto* NS = dyn_cast<NamespaceDecl>(ND)) { |
369 |
if (const auto* AbiTag = NS->getAttr<AbiTagAttr>()) { |
370 |
for (const auto& Tag: AbiTag->tags()) { |
371 |
UsedAbiTags.insert(Tag); |
372 |
} |
373 |
} |
374 |
// don't emit abi tags for namespaces |
375 |
return; |
376 |
} |
377 |
} |
378 |
|
379 |
AbiTagList TagList; |
380 |
if (const auto* AbiTag = ND->getAttr<AbiTagAttr>()) { |
381 |
for (const auto& Tag: AbiTag->tags()) { |
382 |
UsedAbiTags.insert(Tag); |
383 |
// AbiTag->tags() is sorted and has no duplicates |
384 |
TagList.push_back(Tag); |
385 |
} |
386 |
} |
387 |
|
388 |
if (AdditionalAbiTags) { |
389 |
for (const auto& Tag: *AdditionalAbiTags) { |
390 |
UsedAbiTags.insert(Tag); |
391 |
if (std::find(TagList.begin(), TagList.end(), Tag) == TagList.end()) { |
392 |
// don't insert duplicates |
393 |
TagList.push_back(Tag); |
394 |
} |
395 |
} |
396 |
// AbiTag->tags() are already sorted; only add if we had additional tags |
397 |
std::sort(TagList.begin(), TagList.end()); |
398 |
} |
399 |
|
400 |
writeSortedUniqueAbiTags(Out, TagList); |
401 |
} |
402 |
|
403 |
protected: |
404 |
template<typename TagList> |
405 |
void writeSortedUniqueAbiTags(raw_ostream &Out, TagList const& AbiTags) { |
406 |
for (const auto& Tag: AbiTags) { |
407 |
EmittedAbiTags.insert(Tag); |
408 |
Out << "B"; |
409 |
Out << Tag.size(); |
410 |
Out << Tag; |
411 |
} |
412 |
} |
413 |
} *AbiTags = nullptr; |
414 |
AbiTagState AbiTagsRoot{AbiTags}; |
415 |
|
416 |
struct TemporaryDisableDerivedAbiTags { |
417 |
bool& StateRef; |
418 |
bool OldState; |
419 |
|
420 |
TemporaryDisableDerivedAbiTags(bool& State, bool Disable = true) |
421 |
: StateRef(State) { |
422 |
OldState = StateRef; |
423 |
StateRef = Disable; |
424 |
} |
425 |
TemporaryDisableDerivedAbiTags(TemporaryDisableDerivedAbiTags const&) = delete; |
426 |
~TemporaryDisableDerivedAbiTags() { |
427 |
StateRef = OldState; |
428 |
} |
429 |
}; |
430 |
|
266 |
llvm::DenseMap<uintptr_t, unsigned> Substitutions; |
431 |
llvm::DenseMap<uintptr_t, unsigned> Substitutions; |
267 |
|
432 |
|
268 |
ASTContext &getASTContext() const { return Context.getASTContext(); } |
433 |
ASTContext &getASTContext() const { return Context.getASTContext(); } |
Lines 285-290
public:
Link Here
|
285 |
: Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type), |
450 |
: Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type), |
286 |
SeqID(0) { } |
451 |
SeqID(0) { } |
287 |
|
452 |
|
|
|
453 |
CXXNameMangler(CXXNameMangler &Outer, llvm::raw_null_ostream &Out_) |
454 |
: Context(Outer.Context), Out(Out_), NullOut(true), Structor(Outer.Structor), StructorType(Outer.StructorType), |
455 |
SeqID(Outer.SeqID) { } |
456 |
|
288 |
#if MANGLE_CHECKER |
457 |
#if MANGLE_CHECKER |
289 |
~CXXNameMangler() { |
458 |
~CXXNameMangler() { |
290 |
if (Out.str()[0] == '\01') |
459 |
if (Out.str()[0] == '\01') |
Lines 298-315
public:
Link Here
|
298 |
#endif |
467 |
#endif |
299 |
raw_ostream &getStream() { return Out; } |
468 |
raw_ostream &getStream() { return Out; } |
300 |
|
469 |
|
|
|
470 |
void disableDerivedAbiTags() { DisableDerivedAbiTags = true; } |
471 |
|
301 |
void mangle(const NamedDecl *D); |
472 |
void mangle(const NamedDecl *D); |
302 |
void mangleCallOffset(int64_t NonVirtual, int64_t Virtual); |
473 |
void mangleCallOffset(int64_t NonVirtual, int64_t Virtual); |
303 |
void mangleNumber(const llvm::APSInt &I); |
474 |
void mangleNumber(const llvm::APSInt &I); |
304 |
void mangleNumber(int64_t Number); |
475 |
void mangleNumber(int64_t Number); |
305 |
void mangleFloat(const llvm::APFloat &F); |
476 |
void mangleFloat(const llvm::APFloat &F); |
306 |
void mangleFunctionEncoding(const FunctionDecl *FD); |
477 |
void mangleFunctionEncoding(const FunctionDecl *FD, bool ExcludeUnqualifiedName = false); |
307 |
void mangleSeqID(unsigned SeqID); |
478 |
void mangleSeqID(unsigned SeqID); |
308 |
void mangleName(const NamedDecl *ND); |
479 |
void mangleName(const NamedDecl *ND, bool ExcludeUnqualifiedName = false); |
309 |
void mangleType(QualType T); |
480 |
void mangleType(QualType T); |
310 |
void mangleNameOrStandardSubstitution(const NamedDecl *ND); |
481 |
void mangleNameOrStandardSubstitution(const NamedDecl *ND); |
311 |
|
482 |
|
312 |
private: |
483 |
private: |
|
|
484 |
void writeAbiTags(const NamedDecl *ND, const AbiTagList *AdditionalAbiTags = nullptr); |
313 |
|
485 |
|
314 |
bool mangleSubstitution(const NamedDecl *ND); |
486 |
bool mangleSubstitution(const NamedDecl *ND); |
315 |
bool mangleSubstitution(QualType T); |
487 |
bool mangleSubstitution(QualType T); |
Lines 336-366
private:
Link Here
|
336 |
DeclarationName name, |
508 |
DeclarationName name, |
337 |
unsigned KnownArity = UnknownArity); |
509 |
unsigned KnownArity = UnknownArity); |
338 |
|
510 |
|
339 |
void mangleName(const TemplateDecl *TD, |
511 |
void mangleFunctionEncodingBareType(const FunctionDecl *FD); |
|
|
512 |
|
513 |
void mangleNameWithAbiTags(const NamedDecl *ND, |
514 |
const AbiTagList *AdditionalAbiTags, |
515 |
bool ExcludeUnqualifiedName); |
516 |
void mangleTemplateName(const TemplateDecl *TD, |
517 |
const AbiTagList *AdditionalAbiTags, |
518 |
bool ExcludeUnqualifiedName, |
340 |
const TemplateArgument *TemplateArgs, |
519 |
const TemplateArgument *TemplateArgs, |
341 |
unsigned NumTemplateArgs); |
520 |
unsigned NumTemplateArgs); |
342 |
void mangleUnqualifiedName(const NamedDecl *ND) { |
521 |
void mangleUnqualifiedName(const NamedDecl *ND, const AbiTagList *AdditionalAbiTags) { |
343 |
mangleUnqualifiedName(ND, ND->getDeclName(), UnknownArity); |
522 |
mangleUnqualifiedName(ND, ND->getDeclName(), UnknownArity, AdditionalAbiTags); |
344 |
} |
523 |
} |
345 |
void mangleUnqualifiedName(const NamedDecl *ND, DeclarationName Name, |
524 |
void mangleUnqualifiedName(const NamedDecl *ND, DeclarationName Name, |
346 |
unsigned KnownArity); |
525 |
unsigned KnownArity, const AbiTagList *AdditionalAbiTags); |
347 |
void mangleUnscopedName(const NamedDecl *ND); |
526 |
void mangleUnscopedName(const NamedDecl *ND, const AbiTagList *AdditionalAbiTags); |
348 |
void mangleUnscopedTemplateName(const TemplateDecl *ND); |
527 |
void mangleUnscopedTemplateName(const TemplateDecl *ND, |
349 |
void mangleUnscopedTemplateName(TemplateName); |
528 |
const AbiTagList *AdditionalAbiTags); |
|
|
529 |
void mangleUnscopedTemplateName(TemplateName, |
530 |
const AbiTagList *AdditionalAbiTags); |
350 |
void mangleSourceName(const IdentifierInfo *II); |
531 |
void mangleSourceName(const IdentifierInfo *II); |
351 |
void mangleLocalName(const Decl *D); |
532 |
void mangleLocalName(const Decl *D, |
|
|
533 |
const AbiTagList *AdditionalAbiTags, |
534 |
bool ExcludeUnqualifiedName); |
352 |
void mangleBlockForPrefix(const BlockDecl *Block); |
535 |
void mangleBlockForPrefix(const BlockDecl *Block); |
353 |
void mangleUnqualifiedBlock(const BlockDecl *Block); |
536 |
void mangleUnqualifiedBlock(const BlockDecl *Block); |
354 |
void mangleLambda(const CXXRecordDecl *Lambda); |
537 |
void mangleLambda(const CXXRecordDecl *Lambda); |
355 |
void mangleNestedName(const NamedDecl *ND, const DeclContext *DC, |
538 |
void mangleNestedName(const NamedDecl *ND, const DeclContext *DC, |
356 |
bool NoFunction=false); |
539 |
const AbiTagList *AdditionalAbiTags, |
|
|
540 |
bool NoFunction, |
541 |
bool ExcludeUnqualifiedName); |
357 |
void mangleNestedName(const TemplateDecl *TD, |
542 |
void mangleNestedName(const TemplateDecl *TD, |
|
|
543 |
const AbiTagList *AdditionalAbiTags, |
544 |
bool ExcludeUnqualifiedName, |
358 |
const TemplateArgument *TemplateArgs, |
545 |
const TemplateArgument *TemplateArgs, |
359 |
unsigned NumTemplateArgs); |
546 |
unsigned NumTemplateArgs); |
360 |
void manglePrefix(NestedNameSpecifier *qualifier); |
547 |
void manglePrefix(NestedNameSpecifier *qualifier); |
361 |
void manglePrefix(const DeclContext *DC, bool NoFunction=false); |
548 |
void manglePrefix(const DeclContext *DC, bool NoFunction=false); |
362 |
void manglePrefix(QualType type); |
549 |
void manglePrefix(QualType type); |
363 |
void mangleTemplatePrefix(const TemplateDecl *ND, bool NoFunction=false); |
550 |
void mangleTemplatePrefix(const TemplateDecl *ND, |
|
|
551 |
const AbiTagList *AdditionalAbiTags, |
552 |
bool NoFunction = false, |
553 |
bool ExcludeUnqualifiedName = false); |
364 |
void mangleTemplatePrefix(TemplateName Template); |
554 |
void mangleTemplatePrefix(TemplateName Template); |
365 |
bool mangleUnresolvedTypeOrSimpleId(QualType DestroyedType, |
555 |
bool mangleUnresolvedTypeOrSimpleId(QualType DestroyedType, |
366 |
StringRef Prefix = ""); |
556 |
StringRef Prefix = ""); |
Lines 406-411
private:
Link Here
|
406 |
void mangleTemplateParameter(unsigned Index); |
596 |
void mangleTemplateParameter(unsigned Index); |
407 |
|
597 |
|
408 |
void mangleFunctionParam(const ParmVarDecl *parm); |
598 |
void mangleFunctionParam(const ParmVarDecl *parm); |
|
|
599 |
|
600 |
std::set<StringRef> getTagsFromPrefixAndTemplateArguments(const NamedDecl *ND); |
601 |
AbiTagList makeAdditionalTagsForFunction(const FunctionDecl *FD); |
602 |
AbiTagList makeAdditionalTagsForVariable(const VarDecl *VD); |
409 |
}; |
603 |
}; |
410 |
|
604 |
|
411 |
} |
605 |
} |
Lines 456-461
bool ItaniumMangleContextImpl::shouldMangleCXXName(const NamedDecl *D) {
Link Here
|
456 |
return true; |
650 |
return true; |
457 |
} |
651 |
} |
458 |
|
652 |
|
|
|
653 |
void CXXNameMangler::writeAbiTags(const NamedDecl *ND, const AbiTagList *AdditionalAbiTags) { |
654 |
assert(AbiTags && "require AbiTagState"); |
655 |
if (AbiTags) AbiTags->write(Out, ND, DisableDerivedAbiTags ? nullptr : AdditionalAbiTags); |
656 |
} |
657 |
|
459 |
void CXXNameMangler::mangle(const NamedDecl *D) { |
658 |
void CXXNameMangler::mangle(const NamedDecl *D) { |
460 |
// <mangled-name> ::= _Z <encoding> |
659 |
// <mangled-name> ::= _Z <encoding> |
461 |
// ::= <data name> |
660 |
// ::= <data name> |
Lines 471-484
void CXXNameMangler::mangle(const NamedDecl *D) {
Link Here
|
471 |
mangleName(cast<FieldDecl>(D)); |
670 |
mangleName(cast<FieldDecl>(D)); |
472 |
} |
671 |
} |
473 |
|
672 |
|
474 |
void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) { |
673 |
void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD, bool ExcludeUnqualifiedName) { |
475 |
// <encoding> ::= <function name> <bare-function-type> |
|
|
476 |
mangleName(FD); |
477 |
|
478 |
// Don't mangle in the type if this isn't a decl we should typically mangle. |
674 |
// Don't mangle in the type if this isn't a decl we should typically mangle. |
479 |
if (!Context.shouldMangleDeclName(FD)) |
675 |
if (!Context.shouldMangleDeclName(FD)) { |
|
|
676 |
mangleNameWithAbiTags(FD, /* AdditionalAbiTags */ nullptr, ExcludeUnqualifiedName); |
480 |
return; |
677 |
return; |
|
|
678 |
} |
679 |
|
680 |
// <encoding> ::= <function name> <bare-function-type> |
681 |
|
682 |
if (ExcludeUnqualifiedName) |
683 |
{ |
684 |
// running makeAdditionalTagsForFunction would loop, don't need it here anyway |
685 |
mangleNameWithAbiTags(FD, /* AdditionalAbiTags */ nullptr, ExcludeUnqualifiedName); |
686 |
} else { |
687 |
AbiTagList AdditionalAbiTags = makeAdditionalTagsForFunction(FD); |
688 |
mangleNameWithAbiTags(FD, &AdditionalAbiTags, ExcludeUnqualifiedName); |
689 |
} |
690 |
|
691 |
mangleFunctionEncodingBareType(FD); |
692 |
} |
481 |
|
693 |
|
|
|
694 |
void CXXNameMangler::mangleFunctionEncodingBareType(const FunctionDecl *FD) { |
482 |
if (FD->hasAttr<EnableIfAttr>()) { |
695 |
if (FD->hasAttr<EnableIfAttr>()) { |
483 |
FunctionTypeDepthState Saved = FunctionTypeDepth.push(); |
696 |
FunctionTypeDepthState Saved = FunctionTypeDepth.push(); |
484 |
Out << "Ua9enable_ifI"; |
697 |
Out << "Ua9enable_ifI"; |
Lines 582-588
isTemplate(const NamedDecl *ND, const TemplateArgumentList *&TemplateArgs) {
Link Here
|
582 |
return nullptr; |
795 |
return nullptr; |
583 |
} |
796 |
} |
584 |
|
797 |
|
585 |
void CXXNameMangler::mangleName(const NamedDecl *ND) { |
798 |
// must not be run from mangleLocalName for the <entity name> as it would loop otherwise. |
|
|
799 |
void CXXNameMangler::mangleName(const NamedDecl *ND, bool ExcludeUnqualifiedName) { |
800 |
if (!ExcludeUnqualifiedName) { |
801 |
if (const VarDecl *VD = dyn_cast<VarDecl>(ND)) { |
802 |
AbiTagList VariableAdditionalAbiTags = makeAdditionalTagsForVariable(VD); |
803 |
mangleNameWithAbiTags(VD, &VariableAdditionalAbiTags, ExcludeUnqualifiedName); |
804 |
return; |
805 |
} |
806 |
} |
807 |
mangleNameWithAbiTags(ND, nullptr, ExcludeUnqualifiedName); |
808 |
} |
809 |
|
810 |
void CXXNameMangler::mangleNameWithAbiTags(const NamedDecl *ND, |
811 |
const AbiTagList *AdditionalAbiTags, |
812 |
bool ExcludeUnqualifiedName) { |
586 |
// <name> ::= <nested-name> |
813 |
// <name> ::= <nested-name> |
587 |
// ::= <unscoped-name> |
814 |
// ::= <unscoped-name> |
588 |
// ::= <unscoped-template-name> <template-args> |
815 |
// ::= <unscoped-template-name> <template-args> |
Lines 598-604
void CXXNameMangler::mangleName(const NamedDecl *ND) {
Link Here
|
598 |
while (!DC->isNamespace() && !DC->isTranslationUnit()) |
825 |
while (!DC->isNamespace() && !DC->isTranslationUnit()) |
599 |
DC = getEffectiveParentContext(DC); |
826 |
DC = getEffectiveParentContext(DC); |
600 |
else if (GetLocalClassDecl(ND)) { |
827 |
else if (GetLocalClassDecl(ND)) { |
601 |
mangleLocalName(ND); |
828 |
mangleLocalName(ND, AdditionalAbiTags, ExcludeUnqualifiedName); |
602 |
return; |
829 |
return; |
603 |
} |
830 |
} |
604 |
|
831 |
|
Lines 608-683
void CXXNameMangler::mangleName(const NamedDecl *ND) {
Link Here
|
608 |
// Check if we have a template. |
835 |
// Check if we have a template. |
609 |
const TemplateArgumentList *TemplateArgs = nullptr; |
836 |
const TemplateArgumentList *TemplateArgs = nullptr; |
610 |
if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { |
837 |
if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { |
611 |
mangleUnscopedTemplateName(TD); |
838 |
if (!ExcludeUnqualifiedName) |
|
|
839 |
mangleUnscopedTemplateName(TD, AdditionalAbiTags); |
612 |
mangleTemplateArgs(*TemplateArgs); |
840 |
mangleTemplateArgs(*TemplateArgs); |
613 |
return; |
841 |
return; |
614 |
} |
842 |
} |
615 |
|
843 |
|
616 |
mangleUnscopedName(ND); |
844 |
if (!ExcludeUnqualifiedName) |
|
|
845 |
mangleUnscopedName(ND, AdditionalAbiTags); |
617 |
return; |
846 |
return; |
618 |
} |
847 |
} |
619 |
|
848 |
|
620 |
if (isLocalContainerContext(DC)) { |
849 |
if (isLocalContainerContext(DC)) { |
621 |
mangleLocalName(ND); |
850 |
mangleLocalName(ND, AdditionalAbiTags, ExcludeUnqualifiedName); |
622 |
return; |
851 |
return; |
623 |
} |
852 |
} |
624 |
|
853 |
|
625 |
mangleNestedName(ND, DC); |
854 |
mangleNestedName(ND, DC, AdditionalAbiTags, /* NoFunction */ false, ExcludeUnqualifiedName); |
626 |
} |
855 |
} |
627 |
void CXXNameMangler::mangleName(const TemplateDecl *TD, |
856 |
|
628 |
const TemplateArgument *TemplateArgs, |
857 |
void CXXNameMangler::mangleTemplateName(const TemplateDecl *TD, |
629 |
unsigned NumTemplateArgs) { |
858 |
const AbiTagList *AdditionalAbiTags, |
|
|
859 |
bool ExcludeUnqualifiedName, |
860 |
const TemplateArgument *TemplateArgs, |
861 |
unsigned NumTemplateArgs) { |
630 |
const DeclContext *DC = IgnoreLinkageSpecDecls(getEffectiveDeclContext(TD)); |
862 |
const DeclContext *DC = IgnoreLinkageSpecDecls(getEffectiveDeclContext(TD)); |
631 |
|
863 |
|
632 |
if (DC->isTranslationUnit() || isStdNamespace(DC)) { |
864 |
if (DC->isTranslationUnit() || isStdNamespace(DC)) { |
633 |
mangleUnscopedTemplateName(TD); |
865 |
if (!ExcludeUnqualifiedName) |
|
|
866 |
mangleUnscopedTemplateName(TD, AdditionalAbiTags); |
634 |
mangleTemplateArgs(TemplateArgs, NumTemplateArgs); |
867 |
mangleTemplateArgs(TemplateArgs, NumTemplateArgs); |
635 |
} else { |
868 |
} else { |
636 |
mangleNestedName(TD, TemplateArgs, NumTemplateArgs); |
869 |
mangleNestedName(TD, AdditionalAbiTags, ExcludeUnqualifiedName, TemplateArgs, NumTemplateArgs); |
637 |
} |
870 |
} |
638 |
} |
871 |
} |
639 |
|
872 |
|
640 |
void CXXNameMangler::mangleUnscopedName(const NamedDecl *ND) { |
873 |
void CXXNameMangler::mangleUnscopedName(const NamedDecl *ND, const AbiTagList *AdditionalAbiTags) { |
641 |
// <unscoped-name> ::= <unqualified-name> |
874 |
// <unscoped-name> ::= <unqualified-name> |
642 |
// ::= St <unqualified-name> # ::std:: |
875 |
// ::= St <unqualified-name> # ::std:: |
643 |
|
876 |
|
644 |
if (isStdNamespace(IgnoreLinkageSpecDecls(getEffectiveDeclContext(ND)))) |
877 |
if (isStdNamespace(IgnoreLinkageSpecDecls(getEffectiveDeclContext(ND)))) |
645 |
Out << "St"; |
878 |
Out << "St"; |
646 |
|
879 |
|
647 |
mangleUnqualifiedName(ND); |
880 |
mangleUnqualifiedName(ND, AdditionalAbiTags); |
648 |
} |
881 |
} |
649 |
|
882 |
|
650 |
void CXXNameMangler::mangleUnscopedTemplateName(const TemplateDecl *ND) { |
883 |
void CXXNameMangler::mangleUnscopedTemplateName(const TemplateDecl *ND, |
|
|
884 |
const AbiTagList *AdditionalAbiTags) { |
651 |
// <unscoped-template-name> ::= <unscoped-name> |
885 |
// <unscoped-template-name> ::= <unscoped-name> |
652 |
// ::= <substitution> |
886 |
// ::= <substitution> |
653 |
if (mangleSubstitution(ND)) |
887 |
if (mangleSubstitution(ND)) |
654 |
return; |
888 |
return; |
655 |
|
889 |
|
656 |
// <template-template-param> ::= <template-param> |
890 |
// <template-template-param> ::= <template-param> |
657 |
if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) |
891 |
if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) { |
|
|
892 |
assert(!AdditionalAbiTags && "template template param cannot have abi tags"); // TODO(abitags) |
658 |
mangleTemplateParameter(TTP->getIndex()); |
893 |
mangleTemplateParameter(TTP->getIndex()); |
659 |
else |
894 |
} else { |
660 |
mangleUnscopedName(ND->getTemplatedDecl()); |
895 |
mangleUnscopedName(ND->getTemplatedDecl(), AdditionalAbiTags); |
|
|
896 |
} |
661 |
|
897 |
|
662 |
addSubstitution(ND); |
898 |
addSubstitution(ND); |
663 |
} |
899 |
} |
664 |
|
900 |
|
665 |
void CXXNameMangler::mangleUnscopedTemplateName(TemplateName Template) { |
901 |
void CXXNameMangler::mangleUnscopedTemplateName(TemplateName Template, |
|
|
902 |
const AbiTagList *AdditionalAbiTags) { |
666 |
// <unscoped-template-name> ::= <unscoped-name> |
903 |
// <unscoped-template-name> ::= <unscoped-name> |
667 |
// ::= <substitution> |
904 |
// ::= <substitution> |
668 |
if (TemplateDecl *TD = Template.getAsTemplateDecl()) |
905 |
if (TemplateDecl *TD = Template.getAsTemplateDecl()) |
669 |
return mangleUnscopedTemplateName(TD); |
906 |
return mangleUnscopedTemplateName(TD, AdditionalAbiTags); |
670 |
|
907 |
|
671 |
if (mangleSubstitution(Template)) |
908 |
if (mangleSubstitution(Template)) |
672 |
return; |
909 |
return; |
673 |
|
910 |
|
|
|
911 |
assert(!AdditionalAbiTags && "dependent template name cannot have abi tags"); // TODO(abitags) |
912 |
|
674 |
DependentTemplateName *Dependent = Template.getAsDependentTemplateName(); |
913 |
DependentTemplateName *Dependent = Template.getAsDependentTemplateName(); |
675 |
assert(Dependent && "Not a dependent template name?"); |
914 |
assert(Dependent && "Not a dependent template name?"); |
676 |
if (const IdentifierInfo *Id = Dependent->getIdentifier()) |
915 |
if (const IdentifierInfo *Id = Dependent->getIdentifier()) |
677 |
mangleSourceName(Id); |
916 |
mangleSourceName(Id); |
678 |
else |
917 |
else |
679 |
mangleOperatorName(Dependent->getOperator(), UnknownArity); |
918 |
mangleOperatorName(Dependent->getOperator(), UnknownArity); |
680 |
|
919 |
|
681 |
addSubstitution(Template); |
920 |
addSubstitution(Template); |
682 |
} |
921 |
} |
683 |
|
922 |
|
Lines 837-842
void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier *qualifier,
Link Here
|
837 |
else |
1076 |
else |
838 |
Out << "sr"; |
1077 |
Out << "sr"; |
839 |
mangleSourceName(qualifier->getAsNamespace()->getIdentifier()); |
1078 |
mangleSourceName(qualifier->getAsNamespace()->getIdentifier()); |
|
|
1079 |
writeAbiTags(qualifier->getAsNamespace()); |
840 |
break; |
1080 |
break; |
841 |
case NestedNameSpecifier::NamespaceAlias: |
1081 |
case NestedNameSpecifier::NamespaceAlias: |
842 |
if (qualifier->getPrefix()) |
1082 |
if (qualifier->getPrefix()) |
Lines 845-850
void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier *qualifier,
Link Here
|
845 |
else |
1085 |
else |
846 |
Out << "sr"; |
1086 |
Out << "sr"; |
847 |
mangleSourceName(qualifier->getAsNamespaceAlias()->getIdentifier()); |
1087 |
mangleSourceName(qualifier->getAsNamespaceAlias()->getIdentifier()); |
|
|
1088 |
writeAbiTags(qualifier->getAsNamespaceAlias()); |
848 |
break; |
1089 |
break; |
849 |
|
1090 |
|
850 |
case NestedNameSpecifier::TypeSpec: |
1091 |
case NestedNameSpecifier::TypeSpec: |
Lines 879-884
void CXXNameMangler::mangleUnresolvedPrefix(NestedNameSpecifier *qualifier,
Link Here
|
879 |
Out << "sr"; |
1120 |
Out << "sr"; |
880 |
|
1121 |
|
881 |
mangleSourceName(qualifier->getAsIdentifier()); |
1122 |
mangleSourceName(qualifier->getAsIdentifier()); |
|
|
1123 |
// an Identifier has no type information, so we can't emit abi tags for it |
882 |
break; |
1124 |
break; |
883 |
} |
1125 |
} |
884 |
|
1126 |
|
Lines 924-930
void CXXNameMangler::mangleUnresolvedName(NestedNameSpecifier *qualifier,
Link Here
|
924 |
|
1166 |
|
925 |
void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, |
1167 |
void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND, |
926 |
DeclarationName Name, |
1168 |
DeclarationName Name, |
927 |
unsigned KnownArity) { |
1169 |
unsigned KnownArity, |
|
|
1170 |
const AbiTagList *AdditionalAbiTags) { |
928 |
unsigned Arity = KnownArity; |
1171 |
unsigned Arity = KnownArity; |
929 |
// <unqualified-name> ::= <operator-name> |
1172 |
// <unqualified-name> ::= <operator-name> |
930 |
// ::= <ctor-dtor-name> |
1173 |
// ::= <ctor-dtor-name> |
Lines 943-948
void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
Link Here
|
943 |
Out << 'L'; |
1186 |
Out << 'L'; |
944 |
|
1187 |
|
945 |
mangleSourceName(II); |
1188 |
mangleSourceName(II); |
|
|
1189 |
writeAbiTags(ND, AdditionalAbiTags); |
946 |
break; |
1190 |
break; |
947 |
} |
1191 |
} |
948 |
|
1192 |
|
Lines 982-987
void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
Link Here
|
982 |
assert(FD->getIdentifier() && "Data member name isn't an identifier!"); |
1226 |
assert(FD->getIdentifier() && "Data member name isn't an identifier!"); |
983 |
|
1227 |
|
984 |
mangleSourceName(FD->getIdentifier()); |
1228 |
mangleSourceName(FD->getIdentifier()); |
|
|
1229 |
// TODO(abitags): not emitting abi tags: internal name anyway |
985 |
break; |
1230 |
break; |
986 |
} |
1231 |
} |
987 |
|
1232 |
|
Lines 1002-1007
void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
Link Here
|
1002 |
assert(D->getDeclName().getAsIdentifierInfo() && |
1247 |
assert(D->getDeclName().getAsIdentifierInfo() && |
1003 |
"Typedef was not named!"); |
1248 |
"Typedef was not named!"); |
1004 |
mangleSourceName(D->getDeclName().getAsIdentifierInfo()); |
1249 |
mangleSourceName(D->getDeclName().getAsIdentifierInfo()); |
|
|
1250 |
assert(!AdditionalAbiTags && "Type cannot have additional abi tags"); |
1251 |
// explicit abi tags are still possible; take from underlying type, not from typedef. |
1252 |
writeAbiTags(TD, nullptr); |
1005 |
break; |
1253 |
break; |
1006 |
} |
1254 |
} |
1007 |
|
1255 |
|
Lines 1011-1016
void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
Link Here
|
1011 |
// <lambda-sig> ::= <parameter-type>+ # Parameter types or 'v' for 'void'. |
1259 |
// <lambda-sig> ::= <parameter-type>+ # Parameter types or 'v' for 'void'. |
1012 |
if (const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(TD)) { |
1260 |
if (const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(TD)) { |
1013 |
if (Record->isLambda() && Record->getLambdaManglingNumber()) { |
1261 |
if (Record->isLambda() && Record->getLambdaManglingNumber()) { |
|
|
1262 |
assert(!AdditionalAbiTags && "Lambda type cannot have additional abi tags"); |
1014 |
mangleLambda(Record); |
1263 |
mangleLambda(Record); |
1015 |
break; |
1264 |
break; |
1016 |
} |
1265 |
} |
Lines 1022-1027
void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
Link Here
|
1022 |
if (UnnamedMangle > 1) |
1271 |
if (UnnamedMangle > 1) |
1023 |
Out << llvm::utostr(UnnamedMangle - 2); |
1272 |
Out << llvm::utostr(UnnamedMangle - 2); |
1024 |
Out << '_'; |
1273 |
Out << '_'; |
|
|
1274 |
writeAbiTags(TD, AdditionalAbiTags); |
1025 |
break; |
1275 |
break; |
1026 |
} |
1276 |
} |
1027 |
|
1277 |
|
Lines 1054-1059
void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
Link Here
|
1054 |
// Otherwise, use the complete constructor name. This is relevant if a |
1304 |
// Otherwise, use the complete constructor name. This is relevant if a |
1055 |
// class with a constructor is declared within a constructor. |
1305 |
// class with a constructor is declared within a constructor. |
1056 |
mangleCXXCtorType(Ctor_Complete); |
1306 |
mangleCXXCtorType(Ctor_Complete); |
|
|
1307 |
writeAbiTags(ND, AdditionalAbiTags); |
1057 |
break; |
1308 |
break; |
1058 |
|
1309 |
|
1059 |
case DeclarationName::CXXDestructorName: |
1310 |
case DeclarationName::CXXDestructorName: |
Lines 1065-1070
void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
Link Here
|
1065 |
// Otherwise, use the complete destructor name. This is relevant if a |
1316 |
// Otherwise, use the complete destructor name. This is relevant if a |
1066 |
// class with a destructor is declared within a destructor. |
1317 |
// class with a destructor is declared within a destructor. |
1067 |
mangleCXXDtorType(Dtor_Complete); |
1318 |
mangleCXXDtorType(Dtor_Complete); |
|
|
1319 |
writeAbiTags(ND, AdditionalAbiTags); |
1068 |
break; |
1320 |
break; |
1069 |
|
1321 |
|
1070 |
case DeclarationName::CXXOperatorName: |
1322 |
case DeclarationName::CXXOperatorName: |
Lines 1080-1085
void CXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
Link Here
|
1080 |
case DeclarationName::CXXConversionFunctionName: |
1332 |
case DeclarationName::CXXConversionFunctionName: |
1081 |
case DeclarationName::CXXLiteralOperatorName: |
1333 |
case DeclarationName::CXXLiteralOperatorName: |
1082 |
mangleOperatorName(Name, Arity); |
1334 |
mangleOperatorName(Name, Arity); |
|
|
1335 |
writeAbiTags(ND, AdditionalAbiTags); |
1083 |
break; |
1336 |
break; |
1084 |
|
1337 |
|
1085 |
case DeclarationName::CXXUsingDirective: |
1338 |
case DeclarationName::CXXUsingDirective: |
Lines 1096-1102
void CXXNameMangler::mangleSourceName(const IdentifierInfo *II) {
Link Here
|
1096 |
|
1349 |
|
1097 |
void CXXNameMangler::mangleNestedName(const NamedDecl *ND, |
1350 |
void CXXNameMangler::mangleNestedName(const NamedDecl *ND, |
1098 |
const DeclContext *DC, |
1351 |
const DeclContext *DC, |
1099 |
bool NoFunction) { |
1352 |
const AbiTagList *AdditionalAbiTags, |
|
|
1353 |
bool NoFunction, |
1354 |
bool ExcludeUnqualifiedName) { |
1100 |
// <nested-name> |
1355 |
// <nested-name> |
1101 |
// ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E |
1356 |
// ::= N [<CV-qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E |
1102 |
// ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> |
1357 |
// ::= N [<CV-qualifiers>] [<ref-qualifier>] <template-prefix> |
Lines 1116-1145
void CXXNameMangler::mangleNestedName(const NamedDecl *ND,
Link Here
|
1116 |
// Check if we have a template. |
1371 |
// Check if we have a template. |
1117 |
const TemplateArgumentList *TemplateArgs = nullptr; |
1372 |
const TemplateArgumentList *TemplateArgs = nullptr; |
1118 |
if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { |
1373 |
if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { |
1119 |
mangleTemplatePrefix(TD, NoFunction); |
1374 |
mangleTemplatePrefix(TD, AdditionalAbiTags, NoFunction, ExcludeUnqualifiedName); |
1120 |
mangleTemplateArgs(*TemplateArgs); |
1375 |
mangleTemplateArgs(*TemplateArgs); |
1121 |
} |
1376 |
} |
1122 |
else { |
1377 |
else { |
1123 |
manglePrefix(DC, NoFunction); |
1378 |
manglePrefix(DC, NoFunction); |
1124 |
mangleUnqualifiedName(ND); |
1379 |
if (!ExcludeUnqualifiedName) |
|
|
1380 |
mangleUnqualifiedName(ND, AdditionalAbiTags); |
1125 |
} |
1381 |
} |
1126 |
|
1382 |
|
1127 |
Out << 'E'; |
1383 |
Out << 'E'; |
1128 |
} |
1384 |
} |
1129 |
void CXXNameMangler::mangleNestedName(const TemplateDecl *TD, |
1385 |
void CXXNameMangler::mangleNestedName(const TemplateDecl *TD, |
|
|
1386 |
const AbiTagList *AdditionalAbiTags, |
1387 |
bool ExcludeUnqualifiedName, |
1130 |
const TemplateArgument *TemplateArgs, |
1388 |
const TemplateArgument *TemplateArgs, |
1131 |
unsigned NumTemplateArgs) { |
1389 |
unsigned NumTemplateArgs) { |
1132 |
// <nested-name> ::= N [<CV-qualifiers>] <template-prefix> <template-args> E |
1390 |
// <nested-name> ::= N [<CV-qualifiers>] <template-prefix> <template-args> E |
1133 |
|
1391 |
|
1134 |
Out << 'N'; |
1392 |
Out << 'N'; |
1135 |
|
1393 |
|
1136 |
mangleTemplatePrefix(TD); |
1394 |
mangleTemplatePrefix(TD, AdditionalAbiTags, ExcludeUnqualifiedName); |
1137 |
mangleTemplateArgs(TemplateArgs, NumTemplateArgs); |
1395 |
mangleTemplateArgs(TemplateArgs, NumTemplateArgs); |
1138 |
|
1396 |
|
1139 |
Out << 'E'; |
1397 |
Out << 'E'; |
1140 |
} |
1398 |
} |
1141 |
|
1399 |
|
1142 |
void CXXNameMangler::mangleLocalName(const Decl *D) { |
1400 |
void CXXNameMangler::mangleLocalName(const Decl *D, |
|
|
1401 |
const AbiTagList *AdditionalAbiTags, |
1402 |
bool ExcludeUnqualifiedName) { |
1143 |
// <local-name> := Z <function encoding> E <entity name> [<discriminator>] |
1403 |
// <local-name> := Z <function encoding> E <entity name> [<discriminator>] |
1144 |
// := Z <function encoding> E s [<discriminator>] |
1404 |
// := Z <function encoding> E s [<discriminator>] |
1145 |
// <local-name> := Z <function encoding> E d [ <parameter number> ] |
1405 |
// <local-name> := Z <function encoding> E d [ <parameter number> ] |
Lines 1151-1165
void CXXNameMangler::mangleLocalName(const Decl *D) {
Link Here
|
1151 |
|
1411 |
|
1152 |
Out << 'Z'; |
1412 |
Out << 'Z'; |
1153 |
|
1413 |
|
1154 |
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC)) |
1414 |
{ |
1155 |
mangleObjCMethodName(MD); |
1415 |
AbiTagState localAbiTags(AbiTags); |
1156 |
else if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) |
1416 |
|
1157 |
mangleBlockForPrefix(BD); |
1417 |
if (const ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(DC)) |
1158 |
else |
1418 |
mangleObjCMethodName(MD); |
1159 |
mangleFunctionEncoding(cast<FunctionDecl>(DC)); |
1419 |
else if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) |
|
|
1420 |
mangleBlockForPrefix(BD); |
1421 |
else |
1422 |
mangleFunctionEncoding(cast<FunctionDecl>(DC)); |
1423 |
|
1424 |
// implicit abi tags (from namespace) are not available in the following |
1425 |
// entity; reset to actually emitted tags, which are available. |
1426 |
localAbiTags.UsedAbiTags = localAbiTags.EmittedAbiTags; |
1427 |
} |
1160 |
|
1428 |
|
1161 |
Out << 'E'; |
1429 |
Out << 'E'; |
1162 |
|
1430 |
|
|
|
1431 |
TemporaryDisableDerivedAbiTags TemporyDisable(DisableDerivedAbiTags, getStructor(dyn_cast<NamedDecl>(D)) != Structor); |
1432 |
|
1163 |
if (RD) { |
1433 |
if (RD) { |
1164 |
// The parameter number is omitted for the last parameter, 0 for the |
1434 |
// The parameter number is omitted for the last parameter, 0 for the |
1165 |
// second-to-last parameter, 1 for the third-to-last parameter, etc. The |
1435 |
// second-to-last parameter, 1 for the third-to-last parameter, etc. The |
Lines 1184-1196
void CXXNameMangler::mangleLocalName(const Decl *D) {
Link Here
|
1184 |
// Mangle the name relative to the closest enclosing function. |
1454 |
// Mangle the name relative to the closest enclosing function. |
1185 |
// equality ok because RD derived from ND above |
1455 |
// equality ok because RD derived from ND above |
1186 |
if (D == RD) { |
1456 |
if (D == RD) { |
1187 |
mangleUnqualifiedName(RD); |
1457 |
if (!ExcludeUnqualifiedName) |
|
|
1458 |
mangleUnqualifiedName(RD, AdditionalAbiTags); |
1188 |
} else if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) { |
1459 |
} else if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) { |
1189 |
manglePrefix(getEffectiveDeclContext(BD), true /*NoFunction*/); |
1460 |
manglePrefix(getEffectiveDeclContext(BD), true /*NoFunction*/); |
1190 |
mangleUnqualifiedBlock(BD); |
1461 |
assert(!AdditionalAbiTags && "Block cannot have additional abi tags"); |
|
|
1462 |
if (!ExcludeUnqualifiedName) |
1463 |
mangleUnqualifiedBlock(BD); |
1191 |
} else { |
1464 |
} else { |
1192 |
const NamedDecl *ND = cast<NamedDecl>(D); |
1465 |
const NamedDecl *ND = cast<NamedDecl>(D); |
1193 |
mangleNestedName(ND, getEffectiveDeclContext(ND), true /*NoFunction*/); |
1466 |
mangleNestedName(ND, getEffectiveDeclContext(ND), |
|
|
1467 |
AdditionalAbiTags, true /*NoFunction*/, ExcludeUnqualifiedName); |
1194 |
} |
1468 |
} |
1195 |
} else if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) { |
1469 |
} else if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) { |
1196 |
// Mangle a block in a default parameter; see above explanation for |
1470 |
// Mangle a block in a default parameter; see above explanation for |
Lines 1207-1236
void CXXNameMangler::mangleLocalName(const Decl *D) {
Link Here
|
1207 |
} |
1481 |
} |
1208 |
} |
1482 |
} |
1209 |
|
1483 |
|
1210 |
mangleUnqualifiedBlock(BD); |
1484 |
assert(!AdditionalAbiTags && "Block cannot have additional abi tags"); |
|
|
1485 |
if (!ExcludeUnqualifiedName) |
1486 |
mangleUnqualifiedBlock(BD); |
1211 |
} else { |
1487 |
} else { |
1212 |
mangleUnqualifiedName(cast<NamedDecl>(D)); |
1488 |
if (!ExcludeUnqualifiedName) |
1213 |
} |
1489 |
mangleUnqualifiedName(cast<NamedDecl>(D), AdditionalAbiTags); |
1214 |
|
1490 |
} |
1215 |
if (const NamedDecl *ND = dyn_cast<NamedDecl>(RD ? RD : D)) { |
1491 |
|
1216 |
unsigned disc; |
1492 |
if (!ExcludeUnqualifiedName) { |
1217 |
if (Context.getNextDiscriminator(ND, disc)) { |
1493 |
if (const NamedDecl *ND = dyn_cast<NamedDecl>(RD ? RD : D)) { |
1218 |
if (disc < 10) |
1494 |
unsigned disc; |
1219 |
Out << '_' << disc; |
1495 |
if (Context.getNextDiscriminator(ND, disc)) { |
1220 |
else |
1496 |
if (disc < 10) |
1221 |
Out << "__" << disc << '_'; |
1497 |
Out << '_' << disc; |
|
|
1498 |
else |
1499 |
Out << "__" << disc << '_'; |
1500 |
} |
1222 |
} |
1501 |
} |
1223 |
} |
1502 |
} |
1224 |
} |
1503 |
} |
1225 |
|
1504 |
|
1226 |
void CXXNameMangler::mangleBlockForPrefix(const BlockDecl *Block) { |
1505 |
void CXXNameMangler::mangleBlockForPrefix(const BlockDecl *Block) { |
1227 |
if (GetLocalClassDecl(Block)) { |
1506 |
if (GetLocalClassDecl(Block)) { |
1228 |
mangleLocalName(Block); |
1507 |
mangleLocalName(Block, /* AdditionalAbiTags */ nullptr, /* ExcludeUnqualifiedName */ false); |
1229 |
return; |
1508 |
return; |
1230 |
} |
1509 |
} |
1231 |
const DeclContext *DC = getEffectiveDeclContext(Block); |
1510 |
const DeclContext *DC = getEffectiveDeclContext(Block); |
1232 |
if (isLocalContainerContext(DC)) { |
1511 |
if (isLocalContainerContext(DC)) { |
1233 |
mangleLocalName(Block); |
1512 |
mangleLocalName(Block, /* AdditionalAbiTags */ nullptr, /* ExcludeUnqualifiedName */ false); |
1234 |
return; |
1513 |
return; |
1235 |
} |
1514 |
} |
1236 |
manglePrefix(getEffectiveDeclContext(Block)); |
1515 |
manglePrefix(getEffectiveDeclContext(Block)); |
Lines 1241-1250
void CXXNameMangler::mangleUnqualifiedBlock(const BlockDecl *Block) {
Link Here
|
1241 |
if (Decl *Context = Block->getBlockManglingContextDecl()) { |
1520 |
if (Decl *Context = Block->getBlockManglingContextDecl()) { |
1242 |
if ((isa<VarDecl>(Context) || isa<FieldDecl>(Context)) && |
1521 |
if ((isa<VarDecl>(Context) || isa<FieldDecl>(Context)) && |
1243 |
Context->getDeclContext()->isRecord()) { |
1522 |
Context->getDeclContext()->isRecord()) { |
1244 |
if (const IdentifierInfo *Name |
1523 |
const auto *ND = cast<NamedDecl>(Context); |
1245 |
= cast<NamedDecl>(Context)->getIdentifier()) { |
1524 |
if (const IdentifierInfo *Name = ND->getIdentifier()) { |
1246 |
mangleSourceName(Name); |
1525 |
mangleSourceName(Name); |
1247 |
Out << 'M'; |
1526 |
writeAbiTags(ND, /* AdditionalAbiTags */ nullptr); |
|
|
1527 |
Out << 'M'; |
1248 |
} |
1528 |
} |
1249 |
} |
1529 |
} |
1250 |
} |
1530 |
} |
Lines 1277-1283
void CXXNameMangler::mangleLambda(const CXXRecordDecl *Lambda) {
Link Here
|
1277 |
if (const IdentifierInfo *Name |
1557 |
if (const IdentifierInfo *Name |
1278 |
= cast<NamedDecl>(Context)->getIdentifier()) { |
1558 |
= cast<NamedDecl>(Context)->getIdentifier()) { |
1279 |
mangleSourceName(Name); |
1559 |
mangleSourceName(Name); |
1280 |
Out << 'M'; |
1560 |
Out << 'M'; |
1281 |
} |
1561 |
} |
1282 |
} |
1562 |
} |
1283 |
} |
1563 |
} |
Lines 1359-1369
void CXXNameMangler::manglePrefix(const DeclContext *DC, bool NoFunction) {
Link Here
|
1359 |
// Check if we have a template. |
1639 |
// Check if we have a template. |
1360 |
const TemplateArgumentList *TemplateArgs = nullptr; |
1640 |
const TemplateArgumentList *TemplateArgs = nullptr; |
1361 |
if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { |
1641 |
if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) { |
1362 |
mangleTemplatePrefix(TD); |
1642 |
mangleTemplatePrefix(TD, /* AdditionalAbiTags */ nullptr); |
1363 |
mangleTemplateArgs(*TemplateArgs); |
1643 |
mangleTemplateArgs(*TemplateArgs); |
1364 |
} else { |
1644 |
} else { |
1365 |
manglePrefix(getEffectiveDeclContext(ND), NoFunction); |
1645 |
manglePrefix(getEffectiveDeclContext(ND), NoFunction); |
1366 |
mangleUnqualifiedName(ND); |
1646 |
mangleUnqualifiedName(ND, /* AdditionalAbiTags */ nullptr); |
1367 |
} |
1647 |
} |
1368 |
|
1648 |
|
1369 |
addSubstitution(ND); |
1649 |
addSubstitution(ND); |
Lines 1374-1400
void CXXNameMangler::mangleTemplatePrefix(TemplateName Template) {
Link Here
|
1374 |
// ::= <template-param> |
1654 |
// ::= <template-param> |
1375 |
// ::= <substitution> |
1655 |
// ::= <substitution> |
1376 |
if (TemplateDecl *TD = Template.getAsTemplateDecl()) |
1656 |
if (TemplateDecl *TD = Template.getAsTemplateDecl()) |
1377 |
return mangleTemplatePrefix(TD); |
1657 |
return mangleTemplatePrefix(TD, /* AdditionalAbiTags */ nullptr); |
1378 |
|
1658 |
|
1379 |
if (QualifiedTemplateName *Qualified = Template.getAsQualifiedTemplateName()) |
1659 |
if (QualifiedTemplateName *Qualified = Template.getAsQualifiedTemplateName()) |
1380 |
manglePrefix(Qualified->getQualifier()); |
1660 |
manglePrefix(Qualified->getQualifier()); |
1381 |
|
1661 |
|
1382 |
if (OverloadedTemplateStorage *Overloaded |
1662 |
if (OverloadedTemplateStorage *Overloaded |
1383 |
= Template.getAsOverloadedTemplate()) { |
1663 |
= Template.getAsOverloadedTemplate()) { |
1384 |
mangleUnqualifiedName(nullptr, (*Overloaded->begin())->getDeclName(), |
1664 |
mangleUnqualifiedName(nullptr, (*Overloaded->begin())->getDeclName(), |
1385 |
UnknownArity); |
1665 |
UnknownArity, |
|
|
1666 |
/* AdditionalAbiTags */ nullptr); |
1386 |
return; |
1667 |
return; |
1387 |
} |
1668 |
} |
1388 |
|
1669 |
|
1389 |
DependentTemplateName *Dependent = Template.getAsDependentTemplateName(); |
1670 |
DependentTemplateName *Dependent = Template.getAsDependentTemplateName(); |
1390 |
assert(Dependent && "Unknown template name kind?"); |
1671 |
assert(Dependent && "Unknown template name kind?"); |
1391 |
if (NestedNameSpecifier *Qualifier = Dependent->getQualifier()) |
1672 |
if (NestedNameSpecifier *Qualifier = Dependent->getQualifier()) |
1392 |
manglePrefix(Qualifier); |
1673 |
manglePrefix(Qualifier); |
1393 |
mangleUnscopedTemplateName(Template); |
1674 |
mangleUnscopedTemplateName(Template, /* AdditionalAbiTags */ nullptr); |
1394 |
} |
1675 |
} |
1395 |
|
1676 |
|
1396 |
void CXXNameMangler::mangleTemplatePrefix(const TemplateDecl *ND, |
1677 |
void CXXNameMangler::mangleTemplatePrefix(const TemplateDecl *ND, |
1397 |
bool NoFunction) { |
1678 |
const AbiTagList *AdditionalAbiTags, |
|
|
1679 |
bool NoFunction, |
1680 |
bool ExcludeUnqualifiedName) { |
1398 |
// <template-prefix> ::= <prefix> <template unqualified-name> |
1681 |
// <template-prefix> ::= <prefix> <template unqualified-name> |
1399 |
// ::= <template-param> |
1682 |
// ::= <template-param> |
1400 |
// ::= <substitution> |
1683 |
// ::= <substitution> |
Lines 1406-1415
void CXXNameMangler::mangleTemplatePrefix(const TemplateDecl *ND,
Link Here
|
1406 |
|
1689 |
|
1407 |
// <template-template-param> ::= <template-param> |
1690 |
// <template-template-param> ::= <template-param> |
1408 |
if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) { |
1691 |
if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(ND)) { |
|
|
1692 |
// TODO(abitags): ??? |
1409 |
mangleTemplateParameter(TTP->getIndex()); |
1693 |
mangleTemplateParameter(TTP->getIndex()); |
1410 |
} else { |
1694 |
} else { |
1411 |
manglePrefix(getEffectiveDeclContext(ND), NoFunction); |
1695 |
manglePrefix(getEffectiveDeclContext(ND), NoFunction); |
1412 |
mangleUnqualifiedName(ND->getTemplatedDecl()); |
1696 |
if (!ExcludeUnqualifiedName) |
|
|
1697 |
mangleUnqualifiedName(ND->getTemplatedDecl(), AdditionalAbiTags); |
1413 |
} |
1698 |
} |
1414 |
|
1699 |
|
1415 |
addSubstitution(ND); |
1700 |
addSubstitution(ND); |
Lines 1453-1458
void CXXNameMangler::mangleType(TemplateName TN) {
Link Here
|
1453 |
// <name> ::= <nested-name> |
1738 |
// <name> ::= <nested-name> |
1454 |
mangleUnresolvedPrefix(Dependent->getQualifier()); |
1739 |
mangleUnresolvedPrefix(Dependent->getQualifier()); |
1455 |
mangleSourceName(Dependent->getIdentifier()); |
1740 |
mangleSourceName(Dependent->getIdentifier()); |
|
|
1741 |
// writeAbiTags(Dependent); |
1456 |
break; |
1742 |
break; |
1457 |
} |
1743 |
} |
1458 |
|
1744 |
|
Lines 1544-1559
bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty,
Link Here
|
1544 |
|
1830 |
|
1545 |
case Type::Typedef: |
1831 |
case Type::Typedef: |
1546 |
mangleSourceName(cast<TypedefType>(Ty)->getDecl()->getIdentifier()); |
1832 |
mangleSourceName(cast<TypedefType>(Ty)->getDecl()->getIdentifier()); |
|
|
1833 |
writeAbiTags(cast<TypedefType>(Ty)->getDecl()); |
1547 |
break; |
1834 |
break; |
1548 |
|
1835 |
|
1549 |
case Type::UnresolvedUsing: |
1836 |
case Type::UnresolvedUsing: |
1550 |
mangleSourceName( |
1837 |
mangleSourceName( |
1551 |
cast<UnresolvedUsingType>(Ty)->getDecl()->getIdentifier()); |
1838 |
cast<UnresolvedUsingType>(Ty)->getDecl()->getIdentifier()); |
|
|
1839 |
writeAbiTags(cast<UnresolvedUsingType>(Ty)->getDecl()); |
1552 |
break; |
1840 |
break; |
1553 |
|
1841 |
|
1554 |
case Type::Enum: |
1842 |
case Type::Enum: |
1555 |
case Type::Record: |
1843 |
case Type::Record: |
1556 |
mangleSourceName(cast<TagType>(Ty)->getDecl()->getIdentifier()); |
1844 |
mangleSourceName(cast<TagType>(Ty)->getDecl()->getIdentifier()); |
|
|
1845 |
writeAbiTags(cast<TagType>(Ty)->getDecl()); |
1557 |
break; |
1846 |
break; |
1558 |
|
1847 |
|
1559 |
case Type::TemplateSpecialization: { |
1848 |
case Type::TemplateSpecialization: { |
Lines 1572-1577
bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty,
Link Here
|
1572 |
goto unresolvedType; |
1861 |
goto unresolvedType; |
1573 |
|
1862 |
|
1574 |
mangleSourceName(TD->getIdentifier()); |
1863 |
mangleSourceName(TD->getIdentifier()); |
|
|
1864 |
writeAbiTags(TD); |
1575 |
break; |
1865 |
break; |
1576 |
} |
1866 |
} |
1577 |
|
1867 |
|
Lines 1603-1618
bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty,
Link Here
|
1603 |
case Type::InjectedClassName: |
1893 |
case Type::InjectedClassName: |
1604 |
mangleSourceName( |
1894 |
mangleSourceName( |
1605 |
cast<InjectedClassNameType>(Ty)->getDecl()->getIdentifier()); |
1895 |
cast<InjectedClassNameType>(Ty)->getDecl()->getIdentifier()); |
|
|
1896 |
writeAbiTags(cast<InjectedClassNameType>(Ty)->getDecl()); |
1606 |
break; |
1897 |
break; |
1607 |
|
1898 |
|
1608 |
case Type::DependentName: |
1899 |
case Type::DependentName: |
1609 |
mangleSourceName(cast<DependentNameType>(Ty)->getIdentifier()); |
1900 |
mangleSourceName(cast<DependentNameType>(Ty)->getIdentifier()); |
|
|
1901 |
// writeAbiTags(cast<DependentNameType>(Ty)); |
1610 |
break; |
1902 |
break; |
1611 |
|
1903 |
|
1612 |
case Type::DependentTemplateSpecialization: { |
1904 |
case Type::DependentTemplateSpecialization: { |
1613 |
const DependentTemplateSpecializationType *DTST = |
1905 |
const DependentTemplateSpecializationType *DTST = |
1614 |
cast<DependentTemplateSpecializationType>(Ty); |
1906 |
cast<DependentTemplateSpecializationType>(Ty); |
1615 |
mangleSourceName(DTST->getIdentifier()); |
1907 |
mangleSourceName(DTST->getIdentifier()); |
|
|
1908 |
// writeAbiTags(DTST); |
1616 |
mangleTemplateArgs(DTST->getArgs(), DTST->getNumArgs()); |
1909 |
mangleTemplateArgs(DTST->getArgs(), DTST->getNumArgs()); |
1617 |
break; |
1910 |
break; |
1618 |
} |
1911 |
} |
Lines 2421-2427
void CXXNameMangler::mangleType(const InjectedClassNameType *T) {
Link Here
|
2421 |
|
2714 |
|
2422 |
void CXXNameMangler::mangleType(const TemplateSpecializationType *T) { |
2715 |
void CXXNameMangler::mangleType(const TemplateSpecializationType *T) { |
2423 |
if (TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl()) { |
2716 |
if (TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl()) { |
2424 |
mangleName(TD, T->getArgs(), T->getNumArgs()); |
2717 |
// types only have explicit abi tags, no addition tags |
|
|
2718 |
mangleTemplateName(TD, |
2719 |
/* AdditionalAbiTags */ nullptr, |
2720 |
/* ExcludeUnqualifiedName */ false, |
2721 |
T->getArgs(), T->getNumArgs()); |
2425 |
} else { |
2722 |
} else { |
2426 |
if (mangleSubstitution(QualType(T, 0))) |
2723 |
if (mangleSubstitution(QualType(T, 0))) |
2427 |
return; |
2724 |
return; |
Lines 2468-2473
void CXXNameMangler::mangleType(const DependentNameType *T) {
Link Here
|
2468 |
Out << 'N'; |
2765 |
Out << 'N'; |
2469 |
manglePrefix(T->getQualifier()); |
2766 |
manglePrefix(T->getQualifier()); |
2470 |
mangleSourceName(T->getIdentifier()); |
2767 |
mangleSourceName(T->getIdentifier()); |
|
|
2768 |
// writeAbiTags(T); // TODO(abitags) |
2471 |
Out << 'E'; |
2769 |
Out << 'E'; |
2472 |
} |
2770 |
} |
2473 |
|
2771 |
|
Lines 3863-3868
void CXXNameMangler::addSubstitution(uintptr_t Ptr) {
Link Here
|
3863 |
Substitutions[Ptr] = SeqID++; |
4161 |
Substitutions[Ptr] = SeqID++; |
3864 |
} |
4162 |
} |
3865 |
|
4163 |
|
|
|
4164 |
std::set<StringRef> CXXNameMangler::getTagsFromPrefixAndTemplateArguments(const NamedDecl *ND) { |
4165 |
llvm::raw_null_ostream NullOutStream; |
4166 |
CXXNameMangler TrackPrefixAndTemplateArguments(*this, NullOutStream); |
4167 |
|
4168 |
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) { |
4169 |
TrackPrefixAndTemplateArguments.mangleFunctionEncoding(FD, /* ExcludeUnqualifiedName */ true); |
4170 |
} else { |
4171 |
TrackPrefixAndTemplateArguments.mangleName(ND, /* ExcludeUnqualifiedName */ true); |
4172 |
} |
4173 |
|
4174 |
return std::move(TrackPrefixAndTemplateArguments.AbiTagsRoot.UsedAbiTags); |
4175 |
} |
4176 |
|
4177 |
CXXNameMangler::AbiTagList CXXNameMangler::makeAdditionalTagsForFunction(const FunctionDecl *FD) { |
4178 |
// when derived abi tags are disabled there is no need to make any list |
4179 |
if (DisableDerivedAbiTags) return AbiTagList(); |
4180 |
|
4181 |
std::set<StringRef> ImplicitlyAvailableTags = getTagsFromPrefixAndTemplateArguments(FD); |
4182 |
std::set<StringRef> ReturnTypeTags; |
4183 |
|
4184 |
{ |
4185 |
llvm::raw_null_ostream NullOutStream; |
4186 |
CXXNameMangler TrackReturnTypeTags(*this, NullOutStream); |
4187 |
TrackReturnTypeTags.disableDerivedAbiTags(); |
4188 |
|
4189 |
const FunctionProtoType *Proto = cast<FunctionProtoType>(FD->getType()->getAs<FunctionType>()); |
4190 |
TrackReturnTypeTags.FunctionTypeDepth.enterResultType(); |
4191 |
TrackReturnTypeTags.mangleType(Proto->getReturnType()); |
4192 |
TrackReturnTypeTags.FunctionTypeDepth.leaveResultType(); |
4193 |
|
4194 |
ReturnTypeTags = std::move(TrackReturnTypeTags.AbiTagsRoot.UsedAbiTags); |
4195 |
} |
4196 |
|
4197 |
AbiTagList AdditionalAbiTags; |
4198 |
|
4199 |
for (const auto& Tag: ReturnTypeTags) { |
4200 |
if (ImplicitlyAvailableTags.count(Tag) == 0) |
4201 |
AdditionalAbiTags.push_back(Tag); |
4202 |
} |
4203 |
|
4204 |
return AdditionalAbiTags; |
4205 |
} |
4206 |
|
4207 |
CXXNameMangler::AbiTagList CXXNameMangler::makeAdditionalTagsForVariable(const VarDecl *VD) { |
4208 |
// when derived abi tags are disabled there is no need to make any list |
4209 |
if (DisableDerivedAbiTags) return AbiTagList(); |
4210 |
|
4211 |
std::set<StringRef> ImplicitlyAvailableTags = getTagsFromPrefixAndTemplateArguments(VD); |
4212 |
std::set<StringRef> VariableTypeTags; |
4213 |
|
4214 |
{ |
4215 |
llvm::raw_null_ostream NullOutStream; |
4216 |
CXXNameMangler TrackVariableType(*this, NullOutStream); |
4217 |
TrackVariableType.disableDerivedAbiTags(); |
4218 |
|
4219 |
TrackVariableType.mangleType(VD->getType()); |
4220 |
|
4221 |
VariableTypeTags = std::move(TrackVariableType.AbiTagsRoot.UsedAbiTags); |
4222 |
} |
4223 |
|
4224 |
AbiTagList AdditionalAbiTags; |
4225 |
|
4226 |
for (const auto& Tag: VariableTypeTags) { |
4227 |
if (ImplicitlyAvailableTags.count(Tag) == 0) |
4228 |
AdditionalAbiTags.push_back(Tag); |
4229 |
} |
4230 |
|
4231 |
return AdditionalAbiTags; |
4232 |
} |
4233 |
|
3866 |
// |
4234 |
// |
3867 |
|
4235 |
|
3868 |
/// Mangles the name of the declaration D and emits that name to the given |
4236 |
/// Mangles the name of the declaration D and emits that name to the given |
Lines 3964-3969
void ItaniumMangleContextImpl::mangleStaticGuardVariable(const VarDecl *D,
Link Here
|
3964 |
// <special-name> ::= GV <object name> # Guard variable for one-time |
4332 |
// <special-name> ::= GV <object name> # Guard variable for one-time |
3965 |
// # initialization |
4333 |
// # initialization |
3966 |
CXXNameMangler Mangler(*this, Out); |
4334 |
CXXNameMangler Mangler(*this, Out); |
|
|
4335 |
Mangler.disableDerivedAbiTags(); // GCC: doesn't emit derived abi tags for guard variables |
3967 |
Mangler.getStream() << "_ZGV"; |
4336 |
Mangler.getStream() << "_ZGV"; |
3968 |
Mangler.mangleName(D); |
4337 |
Mangler.mangleName(D); |
3969 |
} |
4338 |
} |