2012-12-18 22:30:41 +08:00
|
|
|
//===--- MicrosoftMangle.cpp - Microsoft Visual C++ Name Mangling ---------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This provides C++ name mangling targeting the Microsoft Visual C++ ABI.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/AST/Mangle.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/Attr.h"
|
2013-10-09 17:23:58 +08:00
|
|
|
#include "clang/AST/CXXInheritance.h"
|
2014-01-07 19:51:46 +08:00
|
|
|
#include "clang/AST/CharUnits.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "clang/AST/Decl.h"
|
|
|
|
#include "clang/AST/DeclCXX.h"
|
|
|
|
#include "clang/AST/DeclObjC.h"
|
2016-03-03 13:21:39 +08:00
|
|
|
#include "clang/AST/DeclOpenMP.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "clang/AST/DeclTemplate.h"
|
2014-03-25 05:43:36 +08:00
|
|
|
#include "clang/AST/Expr.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "clang/AST/ExprCXX.h"
|
2014-02-06 01:27:08 +08:00
|
|
|
#include "clang/AST/VTableBuilder.h"
|
2012-12-18 22:30:41 +08:00
|
|
|
#include "clang/Basic/ABI.h"
|
|
|
|
#include "clang/Basic/DiagnosticOptions.h"
|
2013-05-15 04:30:42 +08:00
|
|
|
#include "clang/Basic/TargetInfo.h"
|
2014-03-05 16:57:59 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2015-09-02 05:24:07 +08:00
|
|
|
#include "llvm/Support/JamCRC.h"
|
2016-03-07 16:51:17 +08:00
|
|
|
#include "llvm/Support/MD5.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
2014-03-24 01:47:16 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
using namespace clang;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-03-07 16:51:17 +08:00
|
|
|
struct msvc_hashing_ostream : public llvm::raw_svector_ostream {
|
|
|
|
raw_ostream &OS;
|
|
|
|
llvm::SmallString<64> Buffer;
|
|
|
|
|
|
|
|
msvc_hashing_ostream(raw_ostream &OS)
|
|
|
|
: llvm::raw_svector_ostream(Buffer), OS(OS) {}
|
|
|
|
~msvc_hashing_ostream() override {
|
|
|
|
StringRef MangledName = str();
|
|
|
|
bool StartsWithEscape = MangledName.startswith("\01");
|
|
|
|
if (StartsWithEscape)
|
|
|
|
MangledName = MangledName.drop_front(1);
|
|
|
|
if (MangledName.size() <= 4096) {
|
|
|
|
OS << str();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::MD5 Hasher;
|
|
|
|
llvm::MD5::MD5Result Hash;
|
|
|
|
Hasher.update(MangledName);
|
|
|
|
Hasher.final(Hash);
|
|
|
|
|
|
|
|
SmallString<32> HexString;
|
|
|
|
llvm::MD5::stringifyResult(Hash, HexString);
|
|
|
|
|
|
|
|
if (StartsWithEscape)
|
|
|
|
OS << '\01';
|
|
|
|
OS << "??@" << HexString << '@';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-07 01:01:02 +08:00
|
|
|
static const DeclContext *
|
|
|
|
getLambdaDefaultArgumentDeclContext(const Decl *D) {
|
|
|
|
if (const auto *RD = dyn_cast<CXXRecordDecl>(D))
|
|
|
|
if (RD->isLambda())
|
|
|
|
if (const auto *Parm =
|
|
|
|
dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl()))
|
|
|
|
return Parm->getDeclContext();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-09-13 17:03:14 +08:00
|
|
|
/// \brief Retrieve the declaration context that should be used when mangling
|
|
|
|
/// the given declaration.
|
|
|
|
static const DeclContext *getEffectiveDeclContext(const Decl *D) {
|
|
|
|
// The ABI assumes that lambda closure types that occur within
|
|
|
|
// default arguments live in the context of the function. However, due to
|
|
|
|
// the way in which Clang parses and creates function declarations, this is
|
|
|
|
// not the case: the lambda closure type ends up living in the context
|
|
|
|
// where the function itself resides, because the function declaration itself
|
|
|
|
// had not yet been created. Fix the context here.
|
2016-12-07 01:01:02 +08:00
|
|
|
if (const auto *LDADC = getLambdaDefaultArgumentDeclContext(D))
|
|
|
|
return LDADC;
|
2013-09-13 17:03:14 +08:00
|
|
|
|
|
|
|
// Perform the same check for block literals.
|
|
|
|
if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) {
|
|
|
|
if (ParmVarDecl *ContextParam =
|
|
|
|
dyn_cast_or_null<ParmVarDecl>(BD->getBlockManglingContextDecl()))
|
|
|
|
return ContextParam->getDeclContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
const DeclContext *DC = D->getDeclContext();
|
2016-03-03 13:21:39 +08:00
|
|
|
if (isa<CapturedDecl>(DC) || isa<OMPDeclareReductionDecl>(DC)) {
|
|
|
|
return getEffectiveDeclContext(cast<Decl>(DC));
|
|
|
|
}
|
2013-09-13 17:03:14 +08:00
|
|
|
|
2016-05-20 02:15:53 +08:00
|
|
|
return DC->getRedeclContext();
|
2013-09-13 17:03:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const DeclContext *getEffectiveParentContext(const DeclContext *DC) {
|
|
|
|
return getEffectiveDeclContext(cast<Decl>(DC));
|
|
|
|
}
|
|
|
|
|
2015-03-12 02:36:39 +08:00
|
|
|
static const FunctionDecl *getStructor(const NamedDecl *ND) {
|
|
|
|
if (const auto *FTD = dyn_cast<FunctionTemplateDecl>(ND))
|
2017-01-10 01:04:37 +08:00
|
|
|
return FTD->getTemplatedDecl()->getCanonicalDecl();
|
2013-02-13 16:37:51 +08:00
|
|
|
|
2015-03-12 02:36:39 +08:00
|
|
|
const auto *FD = cast<FunctionDecl>(ND);
|
|
|
|
if (const auto *FTD = FD->getPrimaryTemplate())
|
2017-01-10 01:04:37 +08:00
|
|
|
return FTD->getTemplatedDecl()->getCanonicalDecl();
|
2015-03-12 02:36:39 +08:00
|
|
|
|
2017-01-10 01:04:37 +08:00
|
|
|
return FD->getCanonicalDecl();
|
2013-02-13 16:37:51 +08:00
|
|
|
}
|
|
|
|
|
2014-03-05 16:57:59 +08:00
|
|
|
/// MicrosoftMangleContextImpl - Overrides the default MangleContext for the
|
|
|
|
/// Microsoft Visual C++ ABI.
|
|
|
|
class MicrosoftMangleContextImpl : public MicrosoftMangleContext {
|
|
|
|
typedef std::pair<const DeclContext *, IdentifierInfo *> DiscriminatorKeyTy;
|
|
|
|
llvm::DenseMap<DiscriminatorKeyTy, unsigned> Discriminator;
|
2014-04-23 13:16:51 +08:00
|
|
|
llvm::DenseMap<const NamedDecl *, unsigned> Uniquifier;
|
2014-03-05 18:35:06 +08:00
|
|
|
llvm::DenseMap<const CXXRecordDecl *, unsigned> LambdaIds;
|
Initial support for Win64 SEH IR emission
The lowering looks a lot like normal EH lowering, with the exception
that the exceptions are caught by executing filter expression code
instead of matching typeinfo globals. The filter expressions are
outlined into functions which are used in landingpad clauses where
typeinfo would normally go.
Major aspects that still need work:
- Non-call exceptions in __try bodies won't work yet. The plan is to
outline the __try block in the frontend to keep things simple.
- Filter expressions cannot use local variables until capturing is
implemented.
- __finally blocks will not run after exceptions. Fixing this requires
work in the LLVM SEH preparation pass.
The IR lowering looks like this:
// C code:
bool safe_div(int n, int d, int *r) {
__try {
*r = normal_div(n, d);
} __except(_exception_code() == EXCEPTION_INT_DIVIDE_BY_ZERO) {
return false;
}
return true;
}
; LLVM IR:
define i32 @filter(i8* %e, i8* %fp) {
%ehptrs = bitcast i8* %e to i32**
%ehrec = load i32** %ehptrs
%code = load i32* %ehrec
%matches = icmp eq i32 %code, i32 u0xC0000094
%matches.i32 = zext i1 %matches to i32
ret i32 %matches.i32
}
define i1 zeroext @safe_div(i32 %n, i32 %d, i32* %r) {
%rr = invoke i32 @normal_div(i32 %n, i32 %d)
to label %normal unwind to label %lpad
normal:
store i32 %rr, i32* %r
ret i1 1
lpad:
%ehvals = landingpad {i8*, i32} personality i32 (...)* @__C_specific_handler
catch i8* bitcast (i32 (i8*, i8*)* @filter to i8*)
%ehptr = extractvalue {i8*, i32} %ehvals, i32 0
%sel = extractvalue {i8*, i32} %ehvals, i32 1
%filter_sel = call i32 @llvm.eh.seh.typeid.for(i8* bitcast (i32 (i8*, i8*)* @filter to i8*))
%matches = icmp eq i32 %sel, %filter_sel
br i1 %matches, label %eh.except, label %eh.resume
eh.except:
ret i1 false
eh.resume:
resume
}
Reviewers: rjmccall, rsmith, majnemer
Differential Revision: http://reviews.llvm.org/D5607
llvm-svn: 226760
2015-01-22 09:36:17 +08:00
|
|
|
llvm::DenseMap<const NamedDecl *, unsigned> SEHFilterIds;
|
2015-04-15 04:59:00 +08:00
|
|
|
llvm::DenseMap<const NamedDecl *, unsigned> SEHFinallyIds;
|
2014-03-05 16:57:59 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
MicrosoftMangleContextImpl(ASTContext &Context, DiagnosticsEngine &Diags)
|
|
|
|
: MicrosoftMangleContext(Context, Diags) {}
|
2014-03-11 14:22:39 +08:00
|
|
|
bool shouldMangleCXXName(const NamedDecl *D) override;
|
2014-03-25 05:43:36 +08:00
|
|
|
bool shouldMangleStringLiteral(const StringLiteral *SL) override;
|
2014-03-11 14:22:39 +08:00
|
|
|
void mangleCXXName(const NamedDecl *D, raw_ostream &Out) override;
|
2014-04-23 13:16:51 +08:00
|
|
|
void mangleVirtualMemPtrThunk(const CXXMethodDecl *MD,
|
|
|
|
raw_ostream &) override;
|
2014-03-11 14:22:39 +08:00
|
|
|
void mangleThunk(const CXXMethodDecl *MD, const ThunkInfo &Thunk,
|
|
|
|
raw_ostream &) override;
|
|
|
|
void mangleCXXDtorThunk(const CXXDestructorDecl *DD, CXXDtorType Type,
|
|
|
|
const ThisAdjustment &ThisAdjustment,
|
|
|
|
raw_ostream &) override;
|
|
|
|
void mangleCXXVFTable(const CXXRecordDecl *Derived,
|
|
|
|
ArrayRef<const CXXRecordDecl *> BasePath,
|
|
|
|
raw_ostream &Out) override;
|
|
|
|
void mangleCXXVBTable(const CXXRecordDecl *Derived,
|
|
|
|
ArrayRef<const CXXRecordDecl *> BasePath,
|
|
|
|
raw_ostream &Out) override;
|
2015-06-23 15:31:11 +08:00
|
|
|
void mangleCXXVirtualDisplacementMap(const CXXRecordDecl *SrcRD,
|
|
|
|
const CXXRecordDecl *DstRD,
|
|
|
|
raw_ostream &Out) override;
|
2015-03-05 08:46:22 +08:00
|
|
|
void mangleCXXThrowInfo(QualType T, bool IsConst, bool IsVolatile,
|
2016-07-12 12:42:50 +08:00
|
|
|
bool IsUnaligned, uint32_t NumEntries,
|
|
|
|
raw_ostream &Out) override;
|
2015-03-05 08:46:22 +08:00
|
|
|
void mangleCXXCatchableTypeArray(QualType T, uint32_t NumEntries,
|
|
|
|
raw_ostream &Out) override;
|
2015-03-07 02:53:55 +08:00
|
|
|
void mangleCXXCatchableType(QualType T, const CXXConstructorDecl *CD,
|
2015-03-12 02:36:39 +08:00
|
|
|
CXXCtorType CT, uint32_t Size, uint32_t NVOffset,
|
2015-03-11 03:01:51 +08:00
|
|
|
int32_t VBPtrOffset, uint32_t VBIndex,
|
|
|
|
raw_ostream &Out) override;
|
2014-05-13 08:44:44 +08:00
|
|
|
void mangleCXXRTTI(QualType T, raw_ostream &Out) override;
|
|
|
|
void mangleCXXRTTIName(QualType T, raw_ostream &Out) override;
|
2014-05-13 14:57:43 +08:00
|
|
|
void mangleCXXRTTIBaseClassDescriptor(const CXXRecordDecl *Derived,
|
2014-05-24 00:07:43 +08:00
|
|
|
uint32_t NVOffset, int32_t VBPtrOffset,
|
2014-05-13 14:57:43 +08:00
|
|
|
uint32_t VBTableOffset, uint32_t Flags,
|
|
|
|
raw_ostream &Out) override;
|
2014-05-13 08:44:44 +08:00
|
|
|
void mangleCXXRTTIBaseClassArray(const CXXRecordDecl *Derived,
|
|
|
|
raw_ostream &Out) override;
|
|
|
|
void mangleCXXRTTIClassHierarchyDescriptor(const CXXRecordDecl *Derived,
|
|
|
|
raw_ostream &Out) override;
|
2014-05-13 14:57:43 +08:00
|
|
|
void
|
|
|
|
mangleCXXRTTICompleteObjectLocator(const CXXRecordDecl *Derived,
|
|
|
|
ArrayRef<const CXXRecordDecl *> BasePath,
|
|
|
|
raw_ostream &Out) override;
|
2014-03-11 14:22:39 +08:00
|
|
|
void mangleTypeName(QualType T, raw_ostream &) override;
|
|
|
|
void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
|
|
|
|
raw_ostream &) override;
|
|
|
|
void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
|
|
|
|
raw_ostream &) override;
|
2014-05-02 01:50:17 +08:00
|
|
|
void mangleReferenceTemporary(const VarDecl *, unsigned ManglingNumber,
|
|
|
|
raw_ostream &) override;
|
2014-03-11 14:22:39 +08:00
|
|
|
void mangleStaticGuardVariable(const VarDecl *D, raw_ostream &Out) override;
|
2015-05-07 14:15:46 +08:00
|
|
|
void mangleThreadSafeStaticGuardVariable(const VarDecl *D, unsigned GuardNum,
|
|
|
|
raw_ostream &Out) override;
|
2014-03-11 14:22:39 +08:00
|
|
|
void mangleDynamicInitializer(const VarDecl *D, raw_ostream &Out) override;
|
|
|
|
void mangleDynamicAtExitDestructor(const VarDecl *D,
|
|
|
|
raw_ostream &Out) override;
|
Initial support for Win64 SEH IR emission
The lowering looks a lot like normal EH lowering, with the exception
that the exceptions are caught by executing filter expression code
instead of matching typeinfo globals. The filter expressions are
outlined into functions which are used in landingpad clauses where
typeinfo would normally go.
Major aspects that still need work:
- Non-call exceptions in __try bodies won't work yet. The plan is to
outline the __try block in the frontend to keep things simple.
- Filter expressions cannot use local variables until capturing is
implemented.
- __finally blocks will not run after exceptions. Fixing this requires
work in the LLVM SEH preparation pass.
The IR lowering looks like this:
// C code:
bool safe_div(int n, int d, int *r) {
__try {
*r = normal_div(n, d);
} __except(_exception_code() == EXCEPTION_INT_DIVIDE_BY_ZERO) {
return false;
}
return true;
}
; LLVM IR:
define i32 @filter(i8* %e, i8* %fp) {
%ehptrs = bitcast i8* %e to i32**
%ehrec = load i32** %ehptrs
%code = load i32* %ehrec
%matches = icmp eq i32 %code, i32 u0xC0000094
%matches.i32 = zext i1 %matches to i32
ret i32 %matches.i32
}
define i1 zeroext @safe_div(i32 %n, i32 %d, i32* %r) {
%rr = invoke i32 @normal_div(i32 %n, i32 %d)
to label %normal unwind to label %lpad
normal:
store i32 %rr, i32* %r
ret i1 1
lpad:
%ehvals = landingpad {i8*, i32} personality i32 (...)* @__C_specific_handler
catch i8* bitcast (i32 (i8*, i8*)* @filter to i8*)
%ehptr = extractvalue {i8*, i32} %ehvals, i32 0
%sel = extractvalue {i8*, i32} %ehvals, i32 1
%filter_sel = call i32 @llvm.eh.seh.typeid.for(i8* bitcast (i32 (i8*, i8*)* @filter to i8*))
%matches = icmp eq i32 %sel, %filter_sel
br i1 %matches, label %eh.except, label %eh.resume
eh.except:
ret i1 false
eh.resume:
resume
}
Reviewers: rjmccall, rsmith, majnemer
Differential Revision: http://reviews.llvm.org/D5607
llvm-svn: 226760
2015-01-22 09:36:17 +08:00
|
|
|
void mangleSEHFilterExpression(const NamedDecl *EnclosingDecl,
|
|
|
|
raw_ostream &Out) override;
|
2015-04-15 04:59:00 +08:00
|
|
|
void mangleSEHFinallyBlock(const NamedDecl *EnclosingDecl,
|
|
|
|
raw_ostream &Out) override;
|
2014-03-25 05:43:36 +08:00
|
|
|
void mangleStringLiteral(const StringLiteral *SL, raw_ostream &Out) override;
|
2014-03-05 16:57:59 +08:00
|
|
|
bool getNextDiscriminator(const NamedDecl *ND, unsigned &disc) {
|
|
|
|
const DeclContext *DC = getEffectiveDeclContext(ND);
|
|
|
|
if (!DC->isFunctionOrMethod())
|
|
|
|
return false;
|
|
|
|
|
2016-01-17 15:09:24 +08:00
|
|
|
// Lambda closure types are already numbered, give out a phony number so
|
|
|
|
// that they demangle nicely.
|
2016-12-07 01:01:02 +08:00
|
|
|
if (const auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
|
|
|
|
if (RD->isLambda()) {
|
|
|
|
disc = 1;
|
|
|
|
return true;
|
|
|
|
}
|
2016-01-17 15:09:24 +08:00
|
|
|
}
|
|
|
|
|
2014-03-05 16:57:59 +08:00
|
|
|
// Use the canonical number for externally visible decls.
|
|
|
|
if (ND->isExternallyVisible()) {
|
|
|
|
disc = getASTContext().getManglingNumber(ND);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Anonymous tags are already numbered.
|
|
|
|
if (const TagDecl *Tag = dyn_cast<TagDecl>(ND)) {
|
2015-09-02 23:50:38 +08:00
|
|
|
if (!Tag->hasNameForLinkage() &&
|
|
|
|
!getASTContext().getDeclaratorForUnnamedTagDecl(Tag) &&
|
|
|
|
!getASTContext().getTypedefNameForUnnamedTagDecl(Tag))
|
2014-03-05 16:57:59 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make up a reasonable number for internal decls.
|
|
|
|
unsigned &discriminator = Uniquifier[ND];
|
|
|
|
if (!discriminator)
|
|
|
|
discriminator = ++Discriminator[std::make_pair(DC, ND->getIdentifier())];
|
2014-10-05 14:44:53 +08:00
|
|
|
disc = discriminator + 1;
|
2014-03-05 16:57:59 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-05 18:35:06 +08:00
|
|
|
unsigned getLambdaId(const CXXRecordDecl *RD) {
|
|
|
|
assert(RD->isLambda() && "RD must be a lambda!");
|
|
|
|
assert(!RD->isExternallyVisible() && "RD must not be visible!");
|
|
|
|
assert(RD->getLambdaManglingNumber() == 0 &&
|
|
|
|
"RD must not have a mangling number!");
|
|
|
|
std::pair<llvm::DenseMap<const CXXRecordDecl *, unsigned>::iterator, bool>
|
|
|
|
Result = LambdaIds.insert(std::make_pair(RD, LambdaIds.size()));
|
|
|
|
return Result.first->second;
|
|
|
|
}
|
|
|
|
|
2014-03-05 16:57:59 +08:00
|
|
|
private:
|
2016-03-07 16:51:17 +08:00
|
|
|
void mangleInitFiniStub(const VarDecl *D, char CharCode, raw_ostream &Out);
|
2014-03-05 16:57:59 +08:00
|
|
|
};
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
/// MicrosoftCXXNameMangler - Manage the mangling of a single name for the
|
|
|
|
/// Microsoft Visual C++ ABI.
|
|
|
|
class MicrosoftCXXNameMangler {
|
2014-03-05 16:57:59 +08:00
|
|
|
MicrosoftMangleContextImpl &Context;
|
2012-12-18 22:30:41 +08:00
|
|
|
raw_ostream &Out;
|
|
|
|
|
2013-02-13 16:37:51 +08:00
|
|
|
/// The "structor" is the top-level declaration being mangled, if
|
|
|
|
/// that's not a template specialization; otherwise it's the pattern
|
|
|
|
/// for that specialization.
|
|
|
|
const NamedDecl *Structor;
|
|
|
|
unsigned StructorType;
|
|
|
|
|
2014-09-26 03:43:56 +08:00
|
|
|
typedef llvm::SmallVector<std::string, 10> BackRefVec;
|
|
|
|
BackRefVec NameBackReferences;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-12-31 13:36:52 +08:00
|
|
|
typedef llvm::DenseMap<const void *, unsigned> ArgBackRefMap;
|
2012-12-18 22:30:41 +08:00
|
|
|
ArgBackRefMap TypeBackReferences;
|
|
|
|
|
2015-12-30 13:13:03 +08:00
|
|
|
typedef std::set<int> PassObjectSizeArgsSet;
|
|
|
|
PassObjectSizeArgsSet PassObjectSizeArgs;
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
ASTContext &getASTContext() const { return Context.getASTContext(); }
|
|
|
|
|
2013-05-15 04:30:42 +08:00
|
|
|
// FIXME: If we add support for __ptr32/64 qualifiers, then we should push
|
|
|
|
// this check into mangleQualifiers().
|
|
|
|
const bool PointersAre64Bit;
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
public:
|
2013-04-25 12:25:40 +08:00
|
|
|
enum QualifierMangleMode { QMM_Drop, QMM_Mangle, QMM_Escape, QMM_Result };
|
|
|
|
|
2014-03-05 16:57:59 +08:00
|
|
|
MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &C, raw_ostream &Out_)
|
2014-05-12 13:36:57 +08:00
|
|
|
: Context(C), Out(Out_), Structor(nullptr), StructorType(-1),
|
2014-04-23 13:16:51 +08:00
|
|
|
PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) ==
|
|
|
|
64) {}
|
2013-02-13 16:37:51 +08:00
|
|
|
|
2015-03-12 02:36:39 +08:00
|
|
|
MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &C, raw_ostream &Out_,
|
|
|
|
const CXXConstructorDecl *D, CXXCtorType Type)
|
|
|
|
: Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type),
|
|
|
|
PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) ==
|
|
|
|
64) {}
|
|
|
|
|
2014-03-05 16:57:59 +08:00
|
|
|
MicrosoftCXXNameMangler(MicrosoftMangleContextImpl &C, raw_ostream &Out_,
|
2013-02-13 16:37:51 +08:00
|
|
|
const CXXDestructorDecl *D, CXXDtorType Type)
|
2014-04-23 13:16:51 +08:00
|
|
|
: Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type),
|
|
|
|
PointersAre64Bit(C.getASTContext().getTargetInfo().getPointerWidth(0) ==
|
|
|
|
64) {}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
raw_ostream &getStream() const { return Out; }
|
|
|
|
|
|
|
|
void mangle(const NamedDecl *D, StringRef Prefix = "\01?");
|
|
|
|
void mangleName(const NamedDecl *ND);
|
2015-05-18 08:05:25 +08:00
|
|
|
void mangleFunctionEncoding(const FunctionDecl *FD, bool ShouldMangle);
|
2012-12-18 22:30:41 +08:00
|
|
|
void mangleVariableEncoding(const VarDecl *VD);
|
2014-02-06 20:46:52 +08:00
|
|
|
void mangleMemberDataPointer(const CXXRecordDecl *RD, const ValueDecl *VD);
|
2014-02-06 01:27:08 +08:00
|
|
|
void mangleMemberFunctionPointer(const CXXRecordDecl *RD,
|
|
|
|
const CXXMethodDecl *MD);
|
|
|
|
void mangleVirtualMemPtrThunk(
|
|
|
|
const CXXMethodDecl *MD,
|
|
|
|
const MicrosoftVTableContext::MethodVFTableLocation &ML);
|
2013-12-09 18:44:32 +08:00
|
|
|
void mangleNumber(int64_t Number);
|
2015-12-29 19:45:53 +08:00
|
|
|
void mangleTagTypeKind(TagTypeKind TK);
|
|
|
|
void mangleArtificalTagType(TagTypeKind TK, StringRef UnqualifiedName,
|
|
|
|
ArrayRef<StringRef> NestedNames = None);
|
2013-04-25 12:25:40 +08:00
|
|
|
void mangleType(QualType T, SourceRange Range,
|
|
|
|
QualifierMangleMode QMM = QMM_Mangle);
|
2014-05-12 13:36:57 +08:00
|
|
|
void mangleFunctionType(const FunctionType *T,
|
|
|
|
const FunctionDecl *D = nullptr,
|
2014-08-13 01:53:10 +08:00
|
|
|
bool ForceThisQuals = false);
|
2014-03-05 16:57:59 +08:00
|
|
|
void mangleNestedName(const NamedDecl *ND);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
private:
|
2017-01-10 01:04:37 +08:00
|
|
|
bool isStructorDecl(const NamedDecl *ND) const {
|
|
|
|
return ND == Structor || getStructor(ND) == Structor;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
void mangleUnqualifiedName(const NamedDecl *ND) {
|
|
|
|
mangleUnqualifiedName(ND, ND->getDeclName());
|
|
|
|
}
|
|
|
|
void mangleUnqualifiedName(const NamedDecl *ND, DeclarationName Name);
|
2013-11-26 01:50:19 +08:00
|
|
|
void mangleSourceName(StringRef Name);
|
2012-12-18 22:30:41 +08:00
|
|
|
void mangleOperatorName(OverloadedOperatorKind OO, SourceLocation Loc);
|
2013-02-13 16:37:51 +08:00
|
|
|
void mangleCXXDtorType(CXXDtorType T);
|
2012-12-18 22:30:41 +08:00
|
|
|
void mangleQualifiers(Qualifiers Quals, bool IsMember);
|
2014-04-23 13:16:56 +08:00
|
|
|
void mangleRefQualifier(RefQualifierKind RefQualifier);
|
2014-02-18 22:20:10 +08:00
|
|
|
void manglePointerCVQualifiers(Qualifiers Quals);
|
2015-05-26 09:30:45 +08:00
|
|
|
void manglePointerExtQualifiers(Qualifiers Quals, QualType PointeeType);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
void mangleUnscopedTemplateName(const TemplateDecl *ND);
|
2014-04-23 13:16:51 +08:00
|
|
|
void
|
|
|
|
mangleTemplateInstantiationName(const TemplateDecl *TD,
|
|
|
|
const TemplateArgumentList &TemplateArgs);
|
2012-12-18 22:30:41 +08:00
|
|
|
void mangleObjCMethodName(const ObjCMethodDecl *MD);
|
|
|
|
|
|
|
|
void mangleArgumentType(QualType T, SourceRange Range);
|
2015-12-30 13:13:03 +08:00
|
|
|
void manglePassObjectSizeArg(const PassObjectSizeAttr *POSA);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Declare manglers for every type class.
|
|
|
|
#define ABSTRACT_TYPE(CLASS, PARENT)
|
|
|
|
#define NON_CANONICAL_TYPE(CLASS, PARENT)
|
|
|
|
#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T, \
|
2015-05-26 09:30:45 +08:00
|
|
|
Qualifiers Quals, \
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange Range);
|
|
|
|
#include "clang/AST/TypeNodes.def"
|
|
|
|
#undef ABSTRACT_TYPE
|
|
|
|
#undef NON_CANONICAL_TYPE
|
|
|
|
#undef TYPE
|
2013-12-13 09:06:04 +08:00
|
|
|
|
2013-08-06 06:26:46 +08:00
|
|
|
void mangleType(const TagDecl *TD);
|
2013-09-11 12:44:30 +08:00
|
|
|
void mangleDecayedArrayType(const ArrayType *T);
|
2013-06-25 03:21:52 +08:00
|
|
|
void mangleArrayType(const ArrayType *T);
|
2012-12-18 22:30:41 +08:00
|
|
|
void mangleFunctionClass(const FunctionDecl *FD);
|
2015-03-12 02:36:39 +08:00
|
|
|
void mangleCallingConvention(CallingConv CC);
|
2013-09-26 06:28:52 +08:00
|
|
|
void mangleCallingConvention(const FunctionType *T);
|
2012-12-18 22:30:41 +08:00
|
|
|
void mangleIntegerLiteral(const llvm::APSInt &Number, bool IsBoolean);
|
|
|
|
void mangleExpression(const Expr *E);
|
|
|
|
void mangleThrowSpecification(const FunctionProtoType *T);
|
|
|
|
|
2013-03-20 09:40:23 +08:00
|
|
|
void mangleTemplateArgs(const TemplateDecl *TD,
|
|
|
|
const TemplateArgumentList &TemplateArgs);
|
2014-08-06 06:43:45 +08:00
|
|
|
void mangleTemplateArg(const TemplateDecl *TD, const TemplateArgument &TA,
|
|
|
|
const NamedDecl *Parm);
|
2012-12-18 22:30:41 +08:00
|
|
|
};
|
2015-06-23 07:07:51 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-10-16 09:40:34 +08:00
|
|
|
bool MicrosoftMangleContextImpl::shouldMangleCXXName(const NamedDecl *D) {
|
2013-09-13 17:03:14 +08:00
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
|
|
|
|
LanguageLinkage L = FD->getLanguageLinkage();
|
|
|
|
// Overloadable functions need mangling.
|
|
|
|
if (FD->hasAttr<OverloadableAttr>())
|
|
|
|
return true;
|
|
|
|
|
2013-09-17 06:44:20 +08:00
|
|
|
// The ABI expects that we would never mangle "typical" user-defined entry
|
|
|
|
// points regardless of visibility or freestanding-ness.
|
|
|
|
//
|
|
|
|
// N.B. This is distinct from asking about "main". "main" has a lot of
|
|
|
|
// special rules associated with it in the standard while these
|
|
|
|
// user-defined entry points are outside of the purview of the standard.
|
|
|
|
// For example, there can be only one definition for "main" in a standards
|
|
|
|
// compliant program; however nothing forbids the existence of wmain and
|
|
|
|
// WinMain in the same translation unit.
|
|
|
|
if (FD->isMSVCRTEntryPoint())
|
2013-09-13 17:03:14 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
// C++ functions and those whose names are not a simple identifier need
|
|
|
|
// mangling.
|
|
|
|
if (!FD->getDeclName().isIdentifier() || L == CXXLanguageLinkage)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
// C functions are not mangled.
|
|
|
|
if (L == CLanguageLinkage)
|
|
|
|
return false;
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Otherwise, no mangling is done outside C++ mode.
|
|
|
|
if (!getASTContext().getLangOpts().CPlusPlus)
|
|
|
|
return false;
|
|
|
|
|
2016-08-15 09:33:41 +08:00
|
|
|
const VarDecl *VD = dyn_cast<VarDecl>(D);
|
|
|
|
if (VD && !isa<DecompositionDecl>(D)) {
|
2013-09-13 17:03:14 +08:00
|
|
|
// C variables are not mangled.
|
|
|
|
if (VD->isExternC())
|
2012-12-18 22:30:41 +08:00
|
|
|
return false;
|
|
|
|
|
2013-09-13 17:03:14 +08:00
|
|
|
// Variables at global scope with non-internal linkage are not mangled.
|
|
|
|
const DeclContext *DC = getEffectiveDeclContext(D);
|
|
|
|
// Check for extern variable declared locally.
|
|
|
|
if (DC->isFunctionOrMethod() && D->hasLinkage())
|
|
|
|
while (!DC->isNamespace() && !DC->isTranslationUnit())
|
|
|
|
DC = getEffectiveParentContext(DC);
|
|
|
|
|
|
|
|
if (DC->isTranslationUnit() && D->getFormalLinkage() == InternalLinkage &&
|
2015-10-22 15:15:56 +08:00
|
|
|
!isa<VarTemplateSpecializationDecl>(D) &&
|
|
|
|
D->getIdentifier() != nullptr)
|
2013-09-13 17:03:14 +08:00
|
|
|
return false;
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-25 05:43:36 +08:00
|
|
|
bool
|
|
|
|
MicrosoftMangleContextImpl::shouldMangleStringLiteral(const StringLiteral *SL) {
|
2014-11-22 14:20:38 +08:00
|
|
|
return true;
|
2014-03-25 05:43:36 +08:00
|
|
|
}
|
|
|
|
|
2014-04-23 13:16:51 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangle(const NamedDecl *D, StringRef Prefix) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// MSVC doesn't mangle C++ names the same way it mangles extern "C" names.
|
|
|
|
// Therefore it's really important that we don't decorate the
|
|
|
|
// name with leading underscores or leading/trailing at signs. So, by
|
|
|
|
// default, we emit an asm marker at the start so we get the name right.
|
|
|
|
// Callers can override this with a custom prefix.
|
|
|
|
|
|
|
|
// <mangled-name> ::= ? <name> <type-encoding>
|
|
|
|
Out << Prefix;
|
|
|
|
mangleName(D);
|
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
|
2015-05-18 08:05:25 +08:00
|
|
|
mangleFunctionEncoding(FD, Context.shouldMangleDeclName(FD));
|
2012-12-18 22:30:41 +08:00
|
|
|
else if (const VarDecl *VD = dyn_cast<VarDecl>(D))
|
|
|
|
mangleVariableEncoding(VD);
|
2015-12-30 06:02:10 +08:00
|
|
|
else
|
|
|
|
llvm_unreachable("Tried to mangle unexpected NamedDecl!");
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-05-18 08:05:25 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD,
|
|
|
|
bool ShouldMangle) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// <type-encoding> ::= <function-class> <function-type>
|
|
|
|
|
2013-06-25 03:21:52 +08:00
|
|
|
// Since MSVC operates on the type as written and not the canonical type, it
|
|
|
|
// actually matters which decl we have here. MSVC appears to choose the
|
|
|
|
// first, since it is most likely to be the declaration in a header file.
|
2013-10-17 23:37:26 +08:00
|
|
|
FD = FD->getFirstDecl();
|
2013-06-25 03:21:52 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// We should never ever see a FunctionNoProtoType at this point.
|
|
|
|
// We don't even know how to mangle their types anyway :).
|
2013-10-08 08:58:57 +08:00
|
|
|
const FunctionProtoType *FT = FD->getType()->castAs<FunctionProtoType>();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-09-13 17:03:14 +08:00
|
|
|
// extern "C" functions can hold entities that must be mangled.
|
|
|
|
// As it stands, these functions still need to get expressed in the full
|
|
|
|
// external name. They have their class and type omitted, replaced with '9'.
|
2015-05-18 08:05:25 +08:00
|
|
|
if (ShouldMangle) {
|
2015-05-18 08:05:29 +08:00
|
|
|
// We would like to mangle all extern "C" functions using this additional
|
|
|
|
// component but this would break compatibility with MSVC's behavior.
|
|
|
|
// Instead, do this when we know that compatibility isn't important (in
|
2015-12-17 07:10:46 +08:00
|
|
|
// other words, when it is an overloaded extern "C" function).
|
2015-05-18 08:05:29 +08:00
|
|
|
if (FD->isExternC() && FD->hasAttr<OverloadableAttr>())
|
|
|
|
Out << "$$J0";
|
|
|
|
|
2013-09-13 17:03:14 +08:00
|
|
|
mangleFunctionClass(FD);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-10-04 19:25:05 +08:00
|
|
|
mangleFunctionType(FT, FD);
|
2015-05-18 08:05:25 +08:00
|
|
|
} else {
|
2013-09-13 17:03:14 +08:00
|
|
|
Out << '9';
|
2015-05-18 08:05:25 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftCXXNameMangler::mangleVariableEncoding(const VarDecl *VD) {
|
|
|
|
// <type-encoding> ::= <storage-class> <variable-type>
|
|
|
|
// <storage-class> ::= 0 # private static member
|
|
|
|
// ::= 1 # protected static member
|
|
|
|
// ::= 2 # public static member
|
|
|
|
// ::= 3 # global
|
|
|
|
// ::= 4 # static local
|
2013-12-13 09:06:04 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// The first character in the encoding (after the name) is the storage class.
|
|
|
|
if (VD->isStaticDataMember()) {
|
|
|
|
// If it's a static member, it also encodes the access level.
|
|
|
|
switch (VD->getAccess()) {
|
|
|
|
default:
|
|
|
|
case AS_private: Out << '0'; break;
|
|
|
|
case AS_protected: Out << '1'; break;
|
|
|
|
case AS_public: Out << '2'; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!VD->isStaticLocal())
|
|
|
|
Out << '3';
|
|
|
|
else
|
|
|
|
Out << '4';
|
|
|
|
// Now mangle the type.
|
|
|
|
// <variable-type> ::= <type> <cvr-qualifiers>
|
|
|
|
// ::= <type> <pointee-cvr-qualifiers> # pointers, references
|
|
|
|
// Pointers and references are odd. The type of 'int * const foo;' gets
|
|
|
|
// mangled as 'QAHA' instead of 'PAHB', for example.
|
2014-06-25 13:37:25 +08:00
|
|
|
SourceRange SR = VD->getSourceRange();
|
2014-01-22 04:33:36 +08:00
|
|
|
QualType Ty = VD->getType();
|
2013-08-15 16:13:23 +08:00
|
|
|
if (Ty->isPointerType() || Ty->isReferenceType() ||
|
|
|
|
Ty->isMemberPointerType()) {
|
2014-06-25 13:37:25 +08:00
|
|
|
mangleType(Ty, SR, QMM_Drop);
|
2014-02-18 22:20:10 +08:00
|
|
|
manglePointerExtQualifiers(
|
2015-05-26 09:30:45 +08:00
|
|
|
Ty.getDesugaredType(getASTContext()).getLocalQualifiers(), QualType());
|
2013-08-15 16:13:23 +08:00
|
|
|
if (const MemberPointerType *MPT = Ty->getAs<MemberPointerType>()) {
|
|
|
|
mangleQualifiers(MPT->getPointeeType().getQualifiers(), true);
|
|
|
|
// Member pointers are suffixed with a back reference to the member
|
|
|
|
// pointer's class name.
|
|
|
|
mangleName(MPT->getClass()->getAsCXXRecordDecl());
|
|
|
|
} else
|
|
|
|
mangleQualifiers(Ty->getPointeeType().getQualifiers(), false);
|
2013-08-09 13:56:24 +08:00
|
|
|
} else if (const ArrayType *AT = getASTContext().getAsArrayType(Ty)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Global arrays are funny, too.
|
2013-09-11 12:44:30 +08:00
|
|
|
mangleDecayedArrayType(AT);
|
2013-04-25 12:25:40 +08:00
|
|
|
if (AT->getElementType()->isArrayType())
|
|
|
|
Out << 'A';
|
|
|
|
else
|
|
|
|
mangleQualifiers(Ty.getQualifiers(), false);
|
2012-12-18 22:30:41 +08:00
|
|
|
} else {
|
2014-06-25 13:37:25 +08:00
|
|
|
mangleType(Ty, SR, QMM_Drop);
|
2014-11-05 21:54:21 +08:00
|
|
|
mangleQualifiers(Ty.getQualifiers(), false);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-06 01:27:08 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleMemberDataPointer(const CXXRecordDecl *RD,
|
2014-02-06 20:46:52 +08:00
|
|
|
const ValueDecl *VD) {
|
2014-02-06 01:27:08 +08:00
|
|
|
// <member-data-pointer> ::= <integer-literal>
|
|
|
|
// ::= $F <number> <number>
|
|
|
|
// ::= $G <number> <number> <number>
|
|
|
|
|
2014-02-06 18:59:19 +08:00
|
|
|
int64_t FieldOffset;
|
|
|
|
int64_t VBTableOffset;
|
2014-02-06 01:27:08 +08:00
|
|
|
MSInheritanceAttr::Spelling IM = RD->getMSInheritanceModel();
|
2014-02-06 20:46:52 +08:00
|
|
|
if (VD) {
|
|
|
|
FieldOffset = getASTContext().getFieldOffset(VD);
|
2014-02-06 18:59:19 +08:00
|
|
|
assert(FieldOffset % getASTContext().getCharWidth() == 0 &&
|
2014-02-06 01:27:08 +08:00
|
|
|
"cannot take address of bitfield");
|
2014-02-06 18:59:19 +08:00
|
|
|
FieldOffset /= getASTContext().getCharWidth();
|
|
|
|
|
|
|
|
VBTableOffset = 0;
|
2015-06-24 04:34:18 +08:00
|
|
|
|
|
|
|
if (IM == MSInheritanceAttr::Keyword_virtual_inheritance)
|
|
|
|
FieldOffset -= getASTContext().getOffsetOfBaseWithVBPtr(RD).getQuantity();
|
2014-02-06 18:59:19 +08:00
|
|
|
} else {
|
|
|
|
FieldOffset = RD->nullFieldOffsetIsZero() ? 0 : -1;
|
|
|
|
|
|
|
|
VBTableOffset = -1;
|
2014-02-06 01:27:08 +08:00
|
|
|
}
|
|
|
|
|
2014-02-06 18:59:19 +08:00
|
|
|
char Code = '\0';
|
2014-02-06 01:27:08 +08:00
|
|
|
switch (IM) {
|
2014-02-06 18:59:19 +08:00
|
|
|
case MSInheritanceAttr::Keyword_single_inheritance: Code = '0'; break;
|
|
|
|
case MSInheritanceAttr::Keyword_multiple_inheritance: Code = '0'; break;
|
|
|
|
case MSInheritanceAttr::Keyword_virtual_inheritance: Code = 'F'; break;
|
|
|
|
case MSInheritanceAttr::Keyword_unspecified_inheritance: Code = 'G'; break;
|
2014-02-06 01:27:08 +08:00
|
|
|
}
|
|
|
|
|
2014-02-06 18:59:19 +08:00
|
|
|
Out << '$' << Code;
|
2014-02-06 01:27:08 +08:00
|
|
|
|
2014-02-06 18:59:19 +08:00
|
|
|
mangleNumber(FieldOffset);
|
|
|
|
|
2014-04-08 02:07:03 +08:00
|
|
|
// The C++ standard doesn't allow base-to-derived member pointer conversions
|
|
|
|
// in template parameter contexts, so the vbptr offset of data member pointers
|
|
|
|
// is always zero.
|
2014-02-06 18:59:19 +08:00
|
|
|
if (MSInheritanceAttr::hasVBPtrOffsetField(IM))
|
2014-02-06 01:27:08 +08:00
|
|
|
mangleNumber(0);
|
2014-02-06 18:59:19 +08:00
|
|
|
if (MSInheritanceAttr::hasVBTableOffsetField(IM))
|
|
|
|
mangleNumber(VBTableOffset);
|
2014-02-06 01:27:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MicrosoftCXXNameMangler::mangleMemberFunctionPointer(const CXXRecordDecl *RD,
|
|
|
|
const CXXMethodDecl *MD) {
|
|
|
|
// <member-function-pointer> ::= $1? <name>
|
|
|
|
// ::= $H? <name> <number>
|
|
|
|
// ::= $I? <name> <number> <number>
|
|
|
|
// ::= $J? <name> <number> <number> <number>
|
|
|
|
|
|
|
|
MSInheritanceAttr::Spelling IM = RD->getMSInheritanceModel();
|
|
|
|
|
|
|
|
char Code = '\0';
|
|
|
|
switch (IM) {
|
|
|
|
case MSInheritanceAttr::Keyword_single_inheritance: Code = '1'; break;
|
|
|
|
case MSInheritanceAttr::Keyword_multiple_inheritance: Code = 'H'; break;
|
|
|
|
case MSInheritanceAttr::Keyword_virtual_inheritance: Code = 'I'; break;
|
|
|
|
case MSInheritanceAttr::Keyword_unspecified_inheritance: Code = 'J'; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If non-virtual, mangle the name. If virtual, mangle as a virtual memptr
|
|
|
|
// thunk.
|
|
|
|
uint64_t NVOffset = 0;
|
|
|
|
uint64_t VBTableOffset = 0;
|
2014-04-08 02:07:03 +08:00
|
|
|
uint64_t VBPtrOffset = 0;
|
2014-06-11 12:55:08 +08:00
|
|
|
if (MD) {
|
|
|
|
Out << '$' << Code << '?';
|
|
|
|
if (MD->isVirtual()) {
|
|
|
|
MicrosoftVTableContext *VTContext =
|
|
|
|
cast<MicrosoftVTableContext>(getASTContext().getVTableContext());
|
|
|
|
const MicrosoftVTableContext::MethodVFTableLocation &ML =
|
|
|
|
VTContext->getMethodVFTableLocation(GlobalDecl(MD));
|
|
|
|
mangleVirtualMemPtrThunk(MD, ML);
|
|
|
|
NVOffset = ML.VFPtrOffset.getQuantity();
|
|
|
|
VBTableOffset = ML.VBTableIndex * 4;
|
|
|
|
if (ML.VBase) {
|
|
|
|
const ASTRecordLayout &Layout = getASTContext().getASTRecordLayout(RD);
|
|
|
|
VBPtrOffset = Layout.getVBPtrOffset().getQuantity();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mangleName(MD);
|
2015-05-18 08:05:25 +08:00
|
|
|
mangleFunctionEncoding(MD, /*ShouldMangle=*/true);
|
2014-02-06 01:27:08 +08:00
|
|
|
}
|
2015-06-24 04:34:18 +08:00
|
|
|
|
|
|
|
if (VBTableOffset == 0 &&
|
|
|
|
IM == MSInheritanceAttr::Keyword_virtual_inheritance)
|
|
|
|
NVOffset -= getASTContext().getOffsetOfBaseWithVBPtr(RD).getQuantity();
|
2014-02-06 01:27:08 +08:00
|
|
|
} else {
|
2014-06-11 12:55:08 +08:00
|
|
|
// Null single inheritance member functions are encoded as a simple nullptr.
|
|
|
|
if (IM == MSInheritanceAttr::Keyword_single_inheritance) {
|
|
|
|
Out << "$0A@";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (IM == MSInheritanceAttr::Keyword_unspecified_inheritance)
|
|
|
|
VBTableOffset = -1;
|
|
|
|
Out << '$' << Code;
|
2014-02-06 01:27:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (MSInheritanceAttr::hasNVOffsetField(/*IsMemberFunction=*/true, IM))
|
2015-06-24 04:34:18 +08:00
|
|
|
mangleNumber(static_cast<uint32_t>(NVOffset));
|
2014-02-06 01:27:08 +08:00
|
|
|
if (MSInheritanceAttr::hasVBPtrOffsetField(IM))
|
2014-04-08 02:07:03 +08:00
|
|
|
mangleNumber(VBPtrOffset);
|
2014-02-06 01:27:08 +08:00
|
|
|
if (MSInheritanceAttr::hasVBTableOffsetField(IM))
|
|
|
|
mangleNumber(VBTableOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftCXXNameMangler::mangleVirtualMemPtrThunk(
|
|
|
|
const CXXMethodDecl *MD,
|
|
|
|
const MicrosoftVTableContext::MethodVFTableLocation &ML) {
|
|
|
|
// Get the vftable offset.
|
|
|
|
CharUnits PointerWidth = getASTContext().toCharUnitsFromBits(
|
|
|
|
getASTContext().getTargetInfo().getPointerWidth(0));
|
|
|
|
uint64_t OffsetInVFTable = ML.Index * PointerWidth.getQuantity();
|
|
|
|
|
|
|
|
Out << "?_9";
|
|
|
|
mangleName(MD->getParent());
|
|
|
|
Out << "$B";
|
|
|
|
mangleNumber(OffsetInVFTable);
|
|
|
|
Out << 'A';
|
2015-03-14 14:34:41 +08:00
|
|
|
mangleCallingConvention(MD->getType()->getAs<FunctionProtoType>());
|
2014-02-06 01:27:08 +08:00
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleName(const NamedDecl *ND) {
|
|
|
|
// <name> ::= <unscoped-name> {[<named-scope>]+ | [<nested-name>]}? @
|
|
|
|
|
|
|
|
// Always start with the unqualified name.
|
2013-12-13 09:06:04 +08:00
|
|
|
mangleUnqualifiedName(ND);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-03-05 16:57:59 +08:00
|
|
|
mangleNestedName(ND);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Terminate the whole name with an '@'.
|
|
|
|
Out << '@';
|
|
|
|
}
|
|
|
|
|
2013-12-09 18:44:32 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleNumber(int64_t Number) {
|
|
|
|
// <non-negative integer> ::= A@ # when Number == 0
|
|
|
|
// ::= <decimal digit> # when 1 <= Number <= 10
|
|
|
|
// ::= <hex digit>+ @ # when Number >= 10
|
|
|
|
//
|
|
|
|
// <number> ::= [?] <non-negative integer>
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-12-09 18:44:32 +08:00
|
|
|
uint64_t Value = static_cast<uint64_t>(Number);
|
|
|
|
if (Number < 0) {
|
|
|
|
Value = -Value;
|
2012-12-18 22:30:41 +08:00
|
|
|
Out << '?';
|
|
|
|
}
|
2013-12-09 18:44:32 +08:00
|
|
|
|
|
|
|
if (Value == 0)
|
|
|
|
Out << "A@";
|
|
|
|
else if (Value >= 1 && Value <= 10)
|
|
|
|
Out << (Value - 1);
|
|
|
|
else {
|
|
|
|
// Numbers that are not encoded as decimal digits are represented as nibbles
|
|
|
|
// in the range of ASCII characters 'A' to 'P'.
|
|
|
|
// The number 0x123450 would be encoded as 'BCDEFA'
|
|
|
|
char EncodedNumberBuffer[sizeof(uint64_t) * 2];
|
2014-06-29 07:22:33 +08:00
|
|
|
MutableArrayRef<char> BufferRef(EncodedNumberBuffer);
|
|
|
|
MutableArrayRef<char>::reverse_iterator I = BufferRef.rbegin();
|
2013-12-09 18:44:32 +08:00
|
|
|
for (; Value != 0; Value >>= 4)
|
|
|
|
*I++ = 'A' + (Value & 0xf);
|
|
|
|
Out.write(I.base(), I - BufferRef.rbegin());
|
2012-12-18 22:30:41 +08:00
|
|
|
Out << '@';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TemplateDecl *
|
2013-03-20 09:40:23 +08:00
|
|
|
isTemplate(const NamedDecl *ND, const TemplateArgumentList *&TemplateArgs) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Check if we have a function template.
|
2014-04-23 13:16:51 +08:00
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
|
2012-12-18 22:30:41 +08:00
|
|
|
if (const TemplateDecl *TD = FD->getPrimaryTemplate()) {
|
2013-03-20 09:40:23 +08:00
|
|
|
TemplateArgs = FD->getTemplateSpecializationArgs();
|
2012-12-18 22:30:41 +08:00
|
|
|
return TD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we have a class template.
|
|
|
|
if (const ClassTemplateSpecializationDecl *Spec =
|
2014-04-23 13:16:51 +08:00
|
|
|
dyn_cast<ClassTemplateSpecializationDecl>(ND)) {
|
2013-03-20 09:40:23 +08:00
|
|
|
TemplateArgs = &Spec->getTemplateArgs();
|
2012-12-18 22:30:41 +08:00
|
|
|
return Spec->getSpecializedTemplate();
|
|
|
|
}
|
|
|
|
|
2014-03-04 13:38:05 +08:00
|
|
|
// Check if we have a variable template.
|
|
|
|
if (const VarTemplateSpecializationDecl *Spec =
|
|
|
|
dyn_cast<VarTemplateSpecializationDecl>(ND)) {
|
|
|
|
TemplateArgs = &Spec->getTemplateArgs();
|
|
|
|
return Spec->getSpecializedTemplate();
|
|
|
|
}
|
|
|
|
|
2014-05-12 13:36:57 +08:00
|
|
|
return nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2014-04-23 13:16:51 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
|
|
|
|
DeclarationName Name) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// <unqualified-name> ::= <operator-name>
|
|
|
|
// ::= <ctor-dtor-name>
|
|
|
|
// ::= <source-name>
|
|
|
|
// ::= <template-name>
|
2013-03-20 09:40:23 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Check if we have a template.
|
2014-05-12 13:36:57 +08:00
|
|
|
const TemplateArgumentList *TemplateArgs = nullptr;
|
2012-12-18 22:30:41 +08:00
|
|
|
if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) {
|
2013-07-13 08:43:39 +08:00
|
|
|
// Function templates aren't considered for name back referencing. This
|
|
|
|
// makes sense since function templates aren't likely to occur multiple
|
|
|
|
// times in a symbol.
|
2015-12-30 13:40:32 +08:00
|
|
|
if (isa<FunctionTemplateDecl>(TD)) {
|
2013-07-13 08:43:39 +08:00
|
|
|
mangleTemplateInstantiationName(TD, *TemplateArgs);
|
2014-06-27 06:42:18 +08:00
|
|
|
Out << '@';
|
2013-07-13 08:43:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Here comes the tricky thing: if we need to mangle something like
|
|
|
|
// void foo(A::X<Y>, B::X<Y>),
|
|
|
|
// the X<Y> part is aliased. However, if you need to mangle
|
|
|
|
// void foo(A::X<A::Y>, A::X<B::Y>),
|
|
|
|
// the A::X<> part is not aliased.
|
|
|
|
// That said, from the mangler's perspective we have a structure like this:
|
|
|
|
// namespace[s] -> type[ -> template-parameters]
|
|
|
|
// but from the Clang perspective we have
|
|
|
|
// type [ -> template-parameters]
|
|
|
|
// \-> namespace[s]
|
|
|
|
// What we do is we create a new mangler, mangle the same type (without
|
2014-06-08 12:51:13 +08:00
|
|
|
// a namespace suffix) to a string using the extra mangler and then use
|
|
|
|
// the mangled type name as a key to check the mangling of different types
|
|
|
|
// for aliasing.
|
|
|
|
|
2014-06-27 06:42:18 +08:00
|
|
|
llvm::SmallString<64> TemplateMangling;
|
|
|
|
llvm::raw_svector_ostream Stream(TemplateMangling);
|
2014-06-08 12:51:13 +08:00
|
|
|
MicrosoftCXXNameMangler Extra(Context, Stream);
|
|
|
|
Extra.mangleTemplateInstantiationName(TD, *TemplateArgs);
|
|
|
|
|
2014-06-27 06:42:18 +08:00
|
|
|
mangleSourceName(TemplateMangling);
|
2012-12-18 22:30:41 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (Name.getNameKind()) {
|
|
|
|
case DeclarationName::Identifier: {
|
|
|
|
if (const IdentifierInfo *II = Name.getAsIdentifierInfo()) {
|
2013-11-26 01:50:19 +08:00
|
|
|
mangleSourceName(II->getName());
|
2012-12-18 22:30:41 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-12-13 09:06:04 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// Otherwise, an anonymous entity. We must have a declaration.
|
|
|
|
assert(ND && "mangling empty name without declaration");
|
2013-12-13 09:06:04 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (const NamespaceDecl *NS = dyn_cast<NamespaceDecl>(ND)) {
|
|
|
|
if (NS->isAnonymousNamespace()) {
|
|
|
|
Out << "?A@";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-12-13 09:06:04 +08:00
|
|
|
|
2016-08-15 09:33:41 +08:00
|
|
|
if (const DecompositionDecl *DD = dyn_cast<DecompositionDecl>(ND)) {
|
|
|
|
// FIXME: Invented mangling for decomposition declarations:
|
|
|
|
// [X,Y,Z]
|
|
|
|
// where X,Y,Z are the names of the bindings.
|
|
|
|
llvm::SmallString<128> Name("[");
|
|
|
|
for (auto *BD : DD->bindings()) {
|
|
|
|
if (Name.size() > 1)
|
|
|
|
Name += ',';
|
|
|
|
Name += BD->getDeclName().getAsIdentifierInfo()->getName();
|
|
|
|
}
|
|
|
|
Name += ']';
|
|
|
|
mangleSourceName(Name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-03-05 16:57:59 +08:00
|
|
|
if (const VarDecl *VD = dyn_cast<VarDecl>(ND)) {
|
|
|
|
// We must have an anonymous union or struct declaration.
|
|
|
|
const CXXRecordDecl *RD = VD->getType()->getAsCXXRecordDecl();
|
|
|
|
assert(RD && "expected variable decl to have a record type");
|
|
|
|
// Anonymous types with no tag or typedef get the name of their
|
|
|
|
// declarator mangled in. If they have no declarator, number them with
|
|
|
|
// a $S prefix.
|
|
|
|
llvm::SmallString<64> Name("$S");
|
|
|
|
// Get a unique id for the anonymous struct.
|
|
|
|
Name += llvm::utostr(Context.getAnonymousStructId(RD) + 1);
|
|
|
|
mangleSourceName(Name.str());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// We must have an anonymous struct.
|
|
|
|
const TagDecl *TD = cast<TagDecl>(ND);
|
|
|
|
if (const TypedefNameDecl *D = TD->getTypedefNameForAnonDecl()) {
|
|
|
|
assert(TD->getDeclContext() == D->getDeclContext() &&
|
|
|
|
"Typedef should not be in another decl context!");
|
|
|
|
assert(D->getDeclName().getAsIdentifierInfo() &&
|
|
|
|
"Typedef was not named!");
|
2013-11-26 01:50:19 +08:00
|
|
|
mangleSourceName(D->getDeclName().getAsIdentifierInfo()->getName());
|
2012-12-18 22:30:41 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-03-05 18:35:06 +08:00
|
|
|
if (const CXXRecordDecl *Record = dyn_cast<CXXRecordDecl>(TD)) {
|
|
|
|
if (Record->isLambda()) {
|
|
|
|
llvm::SmallString<10> Name("<lambda_");
|
2016-12-07 01:01:02 +08:00
|
|
|
|
|
|
|
Decl *LambdaContextDecl = Record->getLambdaContextDecl();
|
|
|
|
unsigned LambdaManglingNumber = Record->getLambdaManglingNumber();
|
2014-03-05 18:35:06 +08:00
|
|
|
unsigned LambdaId;
|
2016-12-07 01:01:02 +08:00
|
|
|
const ParmVarDecl *Parm =
|
|
|
|
dyn_cast_or_null<ParmVarDecl>(LambdaContextDecl);
|
|
|
|
const FunctionDecl *Func =
|
|
|
|
Parm ? dyn_cast<FunctionDecl>(Parm->getDeclContext()) : nullptr;
|
|
|
|
|
|
|
|
if (Func) {
|
|
|
|
unsigned DefaultArgNo =
|
|
|
|
Func->getNumParams() - Parm->getFunctionScopeIndex();
|
|
|
|
Name += llvm::utostr(DefaultArgNo);
|
|
|
|
Name += "_";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LambdaManglingNumber)
|
|
|
|
LambdaId = LambdaManglingNumber;
|
2014-03-05 18:35:06 +08:00
|
|
|
else
|
|
|
|
LambdaId = Context.getLambdaId(Record);
|
|
|
|
|
|
|
|
Name += llvm::utostr(LambdaId);
|
|
|
|
Name += ">";
|
|
|
|
|
|
|
|
mangleSourceName(Name);
|
2016-12-07 01:01:02 +08:00
|
|
|
|
|
|
|
// If the context of a closure type is an initializer for a class
|
|
|
|
// member (static or nonstatic), it is encoded in a qualified name.
|
|
|
|
if (LambdaManglingNumber && LambdaContextDecl) {
|
|
|
|
if ((isa<VarDecl>(LambdaContextDecl) ||
|
|
|
|
isa<FieldDecl>(LambdaContextDecl)) &&
|
|
|
|
LambdaContextDecl->getDeclContext()->isRecord()) {
|
|
|
|
mangleUnqualifiedName(cast<NamedDecl>(LambdaContextDecl));
|
|
|
|
}
|
|
|
|
}
|
2014-03-05 18:35:06 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-25 13:26:02 +08:00
|
|
|
llvm::SmallString<64> Name;
|
2015-09-01 02:48:39 +08:00
|
|
|
if (DeclaratorDecl *DD =
|
|
|
|
Context.getASTContext().getDeclaratorForUnnamedTagDecl(TD)) {
|
|
|
|
// Anonymous types without a name for linkage purposes have their
|
2014-03-05 16:57:59 +08:00
|
|
|
// declarator mangled in if they have one.
|
2016-12-25 13:26:02 +08:00
|
|
|
Name += "<unnamed-type-";
|
2015-09-01 02:48:39 +08:00
|
|
|
Name += DD->getName();
|
|
|
|
} else if (TypedefNameDecl *TND =
|
|
|
|
Context.getASTContext().getTypedefNameForUnnamedTagDecl(
|
|
|
|
TD)) {
|
|
|
|
// Anonymous types without a name for linkage purposes have their
|
|
|
|
// associate typedef mangled in if they have one.
|
2016-12-25 13:26:02 +08:00
|
|
|
Name += "<unnamed-type-";
|
2015-09-01 02:48:39 +08:00
|
|
|
Name += TND->getName();
|
2016-12-25 13:26:02 +08:00
|
|
|
} else if (auto *ED = dyn_cast<EnumDecl>(TD)) {
|
|
|
|
auto EnumeratorI = ED->enumerator_begin();
|
|
|
|
assert(EnumeratorI != ED->enumerator_end());
|
|
|
|
Name += "<unnamed-enum-";
|
|
|
|
Name += EnumeratorI->getName();
|
2013-11-26 01:50:19 +08:00
|
|
|
} else {
|
2014-03-05 16:57:59 +08:00
|
|
|
// Otherwise, number the types using a $S prefix.
|
2016-12-25 13:26:02 +08:00
|
|
|
Name += "<unnamed-type-$S";
|
2015-10-22 15:15:56 +08:00
|
|
|
Name += llvm::utostr(Context.getAnonymousStructId(TD) + 1);
|
2013-11-26 01:50:19 +08:00
|
|
|
}
|
2014-03-05 16:57:59 +08:00
|
|
|
Name += ">";
|
|
|
|
mangleSourceName(Name.str());
|
2012-12-18 22:30:41 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-12-13 09:06:04 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
case DeclarationName::ObjCZeroArgSelector:
|
|
|
|
case DeclarationName::ObjCOneArgSelector:
|
|
|
|
case DeclarationName::ObjCMultiArgSelector:
|
|
|
|
llvm_unreachable("Can't mangle Objective-C selector names here!");
|
2013-12-13 09:06:04 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
case DeclarationName::CXXConstructorName:
|
2017-01-10 01:09:59 +08:00
|
|
|
if (isStructorDecl(ND)) {
|
2015-03-12 02:36:39 +08:00
|
|
|
if (StructorType == Ctor_CopyingClosure) {
|
|
|
|
Out << "?_O";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (StructorType == Ctor_DefaultClosure) {
|
|
|
|
Out << "?_F";
|
|
|
|
return;
|
|
|
|
}
|
2013-02-27 21:46:31 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
Out << "?0";
|
2015-03-12 02:36:39 +08:00
|
|
|
return;
|
2013-12-13 09:06:04 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
case DeclarationName::CXXDestructorName:
|
2017-01-10 01:04:37 +08:00
|
|
|
if (isStructorDecl(ND))
|
2013-02-13 16:37:51 +08:00
|
|
|
// If the named decl is the C++ destructor we're mangling,
|
|
|
|
// use the type we were given.
|
|
|
|
mangleCXXDtorType(static_cast<CXXDtorType>(StructorType));
|
|
|
|
else
|
[ms-cxxabi] Emit linkonce complete dtors in TUs that need them
Based on Peter Collingbourne's destructor patches.
Prior to this change, clang was considering ?1 to be the complete
destructor and the base destructor, which was wrong. This lead to
crashes when clang tried to emit two LLVM functions with the same name.
In this ABI, TUs with non-inline dtors might not emit a complete
destructor. They are emitted as inline thunks in TUs that need them,
and they always delegate to the base dtors of the complete class and its
virtual bases. This change uses the DeferredDecls machinery to emit
complete dtors as needed.
Currently in clang try body destructors can catch exceptions thrown by
virtual base destructors. In the Microsoft C++ ABI, clang may not have
the destructor definition, in which case clang won't wrap the virtual
virtual base destructor calls in a try-catch. Diagnosing this in user
code is TODO.
Finally, for classes that don't use virtual inheritance, MSVC always
calls the base destructor (?1) directly. This is a useful code size
optimization that avoids emitting lots of extra thunks or aliases.
Implementing it also means our existing tests continue to pass, and is
consistent with MSVC's output.
We can do the same for Itanium by tweaking GetAddrOfCXXDestructor, but
it will require further testing.
Reviewers: rjmccall
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1066
llvm-svn: 186828
2013-07-22 21:51:44 +08:00
|
|
|
// Otherwise, use the base destructor name. This is relevant if a
|
2013-02-13 16:37:51 +08:00
|
|
|
// class with a destructor is declared within a destructor.
|
[ms-cxxabi] Emit linkonce complete dtors in TUs that need them
Based on Peter Collingbourne's destructor patches.
Prior to this change, clang was considering ?1 to be the complete
destructor and the base destructor, which was wrong. This lead to
crashes when clang tried to emit two LLVM functions with the same name.
In this ABI, TUs with non-inline dtors might not emit a complete
destructor. They are emitted as inline thunks in TUs that need them,
and they always delegate to the base dtors of the complete class and its
virtual bases. This change uses the DeferredDecls machinery to emit
complete dtors as needed.
Currently in clang try body destructors can catch exceptions thrown by
virtual base destructors. In the Microsoft C++ ABI, clang may not have
the destructor definition, in which case clang won't wrap the virtual
virtual base destructor calls in a try-catch. Diagnosing this in user
code is TODO.
Finally, for classes that don't use virtual inheritance, MSVC always
calls the base destructor (?1) directly. This is a useful code size
optimization that avoids emitting lots of extra thunks or aliases.
Implementing it also means our existing tests continue to pass, and is
consistent with MSVC's output.
We can do the same for Itanium by tweaking GetAddrOfCXXDestructor, but
it will require further testing.
Reviewers: rjmccall
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1066
llvm-svn: 186828
2013-07-22 21:51:44 +08:00
|
|
|
mangleCXXDtorType(Dtor_Base);
|
2012-12-18 22:30:41 +08:00
|
|
|
break;
|
2013-12-13 09:06:04 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
case DeclarationName::CXXConversionFunctionName:
|
|
|
|
// <operator-name> ::= ?B # (cast)
|
|
|
|
// The target type is encoded as the return type.
|
|
|
|
Out << "?B";
|
|
|
|
break;
|
2013-12-13 09:06:04 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
case DeclarationName::CXXOperatorName:
|
|
|
|
mangleOperatorName(Name.getCXXOverloadedOperator(), ND->getLocation());
|
|
|
|
break;
|
2013-12-13 09:06:04 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
case DeclarationName::CXXLiteralOperatorName: {
|
2014-06-05 00:46:26 +08:00
|
|
|
Out << "?__K";
|
|
|
|
mangleSourceName(Name.getCXXLiteralIdentifier()->getName());
|
2012-12-18 22:30:41 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-12-13 09:06:04 +08:00
|
|
|
|
2017-02-07 09:37:30 +08:00
|
|
|
case DeclarationName::CXXDeductionGuideName:
|
|
|
|
llvm_unreachable("Can't mangle a deduction guide name!");
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
case DeclarationName::CXXUsingDirective:
|
|
|
|
llvm_unreachable("Can't mangle a using directive name!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 16:57:59 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleNestedName(const NamedDecl *ND) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// <postfix> ::= <unqualified-name> [<postfix>]
|
|
|
|
// ::= <substitution> [<postfix>]
|
2014-08-06 11:12:47 +08:00
|
|
|
const DeclContext *DC = getEffectiveDeclContext(ND);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-03-05 16:57:59 +08:00
|
|
|
while (!DC->isTranslationUnit()) {
|
|
|
|
if (isa<TagDecl>(ND) || isa<VarDecl>(ND)) {
|
|
|
|
unsigned Disc;
|
|
|
|
if (Context.getNextDiscriminator(ND, Disc)) {
|
|
|
|
Out << '?';
|
|
|
|
mangleNumber(Disc);
|
|
|
|
Out << '?';
|
|
|
|
}
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2014-03-05 16:57:59 +08:00
|
|
|
if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) {
|
2014-05-12 06:10:52 +08:00
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
2014-03-05 16:57:59 +08:00
|
|
|
unsigned DiagID =
|
|
|
|
Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle a local inside this block yet");
|
|
|
|
Diags.Report(BD->getLocation(), DiagID);
|
|
|
|
|
|
|
|
// FIXME: This is completely, utterly, wrong; see ItaniumMangle
|
|
|
|
// for how this should be done.
|
|
|
|
Out << "__block_invoke" << Context.getBlockId(BD, false);
|
|
|
|
Out << '@';
|
|
|
|
} else if (const ObjCMethodDecl *Method = dyn_cast<ObjCMethodDecl>(DC)) {
|
|
|
|
mangleObjCMethodName(Method);
|
|
|
|
} else if (isa<NamedDecl>(DC)) {
|
|
|
|
ND = cast<NamedDecl>(DC);
|
|
|
|
if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
|
|
|
|
mangle(FD, "?");
|
|
|
|
break;
|
2016-12-07 01:01:02 +08:00
|
|
|
} else {
|
2014-03-05 16:57:59 +08:00
|
|
|
mangleUnqualifiedName(ND);
|
2016-12-07 01:01:02 +08:00
|
|
|
// Lambdas in default arguments conceptually belong to the function the
|
|
|
|
// parameter corresponds to.
|
|
|
|
if (const auto *LDADC = getLambdaDefaultArgumentDeclContext(ND)) {
|
|
|
|
DC = LDADC;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-03-05 16:57:59 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
DC = DC->getParent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-13 16:37:51 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleCXXDtorType(CXXDtorType T) {
|
[ms-cxxabi] Emit linkonce complete dtors in TUs that need them
Based on Peter Collingbourne's destructor patches.
Prior to this change, clang was considering ?1 to be the complete
destructor and the base destructor, which was wrong. This lead to
crashes when clang tried to emit two LLVM functions with the same name.
In this ABI, TUs with non-inline dtors might not emit a complete
destructor. They are emitted as inline thunks in TUs that need them,
and they always delegate to the base dtors of the complete class and its
virtual bases. This change uses the DeferredDecls machinery to emit
complete dtors as needed.
Currently in clang try body destructors can catch exceptions thrown by
virtual base destructors. In the Microsoft C++ ABI, clang may not have
the destructor definition, in which case clang won't wrap the virtual
virtual base destructor calls in a try-catch. Diagnosing this in user
code is TODO.
Finally, for classes that don't use virtual inheritance, MSVC always
calls the base destructor (?1) directly. This is a useful code size
optimization that avoids emitting lots of extra thunks or aliases.
Implementing it also means our existing tests continue to pass, and is
consistent with MSVC's output.
We can do the same for Itanium by tweaking GetAddrOfCXXDestructor, but
it will require further testing.
Reviewers: rjmccall
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1066
llvm-svn: 186828
2013-07-22 21:51:44 +08:00
|
|
|
// Microsoft uses the names on the case labels for these dtor variants. Clang
|
|
|
|
// uses the Itanium terminology internally. Everything in this ABI delegates
|
|
|
|
// towards the base dtor.
|
2013-02-13 16:37:51 +08:00
|
|
|
switch (T) {
|
[ms-cxxabi] Emit linkonce complete dtors in TUs that need them
Based on Peter Collingbourne's destructor patches.
Prior to this change, clang was considering ?1 to be the complete
destructor and the base destructor, which was wrong. This lead to
crashes when clang tried to emit two LLVM functions with the same name.
In this ABI, TUs with non-inline dtors might not emit a complete
destructor. They are emitted as inline thunks in TUs that need them,
and they always delegate to the base dtors of the complete class and its
virtual bases. This change uses the DeferredDecls machinery to emit
complete dtors as needed.
Currently in clang try body destructors can catch exceptions thrown by
virtual base destructors. In the Microsoft C++ ABI, clang may not have
the destructor definition, in which case clang won't wrap the virtual
virtual base destructor calls in a try-catch. Diagnosing this in user
code is TODO.
Finally, for classes that don't use virtual inheritance, MSVC always
calls the base destructor (?1) directly. This is a useful code size
optimization that avoids emitting lots of extra thunks or aliases.
Implementing it also means our existing tests continue to pass, and is
consistent with MSVC's output.
We can do the same for Itanium by tweaking GetAddrOfCXXDestructor, but
it will require further testing.
Reviewers: rjmccall
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D1066
llvm-svn: 186828
2013-07-22 21:51:44 +08:00
|
|
|
// <operator-name> ::= ?1 # destructor
|
|
|
|
case Dtor_Base: Out << "?1"; return;
|
|
|
|
// <operator-name> ::= ?_D # vbase destructor
|
|
|
|
case Dtor_Complete: Out << "?_D"; return;
|
|
|
|
// <operator-name> ::= ?_G # scalar deleting destructor
|
|
|
|
case Dtor_Deleting: Out << "?_G"; return;
|
|
|
|
// <operator-name> ::= ?_E # vector deleting destructor
|
|
|
|
// FIXME: Add a vector deleting dtor type. It goes in the vtable, so we need
|
|
|
|
// it.
|
2014-09-16 23:18:21 +08:00
|
|
|
case Dtor_Comdat:
|
|
|
|
llvm_unreachable("not expecting a COMDAT");
|
2013-02-13 16:37:51 +08:00
|
|
|
}
|
|
|
|
llvm_unreachable("Unsupported dtor type?");
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleOperatorName(OverloadedOperatorKind OO,
|
|
|
|
SourceLocation Loc) {
|
|
|
|
switch (OO) {
|
|
|
|
// ?0 # constructor
|
|
|
|
// ?1 # destructor
|
|
|
|
// <operator-name> ::= ?2 # new
|
|
|
|
case OO_New: Out << "?2"; break;
|
|
|
|
// <operator-name> ::= ?3 # delete
|
|
|
|
case OO_Delete: Out << "?3"; break;
|
|
|
|
// <operator-name> ::= ?4 # =
|
|
|
|
case OO_Equal: Out << "?4"; break;
|
|
|
|
// <operator-name> ::= ?5 # >>
|
|
|
|
case OO_GreaterGreater: Out << "?5"; break;
|
|
|
|
// <operator-name> ::= ?6 # <<
|
|
|
|
case OO_LessLess: Out << "?6"; break;
|
|
|
|
// <operator-name> ::= ?7 # !
|
|
|
|
case OO_Exclaim: Out << "?7"; break;
|
|
|
|
// <operator-name> ::= ?8 # ==
|
|
|
|
case OO_EqualEqual: Out << "?8"; break;
|
|
|
|
// <operator-name> ::= ?9 # !=
|
|
|
|
case OO_ExclaimEqual: Out << "?9"; break;
|
|
|
|
// <operator-name> ::= ?A # []
|
|
|
|
case OO_Subscript: Out << "?A"; break;
|
|
|
|
// ?B # conversion
|
|
|
|
// <operator-name> ::= ?C # ->
|
|
|
|
case OO_Arrow: Out << "?C"; break;
|
|
|
|
// <operator-name> ::= ?D # *
|
|
|
|
case OO_Star: Out << "?D"; break;
|
|
|
|
// <operator-name> ::= ?E # ++
|
|
|
|
case OO_PlusPlus: Out << "?E"; break;
|
|
|
|
// <operator-name> ::= ?F # --
|
|
|
|
case OO_MinusMinus: Out << "?F"; break;
|
|
|
|
// <operator-name> ::= ?G # -
|
|
|
|
case OO_Minus: Out << "?G"; break;
|
|
|
|
// <operator-name> ::= ?H # +
|
|
|
|
case OO_Plus: Out << "?H"; break;
|
|
|
|
// <operator-name> ::= ?I # &
|
|
|
|
case OO_Amp: Out << "?I"; break;
|
|
|
|
// <operator-name> ::= ?J # ->*
|
|
|
|
case OO_ArrowStar: Out << "?J"; break;
|
|
|
|
// <operator-name> ::= ?K # /
|
|
|
|
case OO_Slash: Out << "?K"; break;
|
|
|
|
// <operator-name> ::= ?L # %
|
|
|
|
case OO_Percent: Out << "?L"; break;
|
|
|
|
// <operator-name> ::= ?M # <
|
|
|
|
case OO_Less: Out << "?M"; break;
|
|
|
|
// <operator-name> ::= ?N # <=
|
|
|
|
case OO_LessEqual: Out << "?N"; break;
|
|
|
|
// <operator-name> ::= ?O # >
|
|
|
|
case OO_Greater: Out << "?O"; break;
|
|
|
|
// <operator-name> ::= ?P # >=
|
|
|
|
case OO_GreaterEqual: Out << "?P"; break;
|
|
|
|
// <operator-name> ::= ?Q # ,
|
|
|
|
case OO_Comma: Out << "?Q"; break;
|
|
|
|
// <operator-name> ::= ?R # ()
|
|
|
|
case OO_Call: Out << "?R"; break;
|
|
|
|
// <operator-name> ::= ?S # ~
|
|
|
|
case OO_Tilde: Out << "?S"; break;
|
|
|
|
// <operator-name> ::= ?T # ^
|
|
|
|
case OO_Caret: Out << "?T"; break;
|
|
|
|
// <operator-name> ::= ?U # |
|
|
|
|
case OO_Pipe: Out << "?U"; break;
|
|
|
|
// <operator-name> ::= ?V # &&
|
|
|
|
case OO_AmpAmp: Out << "?V"; break;
|
|
|
|
// <operator-name> ::= ?W # ||
|
|
|
|
case OO_PipePipe: Out << "?W"; break;
|
|
|
|
// <operator-name> ::= ?X # *=
|
|
|
|
case OO_StarEqual: Out << "?X"; break;
|
|
|
|
// <operator-name> ::= ?Y # +=
|
|
|
|
case OO_PlusEqual: Out << "?Y"; break;
|
|
|
|
// <operator-name> ::= ?Z # -=
|
|
|
|
case OO_MinusEqual: Out << "?Z"; break;
|
|
|
|
// <operator-name> ::= ?_0 # /=
|
|
|
|
case OO_SlashEqual: Out << "?_0"; break;
|
|
|
|
// <operator-name> ::= ?_1 # %=
|
|
|
|
case OO_PercentEqual: Out << "?_1"; break;
|
|
|
|
// <operator-name> ::= ?_2 # >>=
|
|
|
|
case OO_GreaterGreaterEqual: Out << "?_2"; break;
|
|
|
|
// <operator-name> ::= ?_3 # <<=
|
|
|
|
case OO_LessLessEqual: Out << "?_3"; break;
|
|
|
|
// <operator-name> ::= ?_4 # &=
|
|
|
|
case OO_AmpEqual: Out << "?_4"; break;
|
|
|
|
// <operator-name> ::= ?_5 # |=
|
|
|
|
case OO_PipeEqual: Out << "?_5"; break;
|
|
|
|
// <operator-name> ::= ?_6 # ^=
|
|
|
|
case OO_CaretEqual: Out << "?_6"; break;
|
|
|
|
// ?_7 # vftable
|
|
|
|
// ?_8 # vbtable
|
|
|
|
// ?_9 # vcall
|
|
|
|
// ?_A # typeof
|
|
|
|
// ?_B # local static guard
|
|
|
|
// ?_C # string
|
|
|
|
// ?_D # vbase destructor
|
|
|
|
// ?_E # vector deleting destructor
|
|
|
|
// ?_F # default constructor closure
|
|
|
|
// ?_G # scalar deleting destructor
|
|
|
|
// ?_H # vector constructor iterator
|
|
|
|
// ?_I # vector destructor iterator
|
|
|
|
// ?_J # vector vbase constructor iterator
|
|
|
|
// ?_K # virtual displacement map
|
|
|
|
// ?_L # eh vector constructor iterator
|
|
|
|
// ?_M # eh vector destructor iterator
|
|
|
|
// ?_N # eh vector vbase constructor iterator
|
|
|
|
// ?_O # copy constructor closure
|
|
|
|
// ?_P<name> # udt returning <name>
|
|
|
|
// ?_Q # <unknown>
|
|
|
|
// ?_R0 # RTTI Type Descriptor
|
|
|
|
// ?_R1 # RTTI Base Class Descriptor at (a,b,c,d)
|
|
|
|
// ?_R2 # RTTI Base Class Array
|
|
|
|
// ?_R3 # RTTI Class Hierarchy Descriptor
|
|
|
|
// ?_R4 # RTTI Complete Object Locator
|
|
|
|
// ?_S # local vftable
|
|
|
|
// ?_T # local vftable constructor closure
|
|
|
|
// <operator-name> ::= ?_U # new[]
|
|
|
|
case OO_Array_New: Out << "?_U"; break;
|
|
|
|
// <operator-name> ::= ?_V # delete[]
|
|
|
|
case OO_Array_Delete: Out << "?_V"; break;
|
2016-09-29 06:37:17 +08:00
|
|
|
// <operator-name> ::= ?__L # co_await
|
|
|
|
case OO_Coawait: Out << "?__L"; break;
|
2013-12-13 09:06:04 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
case OO_Conditional: {
|
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle this conditional operator yet");
|
|
|
|
Diags.Report(Loc, DiagID);
|
|
|
|
break;
|
|
|
|
}
|
2013-12-13 09:06:04 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
case OO_None:
|
|
|
|
case NUM_OVERLOADED_OPERATORS:
|
|
|
|
llvm_unreachable("Not an overloaded operator");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-26 01:50:19 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleSourceName(StringRef Name) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// <source name> ::= <identifier> @
|
2014-09-26 03:43:56 +08:00
|
|
|
BackRefVec::iterator Found =
|
|
|
|
std::find(NameBackReferences.begin(), NameBackReferences.end(), Name);
|
2014-06-08 12:51:13 +08:00
|
|
|
if (Found == NameBackReferences.end()) {
|
2014-09-26 03:43:56 +08:00
|
|
|
if (NameBackReferences.size() < 10)
|
|
|
|
NameBackReferences.push_back(Name);
|
2013-11-26 01:50:19 +08:00
|
|
|
Out << Name << '@';
|
2012-12-18 22:30:41 +08:00
|
|
|
} else {
|
2014-09-26 03:43:56 +08:00
|
|
|
Out << (Found - NameBackReferences.begin());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftCXXNameMangler::mangleObjCMethodName(const ObjCMethodDecl *MD) {
|
|
|
|
Context.mangleObjCMethodName(MD, Out);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftCXXNameMangler::mangleTemplateInstantiationName(
|
2014-04-23 13:16:51 +08:00
|
|
|
const TemplateDecl *TD, const TemplateArgumentList &TemplateArgs) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// <template-name> ::= <unscoped-template-name> <template-args>
|
|
|
|
// ::= <substitution>
|
|
|
|
// Always start with the unqualified name.
|
|
|
|
|
|
|
|
// Templates have their own context for back references.
|
|
|
|
ArgBackRefMap OuterArgsContext;
|
2014-09-26 03:43:56 +08:00
|
|
|
BackRefVec OuterTemplateContext;
|
2015-12-30 13:13:03 +08:00
|
|
|
PassObjectSizeArgsSet OuterPassObjectSizeArgs;
|
2012-12-18 22:30:41 +08:00
|
|
|
NameBackReferences.swap(OuterTemplateContext);
|
|
|
|
TypeBackReferences.swap(OuterArgsContext);
|
2015-12-30 13:13:03 +08:00
|
|
|
PassObjectSizeArgs.swap(OuterPassObjectSizeArgs);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
mangleUnscopedTemplateName(TD);
|
2013-03-20 09:40:23 +08:00
|
|
|
mangleTemplateArgs(TD, TemplateArgs);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// Restore the previous back reference contexts.
|
|
|
|
NameBackReferences.swap(OuterTemplateContext);
|
|
|
|
TypeBackReferences.swap(OuterArgsContext);
|
2015-12-30 13:13:03 +08:00
|
|
|
PassObjectSizeArgs.swap(OuterPassObjectSizeArgs);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MicrosoftCXXNameMangler::mangleUnscopedTemplateName(const TemplateDecl *TD) {
|
|
|
|
// <unscoped-template-name> ::= ?$ <unqualified-name>
|
|
|
|
Out << "?$";
|
|
|
|
mangleUnqualifiedName(TD);
|
|
|
|
}
|
|
|
|
|
2014-04-23 13:16:51 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleIntegerLiteral(const llvm::APSInt &Value,
|
|
|
|
bool IsBoolean) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// <integer-literal> ::= $0 <number>
|
|
|
|
Out << "$0";
|
|
|
|
// Make sure booleans are encoded as 0/1.
|
|
|
|
if (IsBoolean && Value.getBoolValue())
|
|
|
|
mangleNumber(1);
|
2014-12-11 13:47:10 +08:00
|
|
|
else if (Value.isSigned())
|
2013-12-09 18:44:32 +08:00
|
|
|
mangleNumber(Value.getSExtValue());
|
2014-12-11 13:47:10 +08:00
|
|
|
else
|
|
|
|
mangleNumber(Value.getZExtValue());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2014-04-23 13:16:51 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleExpression(const Expr *E) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// See if this is a constant expression.
|
|
|
|
llvm::APSInt Value;
|
|
|
|
if (E->isIntegerConstantExpr(Value, Context.getASTContext())) {
|
|
|
|
mangleIntegerLiteral(Value, E->getType()->isBooleanType());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-11 04:06:25 +08:00
|
|
|
// Look through no-op casts like template parameter substitutions.
|
|
|
|
E = E->IgnoreParenNoopCasts(Context.getASTContext());
|
|
|
|
|
2014-05-12 13:36:57 +08:00
|
|
|
const CXXUuidofExpr *UE = nullptr;
|
2013-08-13 14:32:20 +08:00
|
|
|
if (const UnaryOperator *UO = dyn_cast<UnaryOperator>(E)) {
|
|
|
|
if (UO->getOpcode() == UO_AddrOf)
|
|
|
|
UE = dyn_cast<CXXUuidofExpr>(UO->getSubExpr());
|
|
|
|
} else
|
|
|
|
UE = dyn_cast<CXXUuidofExpr>(E);
|
|
|
|
|
|
|
|
if (UE) {
|
2013-08-13 17:17:25 +08:00
|
|
|
// If we had to peek through an address-of operator, treat this like we are
|
2013-08-13 14:32:20 +08:00
|
|
|
// dealing with a pointer type. Otherwise, treat it like a const reference.
|
|
|
|
//
|
|
|
|
// N.B. This matches up with the handling of TemplateArgument::Declaration
|
|
|
|
// in mangleTemplateArg
|
|
|
|
if (UE == E)
|
|
|
|
Out << "$E?";
|
|
|
|
else
|
|
|
|
Out << "$1?";
|
2015-12-29 19:45:53 +08:00
|
|
|
|
|
|
|
// This CXXUuidofExpr is mangled as-if it were actually a VarDecl from
|
|
|
|
// const __s_GUID _GUID_{lower case UUID with underscores}
|
2016-03-28 11:19:50 +08:00
|
|
|
StringRef Uuid = UE->getUuidStr();
|
2015-12-29 19:45:53 +08:00
|
|
|
std::string Name = "_GUID_" + Uuid.lower();
|
|
|
|
std::replace(Name.begin(), Name.end(), '-', '_');
|
|
|
|
|
|
|
|
mangleSourceName(Name);
|
|
|
|
// Terminate the whole name with an '@'.
|
|
|
|
Out << '@';
|
|
|
|
// It's a global variable.
|
|
|
|
Out << '3';
|
|
|
|
// It's a struct called __s_GUID.
|
|
|
|
mangleArtificalTagType(TTK_Struct, "__s_GUID");
|
|
|
|
// It's const.
|
|
|
|
Out << 'B';
|
2013-08-13 14:32:20 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// As bad as this diagnostic is, it's better than crashing.
|
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
2014-04-23 13:16:51 +08:00
|
|
|
unsigned DiagID = Diags.getCustomDiagID(
|
|
|
|
DiagnosticsEngine::Error, "cannot yet mangle expression type %0");
|
|
|
|
Diags.Report(E->getExprLoc(), DiagID) << E->getStmtClassName()
|
|
|
|
<< E->getSourceRange();
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2014-03-31 00:30:54 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleTemplateArgs(
|
|
|
|
const TemplateDecl *TD, const TemplateArgumentList &TemplateArgs) {
|
2014-06-27 06:42:18 +08:00
|
|
|
// <template-args> ::= <template-arg>+
|
2014-08-06 06:43:45 +08:00
|
|
|
const TemplateParameterList *TPL = TD->getTemplateParameters();
|
|
|
|
assert(TPL->size() == TemplateArgs.size() &&
|
|
|
|
"size mismatch between args and parms!");
|
|
|
|
|
|
|
|
unsigned Idx = 0;
|
2014-03-31 00:30:54 +08:00
|
|
|
for (const TemplateArgument &TA : TemplateArgs.asArray())
|
2014-08-06 06:43:45 +08:00
|
|
|
mangleTemplateArg(TD, TA, TPL->getParam(Idx++));
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-07-03 02:10:07 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleTemplateArg(const TemplateDecl *TD,
|
2014-08-06 06:43:45 +08:00
|
|
|
const TemplateArgument &TA,
|
|
|
|
const NamedDecl *Parm) {
|
2014-02-06 01:27:08 +08:00
|
|
|
// <template-arg> ::= <type>
|
|
|
|
// ::= <integer-literal>
|
|
|
|
// ::= <member-data-pointer>
|
|
|
|
// ::= <member-function-pointer>
|
|
|
|
// ::= $E? <name> <type-encoding>
|
|
|
|
// ::= $1? <name> <type-encoding>
|
|
|
|
// ::= $0A@
|
|
|
|
// ::= <template-args>
|
|
|
|
|
2013-07-03 02:10:07 +08:00
|
|
|
switch (TA.getKind()) {
|
|
|
|
case TemplateArgument::Null:
|
|
|
|
llvm_unreachable("Can't mangle null template arguments!");
|
2013-08-27 16:21:25 +08:00
|
|
|
case TemplateArgument::TemplateExpansion:
|
|
|
|
llvm_unreachable("Can't mangle template expansion arguments!");
|
2013-07-03 02:10:07 +08:00
|
|
|
case TemplateArgument::Type: {
|
|
|
|
QualType T = TA.getAsType();
|
|
|
|
mangleType(T, SourceRange(), QMM_Escape);
|
|
|
|
break;
|
|
|
|
}
|
2013-08-13 09:25:35 +08:00
|
|
|
case TemplateArgument::Declaration: {
|
|
|
|
const NamedDecl *ND = cast<NamedDecl>(TA.getAsDecl());
|
2014-02-06 20:46:52 +08:00
|
|
|
if (isa<FieldDecl>(ND) || isa<IndirectFieldDecl>(ND)) {
|
2014-02-08 09:15:37 +08:00
|
|
|
mangleMemberDataPointer(
|
|
|
|
cast<CXXRecordDecl>(ND->getDeclContext())->getMostRecentDecl(),
|
|
|
|
cast<ValueDecl>(ND));
|
2014-02-06 02:59:38 +08:00
|
|
|
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
|
2014-02-06 07:53:29 +08:00
|
|
|
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD);
|
2015-05-18 08:05:25 +08:00
|
|
|
if (MD && MD->isInstance()) {
|
2014-02-08 09:15:37 +08:00
|
|
|
mangleMemberFunctionPointer(MD->getParent()->getMostRecentDecl(), MD);
|
2015-05-18 08:05:25 +08:00
|
|
|
} else {
|
|
|
|
Out << "$1?";
|
|
|
|
mangleName(FD);
|
|
|
|
mangleFunctionEncoding(FD, /*ShouldMangle=*/true);
|
|
|
|
}
|
2014-02-06 02:59:38 +08:00
|
|
|
} else {
|
2014-10-18 02:00:12 +08:00
|
|
|
mangle(ND, TA.getParamTypeForDecl()->isReferenceType() ? "$E?" : "$1?");
|
2014-02-06 02:59:38 +08:00
|
|
|
}
|
2013-07-03 02:10:07 +08:00
|
|
|
break;
|
2013-08-13 09:25:35 +08:00
|
|
|
}
|
2013-07-03 02:10:07 +08:00
|
|
|
case TemplateArgument::Integral:
|
|
|
|
mangleIntegerLiteral(TA.getAsIntegral(),
|
|
|
|
TA.getIntegralType()->isBooleanType());
|
|
|
|
break;
|
2014-02-06 01:27:08 +08:00
|
|
|
case TemplateArgument::NullPtr: {
|
|
|
|
QualType T = TA.getNullPtrType();
|
|
|
|
if (const MemberPointerType *MPT = T->getAs<MemberPointerType>()) {
|
2014-02-06 18:59:19 +08:00
|
|
|
const CXXRecordDecl *RD = MPT->getMostRecentCXXRecordDecl();
|
2015-12-02 03:13:51 +08:00
|
|
|
if (MPT->isMemberFunctionPointerType() &&
|
|
|
|
!isa<FunctionTemplateDecl>(TD)) {
|
2014-05-12 13:36:57 +08:00
|
|
|
mangleMemberFunctionPointer(RD, nullptr);
|
2014-06-11 15:08:37 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (MPT->isMemberDataPointer()) {
|
2015-12-02 03:13:51 +08:00
|
|
|
if (!isa<FunctionTemplateDecl>(TD)) {
|
2015-07-02 17:43:11 +08:00
|
|
|
mangleMemberDataPointer(RD, nullptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// nullptr data pointers are always represented with a single field
|
|
|
|
// which is initialized with either 0 or -1. Why -1? Well, we need to
|
|
|
|
// distinguish the case where the data member is at offset zero in the
|
|
|
|
// record.
|
|
|
|
// However, we are free to use 0 *if* we would use multiple fields for
|
|
|
|
// non-nullptr member pointers.
|
|
|
|
if (!RD->nullFieldOffsetIsZero()) {
|
|
|
|
mangleIntegerLiteral(llvm::APSInt::get(-1), /*IsBoolean=*/false);
|
|
|
|
return;
|
|
|
|
}
|
2014-06-11 15:08:37 +08:00
|
|
|
}
|
2014-02-06 01:27:08 +08:00
|
|
|
}
|
2015-07-02 17:43:11 +08:00
|
|
|
mangleIntegerLiteral(llvm::APSInt::getUnsigned(0), /*IsBoolean=*/false);
|
2013-08-06 05:33:59 +08:00
|
|
|
break;
|
2014-02-06 01:27:08 +08:00
|
|
|
}
|
2013-07-03 02:10:07 +08:00
|
|
|
case TemplateArgument::Expression:
|
|
|
|
mangleExpression(TA.getAsExpr());
|
|
|
|
break;
|
2014-06-05 00:46:32 +08:00
|
|
|
case TemplateArgument::Pack: {
|
2014-06-29 07:22:23 +08:00
|
|
|
ArrayRef<TemplateArgument> TemplateArgs = TA.getPackAsArray();
|
2014-06-05 00:46:32 +08:00
|
|
|
if (TemplateArgs.empty()) {
|
2014-08-06 06:43:45 +08:00
|
|
|
if (isa<TemplateTypeParmDecl>(Parm) ||
|
|
|
|
isa<TemplateTemplateParmDecl>(Parm))
|
2015-03-18 11:56:27 +08:00
|
|
|
// MSVC 2015 changed the mangling for empty expanded template packs,
|
|
|
|
// use the old mangling for link compatibility for old versions.
|
2015-05-11 11:57:49 +08:00
|
|
|
Out << (Context.getASTContext().getLangOpts().isCompatibleWithMSVC(
|
|
|
|
LangOptions::MSVC2015)
|
2015-03-18 11:56:27 +08:00
|
|
|
? "$$V"
|
|
|
|
: "$$$V");
|
2014-08-06 06:43:45 +08:00
|
|
|
else if (isa<NonTypeTemplateParmDecl>(Parm))
|
|
|
|
Out << "$S";
|
|
|
|
else
|
|
|
|
llvm_unreachable("unexpected template parameter decl!");
|
2014-06-05 00:46:32 +08:00
|
|
|
} else {
|
|
|
|
for (const TemplateArgument &PA : TemplateArgs)
|
2014-08-06 06:43:45 +08:00
|
|
|
mangleTemplateArg(TD, PA, Parm);
|
2014-06-05 00:46:32 +08:00
|
|
|
}
|
2013-07-03 02:10:07 +08:00
|
|
|
break;
|
2014-06-05 00:46:32 +08:00
|
|
|
}
|
2014-07-30 16:20:03 +08:00
|
|
|
case TemplateArgument::Template: {
|
|
|
|
const NamedDecl *ND =
|
|
|
|
TA.getAsTemplate().getAsTemplateDecl()->getTemplatedDecl();
|
|
|
|
if (const auto *TD = dyn_cast<TagDecl>(ND)) {
|
|
|
|
mangleType(TD);
|
|
|
|
} else if (isa<TypeAliasDecl>(ND)) {
|
2014-08-19 15:29:03 +08:00
|
|
|
Out << "$$Y";
|
|
|
|
mangleName(ND);
|
2014-07-30 16:20:03 +08:00
|
|
|
} else {
|
|
|
|
llvm_unreachable("unexpected template template NamedDecl!");
|
|
|
|
}
|
2013-08-06 06:26:46 +08:00
|
|
|
break;
|
2013-07-03 02:10:07 +08:00
|
|
|
}
|
2014-07-30 16:20:03 +08:00
|
|
|
}
|
2013-07-03 02:10:07 +08:00
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleQualifiers(Qualifiers Quals,
|
|
|
|
bool IsMember) {
|
|
|
|
// <cvr-qualifiers> ::= [E] [F] [I] <base-cvr-qualifiers>
|
|
|
|
// 'E' means __ptr64 (32-bit only); 'F' means __unaligned (32/64-bit only);
|
|
|
|
// 'I' means __restrict (32/64-bit).
|
|
|
|
// Note that the MSVC __restrict keyword isn't the same as the C99 restrict
|
|
|
|
// keyword!
|
|
|
|
// <base-cvr-qualifiers> ::= A # near
|
|
|
|
// ::= B # near const
|
|
|
|
// ::= C # near volatile
|
|
|
|
// ::= D # near const volatile
|
|
|
|
// ::= E # far (16-bit)
|
|
|
|
// ::= F # far const (16-bit)
|
|
|
|
// ::= G # far volatile (16-bit)
|
|
|
|
// ::= H # far const volatile (16-bit)
|
|
|
|
// ::= I # huge (16-bit)
|
|
|
|
// ::= J # huge const (16-bit)
|
|
|
|
// ::= K # huge volatile (16-bit)
|
|
|
|
// ::= L # huge const volatile (16-bit)
|
|
|
|
// ::= M <basis> # based
|
|
|
|
// ::= N <basis> # based const
|
|
|
|
// ::= O <basis> # based volatile
|
|
|
|
// ::= P <basis> # based const volatile
|
|
|
|
// ::= Q # near member
|
|
|
|
// ::= R # near const member
|
|
|
|
// ::= S # near volatile member
|
|
|
|
// ::= T # near const volatile member
|
|
|
|
// ::= U # far member (16-bit)
|
|
|
|
// ::= V # far const member (16-bit)
|
|
|
|
// ::= W # far volatile member (16-bit)
|
|
|
|
// ::= X # far const volatile member (16-bit)
|
|
|
|
// ::= Y # huge member (16-bit)
|
|
|
|
// ::= Z # huge const member (16-bit)
|
|
|
|
// ::= 0 # huge volatile member (16-bit)
|
|
|
|
// ::= 1 # huge const volatile member (16-bit)
|
|
|
|
// ::= 2 <basis> # based member
|
|
|
|
// ::= 3 <basis> # based const member
|
|
|
|
// ::= 4 <basis> # based volatile member
|
|
|
|
// ::= 5 <basis> # based const volatile member
|
|
|
|
// ::= 6 # near function (pointers only)
|
|
|
|
// ::= 7 # far function (pointers only)
|
|
|
|
// ::= 8 # near method (pointers only)
|
|
|
|
// ::= 9 # far method (pointers only)
|
|
|
|
// ::= _A <basis> # based function (pointers only)
|
|
|
|
// ::= _B <basis> # based function (far?) (pointers only)
|
|
|
|
// ::= _C <basis> # based method (pointers only)
|
|
|
|
// ::= _D <basis> # based method (far?) (pointers only)
|
|
|
|
// ::= _E # block (Clang)
|
|
|
|
// <basis> ::= 0 # __based(void)
|
|
|
|
// ::= 1 # __based(segment)?
|
|
|
|
// ::= 2 <name> # __based(name)
|
|
|
|
// ::= 3 # ?
|
|
|
|
// ::= 4 # ?
|
|
|
|
// ::= 5 # not really based
|
|
|
|
bool HasConst = Quals.hasConst(),
|
|
|
|
HasVolatile = Quals.hasVolatile();
|
2013-08-06 06:43:06 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (!IsMember) {
|
|
|
|
if (HasConst && HasVolatile) {
|
|
|
|
Out << 'D';
|
|
|
|
} else if (HasVolatile) {
|
|
|
|
Out << 'C';
|
|
|
|
} else if (HasConst) {
|
|
|
|
Out << 'B';
|
|
|
|
} else {
|
|
|
|
Out << 'A';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (HasConst && HasVolatile) {
|
|
|
|
Out << 'T';
|
|
|
|
} else if (HasVolatile) {
|
|
|
|
Out << 'S';
|
|
|
|
} else if (HasConst) {
|
|
|
|
Out << 'R';
|
|
|
|
} else {
|
|
|
|
Out << 'Q';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: For now, just drop all extension qualifiers on the floor.
|
|
|
|
}
|
|
|
|
|
2014-04-23 13:16:56 +08:00
|
|
|
void
|
|
|
|
MicrosoftCXXNameMangler::mangleRefQualifier(RefQualifierKind RefQualifier) {
|
|
|
|
// <ref-qualifier> ::= G # lvalue reference
|
|
|
|
// ::= H # rvalue-reference
|
|
|
|
switch (RefQualifier) {
|
|
|
|
case RQ_None:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RQ_LValue:
|
|
|
|
Out << 'G';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RQ_RValue:
|
|
|
|
Out << 'H';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::manglePointerExtQualifiers(Qualifiers Quals,
|
|
|
|
QualType PointeeType) {
|
2014-02-18 22:20:10 +08:00
|
|
|
bool HasRestrict = Quals.hasRestrict();
|
2015-05-26 09:30:45 +08:00
|
|
|
if (PointersAre64Bit &&
|
|
|
|
(PointeeType.isNull() || !PointeeType->isFunctionType()))
|
2014-02-18 22:20:10 +08:00
|
|
|
Out << 'E';
|
|
|
|
|
|
|
|
if (HasRestrict)
|
|
|
|
Out << 'I';
|
2016-05-12 02:38:21 +08:00
|
|
|
|
2016-05-26 18:06:01 +08:00
|
|
|
if (Quals.hasUnaligned() ||
|
|
|
|
(!PointeeType.isNull() && PointeeType.getLocalQualifiers().hasUnaligned()))
|
2016-05-12 02:38:21 +08:00
|
|
|
Out << 'F';
|
2014-02-18 22:20:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftCXXNameMangler::manglePointerCVQualifiers(Qualifiers Quals) {
|
|
|
|
// <pointer-cv-qualifiers> ::= P # no qualifiers
|
|
|
|
// ::= Q # const
|
|
|
|
// ::= R # volatile
|
|
|
|
// ::= S # const volatile
|
2012-12-18 22:30:41 +08:00
|
|
|
bool HasConst = Quals.hasConst(),
|
2014-02-18 22:20:10 +08:00
|
|
|
HasVolatile = Quals.hasVolatile();
|
2014-02-18 20:58:35 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
if (HasConst && HasVolatile) {
|
|
|
|
Out << 'S';
|
|
|
|
} else if (HasVolatile) {
|
|
|
|
Out << 'R';
|
|
|
|
} else if (HasConst) {
|
|
|
|
Out << 'Q';
|
|
|
|
} else {
|
|
|
|
Out << 'P';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftCXXNameMangler::mangleArgumentType(QualType T,
|
|
|
|
SourceRange Range) {
|
2013-06-25 03:21:52 +08:00
|
|
|
// MSVC will backreference two canonically equivalent types that have slightly
|
|
|
|
// different manglings when mangled alone.
|
2013-09-11 12:44:30 +08:00
|
|
|
|
|
|
|
// Decayed types do not match up with non-decayed versions of the same type.
|
|
|
|
//
|
|
|
|
// e.g.
|
|
|
|
// void (*x)(void) will not form a backreference with void x(void)
|
|
|
|
void *TypePtr;
|
2015-04-23 13:21:20 +08:00
|
|
|
if (const auto *DT = T->getAs<DecayedType>()) {
|
|
|
|
QualType OriginalType = DT->getOriginalType();
|
2015-04-27 11:07:47 +08:00
|
|
|
// All decayed ArrayTypes should be treated identically; as-if they were
|
|
|
|
// a decayed IncompleteArrayType.
|
|
|
|
if (const auto *AT = getASTContext().getAsArrayType(OriginalType))
|
2015-04-23 13:21:20 +08:00
|
|
|
OriginalType = getASTContext().getIncompleteArrayType(
|
2015-04-27 11:07:47 +08:00
|
|
|
AT->getElementType(), AT->getSizeModifier(),
|
|
|
|
AT->getIndexTypeCVRQualifiers());
|
2015-04-23 13:21:20 +08:00
|
|
|
|
|
|
|
TypePtr = OriginalType.getCanonicalType().getAsOpaquePtr();
|
2013-09-11 12:44:30 +08:00
|
|
|
// If the original parameter was textually written as an array,
|
|
|
|
// instead treat the decayed parameter like it's const.
|
|
|
|
//
|
|
|
|
// e.g.
|
|
|
|
// int [] -> int * const
|
2015-04-23 13:21:20 +08:00
|
|
|
if (OriginalType->isArrayType())
|
2013-09-11 12:44:30 +08:00
|
|
|
T = T.withConst();
|
2015-04-23 13:21:20 +08:00
|
|
|
} else {
|
2013-09-11 12:44:30 +08:00
|
|
|
TypePtr = T.getCanonicalType().getAsOpaquePtr();
|
2015-04-23 13:21:20 +08:00
|
|
|
}
|
2013-09-11 12:44:30 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
ArgBackRefMap::iterator Found = TypeBackReferences.find(TypePtr);
|
|
|
|
|
|
|
|
if (Found == TypeBackReferences.end()) {
|
2015-05-02 23:31:08 +08:00
|
|
|
size_t OutSizeBefore = Out.tell();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-09-11 12:44:30 +08:00
|
|
|
mangleType(T, Range, QMM_Drop);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// See if it's worth creating a back reference.
|
|
|
|
// Only types longer than 1 character are considered
|
|
|
|
// and only 10 back references slots are available:
|
2015-05-02 23:31:08 +08:00
|
|
|
bool LongerThanOneChar = (Out.tell() - OutSizeBefore > 1);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (LongerThanOneChar && TypeBackReferences.size() < 10) {
|
|
|
|
size_t Size = TypeBackReferences.size();
|
|
|
|
TypeBackReferences[TypePtr] = Size;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Out << Found->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-30 13:13:03 +08:00
|
|
|
void MicrosoftCXXNameMangler::manglePassObjectSizeArg(
|
|
|
|
const PassObjectSizeAttr *POSA) {
|
|
|
|
int Type = POSA->getType();
|
|
|
|
|
|
|
|
auto Iter = PassObjectSizeArgs.insert(Type).first;
|
2015-12-31 13:36:52 +08:00
|
|
|
auto *TypePtr = (const void *)&*Iter;
|
2015-12-30 13:13:03 +08:00
|
|
|
ArgBackRefMap::iterator Found = TypeBackReferences.find(TypePtr);
|
|
|
|
|
|
|
|
if (Found == TypeBackReferences.end()) {
|
|
|
|
mangleArtificalTagType(TTK_Enum, "__pass_object_size" + llvm::utostr(Type),
|
|
|
|
{"__clang"});
|
|
|
|
|
|
|
|
if (TypeBackReferences.size() < 10) {
|
|
|
|
size_t Size = TypeBackReferences.size();
|
|
|
|
TypeBackReferences[TypePtr] = Size;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Out << Found->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(QualType T, SourceRange Range,
|
2013-04-25 12:25:40 +08:00
|
|
|
QualifierMangleMode QMM) {
|
2013-06-25 03:21:52 +08:00
|
|
|
// Don't use the canonical types. MSVC includes things like 'const' on
|
|
|
|
// pointer arguments to function pointers that canonicalization strips away.
|
|
|
|
T = T.getDesugaredType(getASTContext());
|
2012-12-18 22:30:41 +08:00
|
|
|
Qualifiers Quals = T.getLocalQualifiers();
|
2013-06-25 03:21:52 +08:00
|
|
|
if (const ArrayType *AT = getASTContext().getAsArrayType(T)) {
|
|
|
|
// If there were any Quals, getAsArrayType() pushed them onto the array
|
|
|
|
// element type.
|
2013-04-25 12:25:40 +08:00
|
|
|
if (QMM == QMM_Mangle)
|
|
|
|
Out << 'A';
|
|
|
|
else if (QMM == QMM_Escape || QMM == QMM_Result)
|
|
|
|
Out << "$$B";
|
2013-06-25 03:21:52 +08:00
|
|
|
mangleArrayType(AT);
|
2013-04-25 12:25:40 +08:00
|
|
|
return;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-04-25 12:25:40 +08:00
|
|
|
bool IsPointer = T->isAnyPointerType() || T->isMemberPointerType() ||
|
2015-05-26 09:30:45 +08:00
|
|
|
T->isReferenceType() || T->isBlockPointerType();
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-04-25 12:25:40 +08:00
|
|
|
switch (QMM) {
|
|
|
|
case QMM_Drop:
|
|
|
|
break;
|
|
|
|
case QMM_Mangle:
|
|
|
|
if (const FunctionType *FT = dyn_cast<FunctionType>(T)) {
|
|
|
|
Out << '6';
|
2013-10-04 19:25:05 +08:00
|
|
|
mangleFunctionType(FT);
|
2013-04-25 12:25:40 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
mangleQualifiers(Quals, false);
|
|
|
|
break;
|
|
|
|
case QMM_Escape:
|
|
|
|
if (!IsPointer && Quals) {
|
|
|
|
Out << "$$C";
|
|
|
|
mangleQualifiers(Quals, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case QMM_Result:
|
2016-05-12 02:38:21 +08:00
|
|
|
// Presence of __unaligned qualifier shouldn't affect mangling here.
|
|
|
|
Quals.removeUnaligned();
|
2013-04-25 12:25:40 +08:00
|
|
|
if ((!IsPointer && Quals) || isa<TagType>(T)) {
|
|
|
|
Out << '?';
|
|
|
|
mangleQualifiers(Quals, false);
|
|
|
|
}
|
|
|
|
break;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-04-25 12:25:40 +08:00
|
|
|
const Type *ty = T.getTypePtr();
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
switch (ty->getTypeClass()) {
|
|
|
|
#define ABSTRACT_TYPE(CLASS, PARENT)
|
|
|
|
#define NON_CANONICAL_TYPE(CLASS, PARENT) \
|
|
|
|
case Type::CLASS: \
|
|
|
|
llvm_unreachable("can't mangle non-canonical type " #CLASS "Type"); \
|
|
|
|
return;
|
|
|
|
#define TYPE(CLASS, PARENT) \
|
|
|
|
case Type::CLASS: \
|
2015-05-26 09:30:45 +08:00
|
|
|
mangleType(cast<CLASS##Type>(ty), Quals, Range); \
|
2012-12-18 22:30:41 +08:00
|
|
|
break;
|
|
|
|
#include "clang/AST/TypeNodes.def"
|
|
|
|
#undef ABSTRACT_TYPE
|
|
|
|
#undef NON_CANONICAL_TYPE
|
|
|
|
#undef TYPE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const BuiltinType *T, Qualifiers,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange Range) {
|
|
|
|
// <type> ::= <builtin-type>
|
|
|
|
// <builtin-type> ::= X # void
|
|
|
|
// ::= C # signed char
|
|
|
|
// ::= D # char
|
|
|
|
// ::= E # unsigned char
|
|
|
|
// ::= F # short
|
|
|
|
// ::= G # unsigned short (or wchar_t if it's not a builtin)
|
|
|
|
// ::= H # int
|
|
|
|
// ::= I # unsigned int
|
|
|
|
// ::= J # long
|
|
|
|
// ::= K # unsigned long
|
|
|
|
// L # <none>
|
|
|
|
// ::= M # float
|
|
|
|
// ::= N # double
|
|
|
|
// ::= O # long double (__float80 is mangled differently)
|
|
|
|
// ::= _J # long long, __int64
|
|
|
|
// ::= _K # unsigned long long, __int64
|
|
|
|
// ::= _L # __int128
|
|
|
|
// ::= _M # unsigned __int128
|
|
|
|
// ::= _N # bool
|
|
|
|
// _O # <array in parameter>
|
|
|
|
// ::= _T # __float80 (Intel)
|
|
|
|
// ::= _W # wchar_t
|
|
|
|
// ::= _Z # __float80 (Digital Mars)
|
|
|
|
switch (T->getKind()) {
|
2015-09-15 20:18:29 +08:00
|
|
|
case BuiltinType::Void:
|
|
|
|
Out << 'X';
|
|
|
|
break;
|
|
|
|
case BuiltinType::SChar:
|
|
|
|
Out << 'C';
|
|
|
|
break;
|
|
|
|
case BuiltinType::Char_U:
|
|
|
|
case BuiltinType::Char_S:
|
|
|
|
Out << 'D';
|
|
|
|
break;
|
|
|
|
case BuiltinType::UChar:
|
|
|
|
Out << 'E';
|
|
|
|
break;
|
|
|
|
case BuiltinType::Short:
|
|
|
|
Out << 'F';
|
|
|
|
break;
|
|
|
|
case BuiltinType::UShort:
|
|
|
|
Out << 'G';
|
|
|
|
break;
|
|
|
|
case BuiltinType::Int:
|
|
|
|
Out << 'H';
|
|
|
|
break;
|
|
|
|
case BuiltinType::UInt:
|
|
|
|
Out << 'I';
|
|
|
|
break;
|
|
|
|
case BuiltinType::Long:
|
|
|
|
Out << 'J';
|
|
|
|
break;
|
|
|
|
case BuiltinType::ULong:
|
|
|
|
Out << 'K';
|
|
|
|
break;
|
|
|
|
case BuiltinType::Float:
|
|
|
|
Out << 'M';
|
|
|
|
break;
|
|
|
|
case BuiltinType::Double:
|
|
|
|
Out << 'N';
|
|
|
|
break;
|
2012-12-18 22:30:41 +08:00
|
|
|
// TODO: Determine size and mangle accordingly
|
2015-09-15 20:18:29 +08:00
|
|
|
case BuiltinType::LongDouble:
|
|
|
|
Out << 'O';
|
|
|
|
break;
|
|
|
|
case BuiltinType::LongLong:
|
|
|
|
Out << "_J";
|
|
|
|
break;
|
|
|
|
case BuiltinType::ULongLong:
|
|
|
|
Out << "_K";
|
|
|
|
break;
|
|
|
|
case BuiltinType::Int128:
|
|
|
|
Out << "_L";
|
|
|
|
break;
|
|
|
|
case BuiltinType::UInt128:
|
|
|
|
Out << "_M";
|
|
|
|
break;
|
|
|
|
case BuiltinType::Bool:
|
|
|
|
Out << "_N";
|
|
|
|
break;
|
|
|
|
case BuiltinType::Char16:
|
|
|
|
Out << "_S";
|
|
|
|
break;
|
|
|
|
case BuiltinType::Char32:
|
|
|
|
Out << "_U";
|
|
|
|
break;
|
2012-12-18 22:30:41 +08:00
|
|
|
case BuiltinType::WChar_S:
|
2015-09-15 20:18:29 +08:00
|
|
|
case BuiltinType::WChar_U:
|
|
|
|
Out << "_W";
|
|
|
|
break;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
#define BUILTIN_TYPE(Id, SingletonId)
|
|
|
|
#define PLACEHOLDER_TYPE(Id, SingletonId) \
|
|
|
|
case BuiltinType::Id:
|
|
|
|
#include "clang/AST/BuiltinTypes.def"
|
|
|
|
case BuiltinType::Dependent:
|
|
|
|
llvm_unreachable("placeholder types shouldn't get to name mangling");
|
|
|
|
|
2015-09-15 20:18:29 +08:00
|
|
|
case BuiltinType::ObjCId:
|
2015-12-29 19:45:53 +08:00
|
|
|
Out << "PA";
|
|
|
|
mangleArtificalTagType(TTK_Struct, "objc_object");
|
2015-09-15 20:18:29 +08:00
|
|
|
break;
|
|
|
|
case BuiltinType::ObjCClass:
|
2015-12-29 19:45:53 +08:00
|
|
|
Out << "PA";
|
|
|
|
mangleArtificalTagType(TTK_Struct, "objc_class");
|
2015-09-15 20:18:29 +08:00
|
|
|
break;
|
|
|
|
case BuiltinType::ObjCSel:
|
2015-12-29 19:45:53 +08:00
|
|
|
Out << "PA";
|
|
|
|
mangleArtificalTagType(TTK_Struct, "objc_selector");
|
2015-09-15 20:18:29 +08:00
|
|
|
break;
|
2012-12-18 22:38:23 +08:00
|
|
|
|
2016-04-08 21:40:33 +08:00
|
|
|
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
|
|
|
|
case BuiltinType::Id: \
|
|
|
|
Out << "PAUocl_" #ImgType "_" #Suffix "@@"; \
|
2015-09-15 20:18:29 +08:00
|
|
|
break;
|
2016-04-13 16:33:41 +08:00
|
|
|
#include "clang/Basic/OpenCLImageTypes.def"
|
2015-09-15 20:18:29 +08:00
|
|
|
case BuiltinType::OCLSampler:
|
2015-12-29 19:45:53 +08:00
|
|
|
Out << "PA";
|
|
|
|
mangleArtificalTagType(TTK_Struct, "ocl_sampler");
|
2015-09-15 20:18:29 +08:00
|
|
|
break;
|
|
|
|
case BuiltinType::OCLEvent:
|
2015-12-29 19:45:53 +08:00
|
|
|
Out << "PA";
|
|
|
|
mangleArtificalTagType(TTK_Struct, "ocl_event");
|
2015-09-15 20:18:29 +08:00
|
|
|
break;
|
2015-09-15 19:18:52 +08:00
|
|
|
case BuiltinType::OCLClkEvent:
|
2015-12-29 19:45:53 +08:00
|
|
|
Out << "PA";
|
|
|
|
mangleArtificalTagType(TTK_Struct, "ocl_clkevent");
|
2015-09-15 19:18:52 +08:00
|
|
|
break;
|
|
|
|
case BuiltinType::OCLQueue:
|
2015-12-29 19:45:53 +08:00
|
|
|
Out << "PA";
|
|
|
|
mangleArtificalTagType(TTK_Struct, "ocl_queue");
|
2015-09-15 19:18:52 +08:00
|
|
|
break;
|
|
|
|
case BuiltinType::OCLNDRange:
|
2015-12-29 19:45:53 +08:00
|
|
|
Out << "PA";
|
|
|
|
mangleArtificalTagType(TTK_Struct, "ocl_ndrange");
|
2015-09-15 19:18:52 +08:00
|
|
|
break;
|
|
|
|
case BuiltinType::OCLReserveID:
|
2015-12-29 19:45:53 +08:00
|
|
|
Out << "PA";
|
|
|
|
mangleArtificalTagType(TTK_Struct, "ocl_reserveid");
|
2015-09-15 19:18:52 +08:00
|
|
|
break;
|
2013-12-13 09:06:04 +08:00
|
|
|
|
2015-09-15 20:18:29 +08:00
|
|
|
case BuiltinType::NullPtr:
|
|
|
|
Out << "$$T";
|
|
|
|
break;
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2016-05-09 16:52:33 +08:00
|
|
|
case BuiltinType::Float128:
|
2012-12-18 22:30:41 +08:00
|
|
|
case BuiltinType::Half: {
|
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
2015-09-15 20:18:29 +08:00
|
|
|
unsigned DiagID = Diags.getCustomDiagID(
|
|
|
|
DiagnosticsEngine::Error, "cannot mangle this built-in %0 type yet");
|
2012-12-18 22:30:41 +08:00
|
|
|
Diags.Report(Range.getBegin(), DiagID)
|
2015-09-15 20:18:29 +08:00
|
|
|
<< T->getName(Context.getASTContext().getPrintingPolicy()) << Range;
|
2012-12-18 22:30:41 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// <type> ::= <function-type>
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const FunctionProtoType *T, Qualifiers,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange) {
|
|
|
|
// Structors only appear in decls, so at this point we know it's not a
|
|
|
|
// structor type.
|
|
|
|
// FIXME: This may not be lambda-friendly.
|
2014-08-13 01:53:10 +08:00
|
|
|
if (T->getTypeQuals() || T->getRefQualifier() != RQ_None) {
|
|
|
|
Out << "$$A8@@";
|
|
|
|
mangleFunctionType(T, /*D=*/nullptr, /*ForceThisQuals=*/true);
|
|
|
|
} else {
|
|
|
|
Out << "$$A6";
|
|
|
|
mangleFunctionType(T);
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
void MicrosoftCXXNameMangler::mangleType(const FunctionNoProtoType *T,
|
2015-05-26 09:30:45 +08:00
|
|
|
Qualifiers, SourceRange) {
|
2015-08-08 07:25:47 +08:00
|
|
|
Out << "$$A6";
|
|
|
|
mangleFunctionType(T);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-04-25 12:25:40 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T,
|
|
|
|
const FunctionDecl *D,
|
2014-08-13 01:53:10 +08:00
|
|
|
bool ForceThisQuals) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// <function-type> ::= <this-cvr-qualifiers> <calling-convention>
|
|
|
|
// <return-type> <argument-list> <throw-spec>
|
2015-08-08 07:25:47 +08:00
|
|
|
const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(T);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2013-06-25 03:21:52 +08:00
|
|
|
SourceRange Range;
|
|
|
|
if (D) Range = D->getSourceRange();
|
|
|
|
|
2016-01-17 15:09:24 +08:00
|
|
|
bool IsInLambda = false;
|
2015-03-12 02:36:39 +08:00
|
|
|
bool IsStructor = false, HasThisQuals = ForceThisQuals, IsCtorClosure = false;
|
|
|
|
CallingConv CC = T->getCallConv();
|
2013-10-04 19:25:05 +08:00
|
|
|
if (const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(D)) {
|
2016-01-17 15:09:24 +08:00
|
|
|
if (MD->getParent()->isLambda())
|
|
|
|
IsInLambda = true;
|
2013-10-04 19:25:05 +08:00
|
|
|
if (MD->isInstance())
|
2014-08-13 01:53:10 +08:00
|
|
|
HasThisQuals = true;
|
2015-03-12 02:36:39 +08:00
|
|
|
if (isa<CXXDestructorDecl>(MD)) {
|
|
|
|
IsStructor = true;
|
|
|
|
} else if (isa<CXXConstructorDecl>(MD)) {
|
2013-10-04 19:25:05 +08:00
|
|
|
IsStructor = true;
|
2015-03-12 02:36:39 +08:00
|
|
|
IsCtorClosure = (StructorType == Ctor_CopyingClosure ||
|
|
|
|
StructorType == Ctor_DefaultClosure) &&
|
2017-01-10 01:04:37 +08:00
|
|
|
isStructorDecl(MD);
|
2015-03-12 02:36:39 +08:00
|
|
|
if (IsCtorClosure)
|
|
|
|
CC = getASTContext().getDefaultCallingConvention(
|
|
|
|
/*IsVariadic=*/false, /*IsCXXMethod=*/true);
|
|
|
|
}
|
2013-10-04 19:25:05 +08:00
|
|
|
}
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
// If this is a C++ instance method, mangle the CVR qualifiers for the
|
|
|
|
// this pointer.
|
2014-08-13 01:53:10 +08:00
|
|
|
if (HasThisQuals) {
|
2016-05-26 18:06:01 +08:00
|
|
|
Qualifiers Quals = Qualifiers::fromCVRUMask(Proto->getTypeQuals());
|
2015-05-26 09:30:45 +08:00
|
|
|
manglePointerExtQualifiers(Quals, /*PointeeType=*/QualType());
|
2014-04-23 13:16:56 +08:00
|
|
|
mangleRefQualifier(Proto->getRefQualifier());
|
2014-08-13 01:53:10 +08:00
|
|
|
mangleQualifiers(Quals, /*IsMember=*/false);
|
2013-08-15 16:13:23 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
2015-03-12 02:36:39 +08:00
|
|
|
mangleCallingConvention(CC);
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// <return-type> ::= <type>
|
|
|
|
// ::= @ # structors (they have no declared return type)
|
2013-02-13 16:37:51 +08:00
|
|
|
if (IsStructor) {
|
2017-01-10 01:04:37 +08:00
|
|
|
if (isa<CXXDestructorDecl>(D) && isStructorDecl(D) &&
|
2013-02-13 16:37:51 +08:00
|
|
|
StructorType == Dtor_Deleting) {
|
|
|
|
// The scalar deleting destructor takes an extra int argument.
|
|
|
|
// However, the FunctionType generated has 0 arguments.
|
|
|
|
// FIXME: This is a temporary hack.
|
|
|
|
// Maybe should fix the FunctionType creation instead?
|
2013-08-26 18:32:04 +08:00
|
|
|
Out << (PointersAre64Bit ? "PEAXI@Z" : "PAXI@Z");
|
2013-02-13 16:37:51 +08:00
|
|
|
return;
|
|
|
|
}
|
2015-03-12 02:36:39 +08:00
|
|
|
if (IsCtorClosure) {
|
|
|
|
// Default constructor closure and copy constructor closure both return
|
|
|
|
// void.
|
|
|
|
Out << 'X';
|
|
|
|
|
|
|
|
if (StructorType == Ctor_DefaultClosure) {
|
|
|
|
// Default constructor closure always has no arguments.
|
|
|
|
Out << 'X';
|
|
|
|
} else if (StructorType == Ctor_CopyingClosure) {
|
|
|
|
// Copy constructor closure always takes an unqualified reference.
|
|
|
|
mangleArgumentType(getASTContext().getLValueReferenceType(
|
|
|
|
Proto->getParamType(0)
|
|
|
|
->getAs<LValueReferenceType>()
|
|
|
|
->getPointeeType(),
|
|
|
|
/*SpelledAsLValue=*/true),
|
|
|
|
Range);
|
2015-03-14 06:36:55 +08:00
|
|
|
Out << '@';
|
2015-03-12 02:36:39 +08:00
|
|
|
} else {
|
|
|
|
llvm_unreachable("unexpected constructor closure!");
|
|
|
|
}
|
2015-03-14 06:36:55 +08:00
|
|
|
Out << 'Z';
|
2015-03-12 02:36:39 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
Out << '@';
|
2013-02-13 16:37:51 +08:00
|
|
|
} else {
|
2015-08-08 07:25:47 +08:00
|
|
|
QualType ResultType = T->getReturnType();
|
2014-04-01 13:29:46 +08:00
|
|
|
if (const auto *AT =
|
|
|
|
dyn_cast_or_null<AutoType>(ResultType->getContainedAutoType())) {
|
|
|
|
Out << '?';
|
|
|
|
mangleQualifiers(ResultType.getLocalQualifiers(), /*IsMember=*/false);
|
|
|
|
Out << '?';
|
2015-11-11 10:02:15 +08:00
|
|
|
assert(AT->getKeyword() != AutoTypeKeyword::GNUAutoType &&
|
|
|
|
"shouldn't need to mangle __auto_type!");
|
2014-04-01 13:29:46 +08:00
|
|
|
mangleSourceName(AT->isDecltypeAuto() ? "<decltype-auto>" : "<auto>");
|
|
|
|
Out << '@';
|
2016-01-17 15:09:24 +08:00
|
|
|
} else if (IsInLambda) {
|
|
|
|
Out << '@';
|
2014-04-01 13:29:46 +08:00
|
|
|
} else {
|
|
|
|
if (ResultType->isVoidType())
|
|
|
|
ResultType = ResultType.getUnqualifiedType();
|
|
|
|
mangleType(ResultType, Range, QMM_Result);
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// <argument-list> ::= X # void
|
|
|
|
// ::= <type>+ @
|
|
|
|
// ::= <type>* Z # varargs
|
2015-08-08 07:25:47 +08:00
|
|
|
if (!Proto) {
|
|
|
|
// Function types without prototypes can arise when mangling a function type
|
|
|
|
// within an overloadable function in C. We mangle these as the absence of
|
|
|
|
// any parameter types (not even an empty parameter list).
|
|
|
|
Out << '@';
|
|
|
|
} else if (Proto->getNumParams() == 0 && !Proto->isVariadic()) {
|
2012-12-18 22:30:41 +08:00
|
|
|
Out << 'X';
|
|
|
|
} else {
|
2013-06-25 03:21:52 +08:00
|
|
|
// Happens for function pointer type arguments for example.
|
2015-12-03 05:58:08 +08:00
|
|
|
for (unsigned I = 0, E = Proto->getNumParams(); I != E; ++I) {
|
|
|
|
mangleArgumentType(Proto->getParamType(I), Range);
|
|
|
|
// Mangle each pass_object_size parameter as if it's a paramater of enum
|
|
|
|
// type passed directly after the parameter with the pass_object_size
|
|
|
|
// attribute. The aforementioned enum's name is __pass_object_size, and we
|
|
|
|
// pretend it resides in a top-level namespace called __clang.
|
|
|
|
//
|
|
|
|
// FIXME: Is there a defined extension notation for the MS ABI, or is it
|
|
|
|
// necessary to just cross our fingers and hope this type+namespace
|
|
|
|
// combination doesn't conflict with anything?
|
|
|
|
if (D)
|
2015-12-30 13:13:03 +08:00
|
|
|
if (const auto *P = D->getParamDecl(I)->getAttr<PassObjectSizeAttr>())
|
|
|
|
manglePassObjectSizeArg(P);
|
2015-12-03 05:58:08 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
// <builtin-type> ::= Z # ellipsis
|
|
|
|
if (Proto->isVariadic())
|
|
|
|
Out << 'Z';
|
|
|
|
else
|
|
|
|
Out << '@';
|
|
|
|
}
|
|
|
|
|
|
|
|
mangleThrowSpecification(Proto);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftCXXNameMangler::mangleFunctionClass(const FunctionDecl *FD) {
|
2013-05-15 04:30:42 +08:00
|
|
|
// <function-class> ::= <member-function> E? # E designates a 64-bit 'this'
|
|
|
|
// # pointer. in 64-bit mode *all*
|
|
|
|
// # 'this' pointers are 64-bit.
|
|
|
|
// ::= <global-function>
|
|
|
|
// <member-function> ::= A # private: near
|
|
|
|
// ::= B # private: far
|
|
|
|
// ::= C # private: static near
|
|
|
|
// ::= D # private: static far
|
|
|
|
// ::= E # private: virtual near
|
|
|
|
// ::= F # private: virtual far
|
|
|
|
// ::= I # protected: near
|
|
|
|
// ::= J # protected: far
|
|
|
|
// ::= K # protected: static near
|
|
|
|
// ::= L # protected: static far
|
|
|
|
// ::= M # protected: virtual near
|
|
|
|
// ::= N # protected: virtual far
|
|
|
|
// ::= Q # public: near
|
|
|
|
// ::= R # public: far
|
|
|
|
// ::= S # public: static near
|
|
|
|
// ::= T # public: static far
|
|
|
|
// ::= U # public: virtual near
|
|
|
|
// ::= V # public: virtual far
|
|
|
|
// <global-function> ::= Y # global near
|
|
|
|
// ::= Z # global far
|
2012-12-18 22:30:41 +08:00
|
|
|
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD)) {
|
|
|
|
switch (MD->getAccess()) {
|
2013-10-09 17:23:58 +08:00
|
|
|
case AS_none:
|
|
|
|
llvm_unreachable("Unsupported access specifier");
|
2012-12-18 22:30:41 +08:00
|
|
|
case AS_private:
|
|
|
|
if (MD->isStatic())
|
|
|
|
Out << 'C';
|
|
|
|
else if (MD->isVirtual())
|
|
|
|
Out << 'E';
|
|
|
|
else
|
|
|
|
Out << 'A';
|
|
|
|
break;
|
|
|
|
case AS_protected:
|
|
|
|
if (MD->isStatic())
|
|
|
|
Out << 'K';
|
|
|
|
else if (MD->isVirtual())
|
|
|
|
Out << 'M';
|
|
|
|
else
|
|
|
|
Out << 'I';
|
|
|
|
break;
|
|
|
|
case AS_public:
|
|
|
|
if (MD->isStatic())
|
|
|
|
Out << 'S';
|
|
|
|
else if (MD->isVirtual())
|
|
|
|
Out << 'U';
|
|
|
|
else
|
|
|
|
Out << 'Q';
|
|
|
|
}
|
2015-05-18 08:05:29 +08:00
|
|
|
} else {
|
2012-12-18 22:30:41 +08:00
|
|
|
Out << 'Y';
|
2015-05-18 08:05:29 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2015-03-12 02:36:39 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleCallingConvention(CallingConv CC) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// <calling-convention> ::= A # __cdecl
|
|
|
|
// ::= B # __export __cdecl
|
|
|
|
// ::= C # __pascal
|
|
|
|
// ::= D # __export __pascal
|
|
|
|
// ::= E # __thiscall
|
|
|
|
// ::= F # __export __thiscall
|
|
|
|
// ::= G # __stdcall
|
|
|
|
// ::= H # __export __stdcall
|
|
|
|
// ::= I # __fastcall
|
|
|
|
// ::= J # __export __fastcall
|
2014-10-25 01:42:17 +08:00
|
|
|
// ::= Q # __vectorcall
|
2016-11-03 02:29:35 +08:00
|
|
|
// ::= w # __regcall
|
2012-12-18 22:30:41 +08:00
|
|
|
// The 'export' calling conventions are from a bygone era
|
|
|
|
// (*cough*Win16*cough*) when functions were declared for export with
|
|
|
|
// that keyword. (It didn't actually export them, it just made them so
|
|
|
|
// that they could be in a DLL and somebody from another module could call
|
|
|
|
// them.)
|
2015-03-12 02:36:39 +08:00
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
switch (CC) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unsupported CC for mangling");
|
2013-08-30 12:39:01 +08:00
|
|
|
case CC_X86_64Win64:
|
|
|
|
case CC_X86_64SysV:
|
2012-12-18 22:30:41 +08:00
|
|
|
case CC_C: Out << 'A'; break;
|
|
|
|
case CC_X86Pascal: Out << 'C'; break;
|
|
|
|
case CC_X86ThisCall: Out << 'E'; break;
|
|
|
|
case CC_X86StdCall: Out << 'G'; break;
|
|
|
|
case CC_X86FastCall: Out << 'I'; break;
|
2014-10-25 01:42:17 +08:00
|
|
|
case CC_X86VectorCall: Out << 'Q'; break;
|
2016-11-03 02:29:35 +08:00
|
|
|
case CC_X86RegCall: Out << 'w'; break;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
2015-03-12 02:36:39 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleCallingConvention(const FunctionType *T) {
|
|
|
|
mangleCallingConvention(T->getCallConv());
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleThrowSpecification(
|
|
|
|
const FunctionProtoType *FT) {
|
|
|
|
// <throw-spec> ::= Z # throw(...) (default)
|
|
|
|
// ::= @ # throw() or __declspec/__attribute__((nothrow))
|
|
|
|
// ::= <type>+
|
|
|
|
// NOTE: Since the Microsoft compiler ignores throw specifications, they are
|
|
|
|
// all actually mangled as 'Z'. (They're ignored because their associated
|
|
|
|
// functionality isn't implemented, and probably never will be.)
|
|
|
|
Out << 'Z';
|
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftCXXNameMangler::mangleType(const UnresolvedUsingType *T,
|
2015-05-26 09:30:45 +08:00
|
|
|
Qualifiers, SourceRange Range) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// Probably should be mangled as a template instantiation; need to see what
|
|
|
|
// VC does first.
|
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle this unresolved dependent type yet");
|
|
|
|
Diags.Report(Range.getBegin(), DiagID)
|
|
|
|
<< Range;
|
|
|
|
}
|
|
|
|
|
|
|
|
// <type> ::= <union-type> | <struct-type> | <class-type> | <enum-type>
|
|
|
|
// <union-type> ::= T <name>
|
|
|
|
// <struct-type> ::= U <name>
|
|
|
|
// <class-type> ::= V <name>
|
2013-12-09 12:28:34 +08:00
|
|
|
// <enum-type> ::= W4 <name>
|
2015-12-29 19:45:53 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleTagTypeKind(TagTypeKind TTK) {
|
|
|
|
switch (TTK) {
|
2012-12-18 22:30:41 +08:00
|
|
|
case TTK_Union:
|
|
|
|
Out << 'T';
|
|
|
|
break;
|
|
|
|
case TTK_Struct:
|
|
|
|
case TTK_Interface:
|
|
|
|
Out << 'U';
|
|
|
|
break;
|
|
|
|
case TTK_Class:
|
|
|
|
Out << 'V';
|
|
|
|
break;
|
|
|
|
case TTK_Enum:
|
2013-12-09 12:28:34 +08:00
|
|
|
Out << "W4";
|
2012-12-18 22:30:41 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-12-29 19:45:53 +08:00
|
|
|
}
|
|
|
|
void MicrosoftCXXNameMangler::mangleType(const EnumType *T, Qualifiers,
|
|
|
|
SourceRange) {
|
|
|
|
mangleType(cast<TagType>(T)->getDecl());
|
|
|
|
}
|
|
|
|
void MicrosoftCXXNameMangler::mangleType(const RecordType *T, Qualifiers,
|
|
|
|
SourceRange) {
|
|
|
|
mangleType(cast<TagType>(T)->getDecl());
|
|
|
|
}
|
|
|
|
void MicrosoftCXXNameMangler::mangleType(const TagDecl *TD) {
|
|
|
|
mangleTagTypeKind(TD->getTagKind());
|
2013-08-06 06:26:46 +08:00
|
|
|
mangleName(TD);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2015-12-29 19:45:53 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleArtificalTagType(
|
|
|
|
TagTypeKind TK, StringRef UnqualifiedName, ArrayRef<StringRef> NestedNames) {
|
|
|
|
// <name> ::= <unscoped-name> {[<named-scope>]+ | [<nested-name>]}? @
|
|
|
|
mangleTagTypeKind(TK);
|
|
|
|
|
|
|
|
// Always start with the unqualified name.
|
|
|
|
mangleSourceName(UnqualifiedName);
|
|
|
|
|
|
|
|
for (auto I = NestedNames.rbegin(), E = NestedNames.rend(); I != E; ++I)
|
|
|
|
mangleSourceName(*I);
|
|
|
|
|
|
|
|
// Terminate the whole name with an '@'.
|
|
|
|
Out << '@';
|
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
|
|
|
|
// <type> ::= <array-type>
|
|
|
|
// <array-type> ::= <pointer-cvr-qualifiers> <cvr-qualifiers>
|
|
|
|
// [Y <dimension-count> <dimension>+]
|
2013-05-15 04:30:42 +08:00
|
|
|
// <element-type> # as global, E is never required
|
2012-12-18 22:30:41 +08:00
|
|
|
// It's supposed to be the other way around, but for some strange reason, it
|
|
|
|
// isn't. Today this behavior is retained for the sole purpose of backwards
|
|
|
|
// compatibility.
|
2013-09-11 12:44:30 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleDecayedArrayType(const ArrayType *T) {
|
2012-12-18 22:30:41 +08:00
|
|
|
// This isn't a recursive mangling, so now we have to do it all in this
|
|
|
|
// one call.
|
2014-02-18 22:20:10 +08:00
|
|
|
manglePointerCVQualifiers(T->getElementType().getQualifiers());
|
2013-04-25 12:25:40 +08:00
|
|
|
mangleType(T->getElementType(), SourceRange());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const ConstantArrayType *T, Qualifiers,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange) {
|
2013-04-25 12:25:40 +08:00
|
|
|
llvm_unreachable("Should have been special cased");
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const VariableArrayType *T, Qualifiers,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange) {
|
2013-04-25 12:25:40 +08:00
|
|
|
llvm_unreachable("Should have been special cased");
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
void MicrosoftCXXNameMangler::mangleType(const DependentSizedArrayType *T,
|
2015-05-26 09:30:45 +08:00
|
|
|
Qualifiers, SourceRange) {
|
2013-04-25 12:25:40 +08:00
|
|
|
llvm_unreachable("Should have been special cased");
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
void MicrosoftCXXNameMangler::mangleType(const IncompleteArrayType *T,
|
2015-05-26 09:30:45 +08:00
|
|
|
Qualifiers, SourceRange) {
|
2013-04-25 12:25:40 +08:00
|
|
|
llvm_unreachable("Should have been special cased");
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2013-06-25 03:21:52 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleArrayType(const ArrayType *T) {
|
2013-04-25 12:25:40 +08:00
|
|
|
QualType ElementTy(T, 0);
|
2012-12-18 22:30:41 +08:00
|
|
|
SmallVector<llvm::APInt, 3> Dimensions;
|
|
|
|
for (;;) {
|
2015-04-23 15:42:08 +08:00
|
|
|
if (ElementTy->isConstantArrayType()) {
|
|
|
|
const ConstantArrayType *CAT =
|
|
|
|
getASTContext().getAsConstantArrayType(ElementTy);
|
2012-12-18 22:30:41 +08:00
|
|
|
Dimensions.push_back(CAT->getSize());
|
|
|
|
ElementTy = CAT->getElementType();
|
2015-04-23 15:42:08 +08:00
|
|
|
} else if (ElementTy->isIncompleteArrayType()) {
|
|
|
|
const IncompleteArrayType *IAT =
|
|
|
|
getASTContext().getAsIncompleteArrayType(ElementTy);
|
|
|
|
Dimensions.push_back(llvm::APInt(32, 0));
|
|
|
|
ElementTy = IAT->getElementType();
|
2012-12-18 22:30:41 +08:00
|
|
|
} else if (ElementTy->isVariableArrayType()) {
|
|
|
|
const VariableArrayType *VAT =
|
|
|
|
getASTContext().getAsVariableArrayType(ElementTy);
|
2015-04-23 15:42:08 +08:00
|
|
|
Dimensions.push_back(llvm::APInt(32, 0));
|
|
|
|
ElementTy = VAT->getElementType();
|
2012-12-18 22:30:41 +08:00
|
|
|
} else if (ElementTy->isDependentSizedArrayType()) {
|
|
|
|
// The dependent expression has to be folded into a constant (TODO).
|
|
|
|
const DependentSizedArrayType *DSAT =
|
|
|
|
getASTContext().getAsDependentSizedArrayType(ElementTy);
|
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle this dependent-length array yet");
|
|
|
|
Diags.Report(DSAT->getSizeExpr()->getExprLoc(), DiagID)
|
|
|
|
<< DSAT->getBracketsRange();
|
|
|
|
return;
|
2015-04-23 15:42:08 +08:00
|
|
|
} else {
|
|
|
|
break;
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
2013-04-25 12:25:40 +08:00
|
|
|
Out << 'Y';
|
|
|
|
// <dimension-count> ::= <number> # number of extra dimensions
|
|
|
|
mangleNumber(Dimensions.size());
|
2014-04-23 13:16:53 +08:00
|
|
|
for (const llvm::APInt &Dimension : Dimensions)
|
|
|
|
mangleNumber(Dimension.getLimitedValue());
|
2013-06-25 03:21:52 +08:00
|
|
|
mangleType(ElementTy, SourceRange(), QMM_Escape);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// <type> ::= <pointer-to-member-type>
|
|
|
|
// <pointer-to-member-type> ::= <pointer-cvr-qualifiers> <cvr-qualifiers>
|
|
|
|
// <class name> <type>
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const MemberPointerType *T, Qualifiers Quals,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange Range) {
|
|
|
|
QualType PointeeType = T->getPointeeType();
|
2015-05-26 09:30:45 +08:00
|
|
|
manglePointerCVQualifiers(Quals);
|
|
|
|
manglePointerExtQualifiers(Quals, PointeeType);
|
2012-12-18 22:30:41 +08:00
|
|
|
if (const FunctionProtoType *FPT = PointeeType->getAs<FunctionProtoType>()) {
|
|
|
|
Out << '8';
|
|
|
|
mangleName(T->getClass()->castAs<RecordType>()->getDecl());
|
2014-05-12 13:36:57 +08:00
|
|
|
mangleFunctionType(FPT, nullptr, true);
|
2012-12-18 22:30:41 +08:00
|
|
|
} else {
|
|
|
|
mangleQualifiers(PointeeType.getQualifiers(), true);
|
|
|
|
mangleName(T->getClass()->castAs<RecordType>()->getDecl());
|
2013-04-25 12:25:40 +08:00
|
|
|
mangleType(PointeeType, Range, QMM_Drop);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftCXXNameMangler::mangleType(const TemplateTypeParmType *T,
|
2015-05-26 09:30:45 +08:00
|
|
|
Qualifiers, SourceRange Range) {
|
2012-12-18 22:30:41 +08:00
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle this template type parameter type yet");
|
|
|
|
Diags.Report(Range.getBegin(), DiagID)
|
|
|
|
<< Range;
|
|
|
|
}
|
|
|
|
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const SubstTemplateTypeParmPackType *T,
|
|
|
|
Qualifiers, SourceRange Range) {
|
2012-12-18 22:30:41 +08:00
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle this substituted parameter pack yet");
|
|
|
|
Diags.Report(Range.getBegin(), DiagID)
|
|
|
|
<< Range;
|
|
|
|
}
|
|
|
|
|
|
|
|
// <type> ::= <pointer-type>
|
2013-05-15 04:30:42 +08:00
|
|
|
// <pointer-type> ::= E? <pointer-cvr-qualifiers> <cvr-qualifiers> <type>
|
2013-12-05 12:47:09 +08:00
|
|
|
// # the E is required for 64-bit non-static pointers
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const PointerType *T, Qualifiers Quals,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange Range) {
|
2015-05-26 09:30:45 +08:00
|
|
|
QualType PointeeType = T->getPointeeType();
|
|
|
|
manglePointerCVQualifiers(Quals);
|
|
|
|
manglePointerExtQualifiers(Quals, PointeeType);
|
|
|
|
mangleType(PointeeType, Range);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
void MicrosoftCXXNameMangler::mangleType(const ObjCObjectPointerType *T,
|
2015-05-26 09:30:45 +08:00
|
|
|
Qualifiers Quals, SourceRange Range) {
|
|
|
|
QualType PointeeType = T->getPointeeType();
|
|
|
|
manglePointerCVQualifiers(Quals);
|
|
|
|
manglePointerExtQualifiers(Quals, PointeeType);
|
2012-12-18 22:30:41 +08:00
|
|
|
// Object pointers never have qualifiers.
|
|
|
|
Out << 'A';
|
2015-05-26 09:30:45 +08:00
|
|
|
mangleType(PointeeType, Range);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// <type> ::= <reference-type>
|
2013-05-15 04:30:42 +08:00
|
|
|
// <reference-type> ::= A E? <cvr-qualifiers> <type>
|
2013-12-05 12:47:09 +08:00
|
|
|
// # the E is required for 64-bit non-static lvalue references
|
2012-12-18 22:30:41 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const LValueReferenceType *T,
|
2015-05-26 09:30:45 +08:00
|
|
|
Qualifiers Quals, SourceRange Range) {
|
|
|
|
QualType PointeeType = T->getPointeeType();
|
2015-12-31 13:36:50 +08:00
|
|
|
assert(!Quals.hasConst() && !Quals.hasVolatile() && "unexpected qualifier!");
|
|
|
|
Out << 'A';
|
2015-05-26 09:30:45 +08:00
|
|
|
manglePointerExtQualifiers(Quals, PointeeType);
|
|
|
|
mangleType(PointeeType, Range);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// <type> ::= <r-value-reference-type>
|
2013-05-15 04:30:42 +08:00
|
|
|
// <r-value-reference-type> ::= $$Q E? <cvr-qualifiers> <type>
|
2013-12-05 12:47:09 +08:00
|
|
|
// # the E is required for 64-bit non-static rvalue references
|
2012-12-18 22:30:41 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const RValueReferenceType *T,
|
2015-05-26 09:30:45 +08:00
|
|
|
Qualifiers Quals, SourceRange Range) {
|
|
|
|
QualType PointeeType = T->getPointeeType();
|
2015-12-31 13:36:50 +08:00
|
|
|
assert(!Quals.hasConst() && !Quals.hasVolatile() && "unexpected qualifier!");
|
|
|
|
Out << "$$Q";
|
2015-05-26 09:30:45 +08:00
|
|
|
manglePointerExtQualifiers(Quals, PointeeType);
|
|
|
|
mangleType(PointeeType, Range);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const ComplexType *T, Qualifiers,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange Range) {
|
2015-12-30 06:02:15 +08:00
|
|
|
QualType ElementType = T->getElementType();
|
|
|
|
|
|
|
|
llvm::SmallString<64> TemplateMangling;
|
|
|
|
llvm::raw_svector_ostream Stream(TemplateMangling);
|
|
|
|
MicrosoftCXXNameMangler Extra(Context, Stream);
|
|
|
|
Stream << "?$";
|
|
|
|
Extra.mangleSourceName("_Complex");
|
|
|
|
Extra.mangleType(ElementType, Range, QMM_Escape);
|
|
|
|
|
|
|
|
mangleArtificalTagType(TTK_Struct, TemplateMangling, {"__clang"});
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const VectorType *T, Qualifiers Quals,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange Range) {
|
2013-03-27 00:56:59 +08:00
|
|
|
const BuiltinType *ET = T->getElementType()->getAs<BuiltinType>();
|
|
|
|
assert(ET && "vectors with non-builtin elements are unsupported");
|
|
|
|
uint64_t Width = getASTContext().getTypeSize(T);
|
|
|
|
// Pattern match exactly the typedefs in our intrinsic headers. Anything that
|
|
|
|
// doesn't match the Intel types uses a custom mangling below.
|
2015-12-29 19:45:58 +08:00
|
|
|
size_t OutSizeBefore = Out.tell();
|
2015-06-01 15:41:37 +08:00
|
|
|
llvm::Triple::ArchType AT =
|
|
|
|
getASTContext().getTargetInfo().getTriple().getArch();
|
|
|
|
if (AT == llvm::Triple::x86 || AT == llvm::Triple::x86_64) {
|
|
|
|
if (Width == 64 && ET->getKind() == BuiltinType::LongLong) {
|
2015-12-29 19:45:53 +08:00
|
|
|
mangleArtificalTagType(TTK_Union, "__m64");
|
2015-06-01 15:41:37 +08:00
|
|
|
} else if (Width >= 128) {
|
|
|
|
if (ET->getKind() == BuiltinType::Float)
|
2015-12-29 19:45:53 +08:00
|
|
|
mangleArtificalTagType(TTK_Union, "__m" + llvm::utostr(Width));
|
2015-06-01 15:41:37 +08:00
|
|
|
else if (ET->getKind() == BuiltinType::LongLong)
|
2015-12-29 19:45:53 +08:00
|
|
|
mangleArtificalTagType(TTK_Union, "__m" + llvm::utostr(Width) + 'i');
|
2015-06-01 15:41:37 +08:00
|
|
|
else if (ET->getKind() == BuiltinType::Double)
|
2015-12-29 19:45:53 +08:00
|
|
|
mangleArtificalTagType(TTK_Struct, "__m" + llvm::utostr(Width) + 'd');
|
2015-06-01 15:41:37 +08:00
|
|
|
}
|
2013-03-27 00:56:59 +08:00
|
|
|
}
|
|
|
|
|
2015-12-29 19:45:58 +08:00
|
|
|
bool IsBuiltin = Out.tell() != OutSizeBefore;
|
2015-06-01 15:41:37 +08:00
|
|
|
if (!IsBuiltin) {
|
2013-03-27 00:56:59 +08:00
|
|
|
// The MS ABI doesn't have a special mangling for vector types, so we define
|
|
|
|
// our own mangling to handle uses of __vector_size__ on user-specified
|
|
|
|
// types, and for extensions like __v4sf.
|
2015-12-29 19:45:58 +08:00
|
|
|
|
|
|
|
llvm::SmallString<64> TemplateMangling;
|
|
|
|
llvm::raw_svector_ostream Stream(TemplateMangling);
|
|
|
|
MicrosoftCXXNameMangler Extra(Context, Stream);
|
|
|
|
Stream << "?$";
|
|
|
|
Extra.mangleSourceName("__vector");
|
|
|
|
Extra.mangleType(QualType(ET, 0), Range, QMM_Escape);
|
|
|
|
Extra.mangleIntegerLiteral(llvm::APSInt::getUnsigned(T->getNumElements()),
|
|
|
|
/*IsBoolean=*/false);
|
|
|
|
|
|
|
|
mangleArtificalTagType(TTK_Union, TemplateMangling, {"__clang"});
|
2013-03-27 00:56:59 +08:00
|
|
|
}
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2013-03-27 00:56:59 +08:00
|
|
|
|
2015-08-01 13:51:55 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const ExtVectorType *T,
|
|
|
|
Qualifiers Quals, SourceRange Range) {
|
|
|
|
mangleType(static_cast<const VectorType *>(T), Quals, Range);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
void MicrosoftCXXNameMangler::mangleType(const DependentSizedExtVectorType *T,
|
2015-05-26 09:30:45 +08:00
|
|
|
Qualifiers, SourceRange Range) {
|
2012-12-18 22:30:41 +08:00
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle this dependent-sized extended vector type yet");
|
|
|
|
Diags.Report(Range.getBegin(), DiagID)
|
|
|
|
<< Range;
|
|
|
|
}
|
|
|
|
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const ObjCInterfaceType *T, Qualifiers,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange) {
|
|
|
|
// ObjC interfaces have structs underlying them.
|
2015-12-29 19:45:53 +08:00
|
|
|
mangleTagTypeKind(TTK_Struct);
|
2012-12-18 22:30:41 +08:00
|
|
|
mangleName(T->getDecl());
|
|
|
|
}
|
|
|
|
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const ObjCObjectType *T, Qualifiers,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange Range) {
|
|
|
|
// We don't allow overloading by different protocol qualification,
|
|
|
|
// so mangling them isn't necessary.
|
|
|
|
mangleType(T->getBaseType(), Range);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftCXXNameMangler::mangleType(const BlockPointerType *T,
|
2015-05-26 09:30:45 +08:00
|
|
|
Qualifiers Quals, SourceRange Range) {
|
|
|
|
QualType PointeeType = T->getPointeeType();
|
|
|
|
manglePointerCVQualifiers(Quals);
|
|
|
|
manglePointerExtQualifiers(Quals, PointeeType);
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
Out << "_E";
|
|
|
|
|
2015-05-26 09:30:45 +08:00
|
|
|
mangleFunctionType(PointeeType->castAs<FunctionProtoType>());
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2013-08-16 16:29:13 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const InjectedClassNameType *,
|
2015-05-26 09:30:45 +08:00
|
|
|
Qualifiers, SourceRange) {
|
2013-08-16 16:29:13 +08:00
|
|
|
llvm_unreachable("Cannot mangle injected class name type.");
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftCXXNameMangler::mangleType(const TemplateSpecializationType *T,
|
2015-05-26 09:30:45 +08:00
|
|
|
Qualifiers, SourceRange Range) {
|
2012-12-18 22:30:41 +08:00
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle this template specialization type yet");
|
|
|
|
Diags.Report(Range.getBegin(), DiagID)
|
|
|
|
<< Range;
|
|
|
|
}
|
|
|
|
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const DependentNameType *T, Qualifiers,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange Range) {
|
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle this dependent name type yet");
|
|
|
|
Diags.Report(Range.getBegin(), DiagID)
|
|
|
|
<< Range;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftCXXNameMangler::mangleType(
|
2015-05-26 09:30:45 +08:00
|
|
|
const DependentTemplateSpecializationType *T, Qualifiers,
|
|
|
|
SourceRange Range) {
|
2012-12-18 22:30:41 +08:00
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle this dependent template specialization type yet");
|
|
|
|
Diags.Report(Range.getBegin(), DiagID)
|
|
|
|
<< Range;
|
|
|
|
}
|
|
|
|
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const PackExpansionType *T, Qualifiers,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange Range) {
|
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle this pack expansion yet");
|
|
|
|
Diags.Report(Range.getBegin(), DiagID)
|
|
|
|
<< Range;
|
|
|
|
}
|
|
|
|
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const TypeOfType *T, Qualifiers,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange Range) {
|
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle this typeof(type) yet");
|
|
|
|
Diags.Report(Range.getBegin(), DiagID)
|
|
|
|
<< Range;
|
|
|
|
}
|
|
|
|
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const TypeOfExprType *T, Qualifiers,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange Range) {
|
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle this typeof(expression) yet");
|
|
|
|
Diags.Report(Range.getBegin(), DiagID)
|
|
|
|
<< Range;
|
|
|
|
}
|
|
|
|
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const DecltypeType *T, Qualifiers,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange Range) {
|
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle this decltype() yet");
|
|
|
|
Diags.Report(Range.getBegin(), DiagID)
|
|
|
|
<< Range;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftCXXNameMangler::mangleType(const UnaryTransformType *T,
|
2015-05-26 09:30:45 +08:00
|
|
|
Qualifiers, SourceRange Range) {
|
2012-12-18 22:30:41 +08:00
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle this unary transform type yet");
|
|
|
|
Diags.Report(Range.getBegin(), DiagID)
|
|
|
|
<< Range;
|
|
|
|
}
|
|
|
|
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const AutoType *T, Qualifiers,
|
|
|
|
SourceRange Range) {
|
2014-01-22 04:33:36 +08:00
|
|
|
assert(T->getDeducedType().isNull() && "expecting a dependent type!");
|
|
|
|
|
2012-12-18 22:30:41 +08:00
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle this 'auto' type yet");
|
|
|
|
Diags.Report(Range.getBegin(), DiagID)
|
|
|
|
<< Range;
|
|
|
|
}
|
|
|
|
|
2017-01-27 04:40:47 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(
|
|
|
|
const DeducedTemplateSpecializationType *T, Qualifiers, SourceRange Range) {
|
|
|
|
assert(T->getDeducedType().isNull() && "expecting a dependent type!");
|
|
|
|
|
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle this deduced class template specialization type yet");
|
|
|
|
Diags.Report(Range.getBegin(), DiagID)
|
|
|
|
<< Range;
|
|
|
|
}
|
|
|
|
|
2015-05-26 09:30:45 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const AtomicType *T, Qualifiers,
|
2012-12-18 22:30:41 +08:00
|
|
|
SourceRange Range) {
|
2015-12-29 19:46:00 +08:00
|
|
|
QualType ValueType = T->getValueType();
|
|
|
|
|
|
|
|
llvm::SmallString<64> TemplateMangling;
|
|
|
|
llvm::raw_svector_ostream Stream(TemplateMangling);
|
|
|
|
MicrosoftCXXNameMangler Extra(Context, Stream);
|
|
|
|
Stream << "?$";
|
|
|
|
Extra.mangleSourceName("_Atomic");
|
|
|
|
Extra.mangleType(ValueType, Range, QMM_Escape);
|
|
|
|
|
|
|
|
mangleArtificalTagType(TTK_Struct, TemplateMangling, {"__clang"});
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2016-01-09 20:53:17 +08:00
|
|
|
void MicrosoftCXXNameMangler::mangleType(const PipeType *T, Qualifiers,
|
|
|
|
SourceRange Range) {
|
|
|
|
DiagnosticsEngine &Diags = Context.getDiags();
|
|
|
|
unsigned DiagID = Diags.getCustomDiagID(DiagnosticsEngine::Error,
|
|
|
|
"cannot mangle this OpenCL pipe type yet");
|
|
|
|
Diags.Report(Range.getBegin(), DiagID)
|
|
|
|
<< Range;
|
|
|
|
}
|
|
|
|
|
2013-10-16 09:40:34 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleCXXName(const NamedDecl *D,
|
|
|
|
raw_ostream &Out) {
|
2012-12-18 22:30:41 +08:00
|
|
|
assert((isa<FunctionDecl>(D) || isa<VarDecl>(D)) &&
|
|
|
|
"Invalid mangleName() call, argument is not a variable or function!");
|
|
|
|
assert(!isa<CXXConstructorDecl>(D) && !isa<CXXDestructorDecl>(D) &&
|
|
|
|
"Invalid mangleName() call on 'structor decl!");
|
|
|
|
|
|
|
|
PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
|
|
|
|
getASTContext().getSourceManager(),
|
|
|
|
"Mangling declaration");
|
|
|
|
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
2012-12-18 22:30:41 +08:00
|
|
|
return Mangler.mangle(D);
|
|
|
|
}
|
2013-07-30 17:46:19 +08:00
|
|
|
|
2013-11-06 14:24:31 +08:00
|
|
|
// <this-adjustment> ::= <no-adjustment> | <static-adjustment> |
|
|
|
|
// <virtual-adjustment>
|
|
|
|
// <no-adjustment> ::= A # private near
|
|
|
|
// ::= B # private far
|
|
|
|
// ::= I # protected near
|
|
|
|
// ::= J # protected far
|
|
|
|
// ::= Q # public near
|
|
|
|
// ::= R # public far
|
|
|
|
// <static-adjustment> ::= G <static-offset> # private near
|
|
|
|
// ::= H <static-offset> # private far
|
|
|
|
// ::= O <static-offset> # protected near
|
|
|
|
// ::= P <static-offset> # protected far
|
|
|
|
// ::= W <static-offset> # public near
|
|
|
|
// ::= X <static-offset> # public far
|
|
|
|
// <virtual-adjustment> ::= $0 <virtual-shift> <static-offset> # private near
|
|
|
|
// ::= $1 <virtual-shift> <static-offset> # private far
|
|
|
|
// ::= $2 <virtual-shift> <static-offset> # protected near
|
|
|
|
// ::= $3 <virtual-shift> <static-offset> # protected far
|
|
|
|
// ::= $4 <virtual-shift> <static-offset> # public near
|
|
|
|
// ::= $5 <virtual-shift> <static-offset> # public far
|
|
|
|
// <virtual-shift> ::= <vtordisp-shift> | <vtordispex-shift>
|
|
|
|
// <vtordisp-shift> ::= <offset-to-vtordisp>
|
|
|
|
// <vtordispex-shift> ::= <offset-to-vbptr> <vbase-offset-offset>
|
|
|
|
// <offset-to-vtordisp>
|
2013-10-09 17:23:58 +08:00
|
|
|
static void mangleThunkThisAdjustment(const CXXMethodDecl *MD,
|
|
|
|
const ThisAdjustment &Adjustment,
|
|
|
|
MicrosoftCXXNameMangler &Mangler,
|
|
|
|
raw_ostream &Out) {
|
2013-11-06 14:24:31 +08:00
|
|
|
if (!Adjustment.Virtual.isEmpty()) {
|
|
|
|
Out << '$';
|
|
|
|
char AccessSpec;
|
|
|
|
switch (MD->getAccess()) {
|
|
|
|
case AS_none:
|
|
|
|
llvm_unreachable("Unsupported access specifier");
|
|
|
|
case AS_private:
|
|
|
|
AccessSpec = '0';
|
|
|
|
break;
|
|
|
|
case AS_protected:
|
|
|
|
AccessSpec = '2';
|
|
|
|
break;
|
|
|
|
case AS_public:
|
|
|
|
AccessSpec = '4';
|
|
|
|
}
|
|
|
|
if (Adjustment.Virtual.Microsoft.VBPtrOffset) {
|
|
|
|
Out << 'R' << AccessSpec;
|
2013-12-09 18:44:32 +08:00
|
|
|
Mangler.mangleNumber(
|
|
|
|
static_cast<uint32_t>(Adjustment.Virtual.Microsoft.VBPtrOffset));
|
|
|
|
Mangler.mangleNumber(
|
|
|
|
static_cast<uint32_t>(Adjustment.Virtual.Microsoft.VBOffsetOffset));
|
|
|
|
Mangler.mangleNumber(
|
|
|
|
static_cast<uint32_t>(Adjustment.Virtual.Microsoft.VtordispOffset));
|
|
|
|
Mangler.mangleNumber(static_cast<uint32_t>(Adjustment.NonVirtual));
|
2013-11-06 14:24:31 +08:00
|
|
|
} else {
|
|
|
|
Out << AccessSpec;
|
2013-12-09 18:44:32 +08:00
|
|
|
Mangler.mangleNumber(
|
|
|
|
static_cast<uint32_t>(Adjustment.Virtual.Microsoft.VtordispOffset));
|
|
|
|
Mangler.mangleNumber(-static_cast<uint32_t>(Adjustment.NonVirtual));
|
2013-11-06 14:24:31 +08:00
|
|
|
}
|
|
|
|
} else if (Adjustment.NonVirtual != 0) {
|
2013-10-09 17:23:58 +08:00
|
|
|
switch (MD->getAccess()) {
|
|
|
|
case AS_none:
|
|
|
|
llvm_unreachable("Unsupported access specifier");
|
|
|
|
case AS_private:
|
|
|
|
Out << 'G';
|
|
|
|
break;
|
|
|
|
case AS_protected:
|
|
|
|
Out << 'O';
|
|
|
|
break;
|
|
|
|
case AS_public:
|
|
|
|
Out << 'W';
|
|
|
|
}
|
2013-12-09 18:44:32 +08:00
|
|
|
Mangler.mangleNumber(-static_cast<uint32_t>(Adjustment.NonVirtual));
|
2013-10-09 17:23:58 +08:00
|
|
|
} else {
|
|
|
|
switch (MD->getAccess()) {
|
|
|
|
case AS_none:
|
|
|
|
llvm_unreachable("Unsupported access specifier");
|
|
|
|
case AS_private:
|
|
|
|
Out << 'A';
|
|
|
|
break;
|
|
|
|
case AS_protected:
|
|
|
|
Out << 'I';
|
|
|
|
break;
|
|
|
|
case AS_public:
|
|
|
|
Out << 'Q';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-06 01:27:08 +08:00
|
|
|
void
|
|
|
|
MicrosoftMangleContextImpl::mangleVirtualMemPtrThunk(const CXXMethodDecl *MD,
|
|
|
|
raw_ostream &Out) {
|
|
|
|
MicrosoftVTableContext *VTContext =
|
|
|
|
cast<MicrosoftVTableContext>(getASTContext().getVTableContext());
|
|
|
|
const MicrosoftVTableContext::MethodVFTableLocation &ML =
|
|
|
|
VTContext->getMethodVFTableLocation(GlobalDecl(MD));
|
2013-11-16 01:24:45 +08:00
|
|
|
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
2014-02-06 01:27:08 +08:00
|
|
|
Mangler.getStream() << "\01?";
|
|
|
|
Mangler.mangleVirtualMemPtrThunk(MD, ML);
|
2013-11-16 01:24:45 +08:00
|
|
|
}
|
|
|
|
|
2013-10-03 14:26:13 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleThunk(const CXXMethodDecl *MD,
|
|
|
|
const ThunkInfo &Thunk,
|
|
|
|
raw_ostream &Out) {
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
|
|
|
Mangler.getStream() << "\01?";
|
2013-07-30 17:46:19 +08:00
|
|
|
Mangler.mangleName(MD);
|
2016-03-07 16:51:17 +08:00
|
|
|
mangleThunkThisAdjustment(MD, Thunk.This, Mangler, MHO);
|
2013-10-09 17:23:58 +08:00
|
|
|
if (!Thunk.Return.isEmpty())
|
2014-05-12 13:36:57 +08:00
|
|
|
assert(Thunk.Method != nullptr &&
|
|
|
|
"Thunk info should hold the overridee decl");
|
2013-10-09 17:23:58 +08:00
|
|
|
|
|
|
|
const CXXMethodDecl *DeclForFPT = Thunk.Method ? Thunk.Method : MD;
|
|
|
|
Mangler.mangleFunctionType(
|
|
|
|
DeclForFPT->getType()->castAs<FunctionProtoType>(), MD);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftMangleContextImpl::mangleCXXDtorThunk(
|
|
|
|
const CXXDestructorDecl *DD, CXXDtorType Type,
|
|
|
|
const ThisAdjustment &Adjustment, raw_ostream &Out) {
|
|
|
|
// FIXME: Actually, the dtor thunk should be emitted for vector deleting
|
|
|
|
// dtors rather than scalar deleting dtors. Just use the vector deleting dtor
|
|
|
|
// mangling manually until we support both deleting dtor types.
|
|
|
|
assert(Type == Dtor_Deleting);
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO, DD, Type);
|
|
|
|
Mangler.getStream() << "\01??_E";
|
2013-10-09 17:23:58 +08:00
|
|
|
Mangler.mangleName(DD->getParent());
|
2016-03-07 16:51:17 +08:00
|
|
|
mangleThunkThisAdjustment(DD, Adjustment, Mangler, MHO);
|
2013-10-09 17:23:58 +08:00
|
|
|
Mangler.mangleFunctionType(DD->getType()->castAs<FunctionProtoType>(), DD);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2013-06-19 23:20:38 +08:00
|
|
|
|
2013-10-03 14:26:13 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleCXXVFTable(
|
2013-09-27 22:48:01 +08:00
|
|
|
const CXXRecordDecl *Derived, ArrayRef<const CXXRecordDecl *> BasePath,
|
|
|
|
raw_ostream &Out) {
|
2013-06-19 23:20:38 +08:00
|
|
|
// <mangled-name> ::= ?_7 <class-name> <storage-class>
|
|
|
|
// <cvr-qualifiers> [<name>] @
|
2012-12-18 22:30:41 +08:00
|
|
|
// NOTE: <cvr-qualifiers> here is always 'B' (const). <storage-class>
|
2013-06-19 23:20:38 +08:00
|
|
|
// is always '6' for vftables.
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
2016-02-12 01:49:28 +08:00
|
|
|
if (Derived->hasAttr<DLLImportAttr>())
|
|
|
|
Mangler.getStream() << "\01??_S";
|
|
|
|
else
|
|
|
|
Mangler.getStream() << "\01??_7";
|
2013-09-27 22:48:01 +08:00
|
|
|
Mangler.mangleName(Derived);
|
|
|
|
Mangler.getStream() << "6B"; // '6' for vftable, 'B' for const.
|
2014-04-23 13:16:53 +08:00
|
|
|
for (const CXXRecordDecl *RD : BasePath)
|
|
|
|
Mangler.mangleName(RD);
|
2012-12-18 22:30:41 +08:00
|
|
|
Mangler.getStream() << '@';
|
|
|
|
}
|
2013-06-19 23:20:38 +08:00
|
|
|
|
2013-10-03 14:26:13 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleCXXVBTable(
|
2013-06-19 23:20:38 +08:00
|
|
|
const CXXRecordDecl *Derived, ArrayRef<const CXXRecordDecl *> BasePath,
|
|
|
|
raw_ostream &Out) {
|
|
|
|
// <mangled-name> ::= ?_8 <class-name> <storage-class>
|
|
|
|
// <cvr-qualifiers> [<name>] @
|
|
|
|
// NOTE: <cvr-qualifiers> here is always 'B' (const). <storage-class>
|
|
|
|
// is always '7' for vbtables.
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
2013-06-19 23:20:38 +08:00
|
|
|
Mangler.getStream() << "\01??_8";
|
|
|
|
Mangler.mangleName(Derived);
|
|
|
|
Mangler.getStream() << "7B"; // '7' for vbtable, 'B' for const.
|
2014-04-23 13:16:53 +08:00
|
|
|
for (const CXXRecordDecl *RD : BasePath)
|
|
|
|
Mangler.mangleName(RD);
|
2013-06-19 23:20:38 +08:00
|
|
|
Mangler.getStream() << '@';
|
|
|
|
}
|
|
|
|
|
2014-05-13 08:44:44 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleCXXRTTI(QualType T, raw_ostream &Out) {
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
2014-05-13 08:44:44 +08:00
|
|
|
Mangler.getStream() << "\01??_R0";
|
|
|
|
Mangler.mangleType(T, SourceRange(), MicrosoftCXXNameMangler::QMM_Result);
|
|
|
|
Mangler.getStream() << "@8";
|
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftMangleContextImpl::mangleCXXRTTIName(QualType T,
|
|
|
|
raw_ostream &Out) {
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, Out);
|
|
|
|
Mangler.getStream() << '.';
|
|
|
|
Mangler.mangleType(T, SourceRange(), MicrosoftCXXNameMangler::QMM_Result);
|
|
|
|
}
|
|
|
|
|
2015-06-23 15:31:11 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleCXXVirtualDisplacementMap(
|
|
|
|
const CXXRecordDecl *SrcRD, const CXXRecordDecl *DstRD, raw_ostream &Out) {
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
2015-06-23 15:31:11 +08:00
|
|
|
Mangler.getStream() << "\01??_K";
|
|
|
|
Mangler.mangleName(SrcRD);
|
|
|
|
Mangler.getStream() << "$C";
|
|
|
|
Mangler.mangleName(DstRD);
|
|
|
|
}
|
|
|
|
|
2016-07-12 12:42:50 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleCXXThrowInfo(QualType T, bool IsConst,
|
2015-03-05 08:46:22 +08:00
|
|
|
bool IsVolatile,
|
2016-07-12 12:42:50 +08:00
|
|
|
bool IsUnaligned,
|
2015-03-05 08:46:22 +08:00
|
|
|
uint32_t NumEntries,
|
|
|
|
raw_ostream &Out) {
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
2015-03-05 08:46:22 +08:00
|
|
|
Mangler.getStream() << "_TI";
|
|
|
|
if (IsConst)
|
|
|
|
Mangler.getStream() << 'C';
|
|
|
|
if (IsVolatile)
|
|
|
|
Mangler.getStream() << 'V';
|
2016-07-12 12:42:50 +08:00
|
|
|
if (IsUnaligned)
|
|
|
|
Mangler.getStream() << 'U';
|
2015-03-05 08:46:22 +08:00
|
|
|
Mangler.getStream() << NumEntries;
|
|
|
|
Mangler.mangleType(T, SourceRange(), MicrosoftCXXNameMangler::QMM_Result);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftMangleContextImpl::mangleCXXCatchableTypeArray(
|
|
|
|
QualType T, uint32_t NumEntries, raw_ostream &Out) {
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
2015-03-05 08:46:22 +08:00
|
|
|
Mangler.getStream() << "_CTA";
|
|
|
|
Mangler.getStream() << NumEntries;
|
|
|
|
Mangler.mangleType(T, SourceRange(), MicrosoftCXXNameMangler::QMM_Result);
|
|
|
|
}
|
|
|
|
|
2015-03-07 02:53:55 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleCXXCatchableType(
|
2015-03-12 02:36:39 +08:00
|
|
|
QualType T, const CXXConstructorDecl *CD, CXXCtorType CT, uint32_t Size,
|
|
|
|
uint32_t NVOffset, int32_t VBPtrOffset, uint32_t VBIndex,
|
|
|
|
raw_ostream &Out) {
|
2015-03-05 08:46:22 +08:00
|
|
|
MicrosoftCXXNameMangler Mangler(*this, Out);
|
2015-03-07 02:53:55 +08:00
|
|
|
Mangler.getStream() << "_CT";
|
|
|
|
|
|
|
|
llvm::SmallString<64> RTTIMangling;
|
|
|
|
{
|
|
|
|
llvm::raw_svector_ostream Stream(RTTIMangling);
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Stream);
|
|
|
|
mangleCXXRTTI(T, MHO);
|
2015-03-07 02:53:55 +08:00
|
|
|
}
|
|
|
|
Mangler.getStream() << RTTIMangling.substr(1);
|
|
|
|
|
2015-03-11 03:01:51 +08:00
|
|
|
// VS2015 CTP6 omits the copy-constructor in the mangled name. This name is,
|
|
|
|
// in fact, superfluous but I'm not sure the change was made consciously.
|
2015-03-07 02:53:55 +08:00
|
|
|
llvm::SmallString<64> CopyCtorMangling;
|
2016-03-07 16:51:17 +08:00
|
|
|
if (!getASTContext().getLangOpts().isCompatibleWithMSVC(
|
|
|
|
LangOptions::MSVC2015) &&
|
|
|
|
CD) {
|
2015-03-07 02:53:55 +08:00
|
|
|
llvm::raw_svector_ostream Stream(CopyCtorMangling);
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Stream);
|
|
|
|
mangleCXXCtor(CD, CT, MHO);
|
2015-03-07 02:53:55 +08:00
|
|
|
}
|
|
|
|
Mangler.getStream() << CopyCtorMangling.substr(1);
|
|
|
|
|
2015-03-05 08:46:22 +08:00
|
|
|
Mangler.getStream() << Size;
|
2015-03-11 03:01:51 +08:00
|
|
|
if (VBPtrOffset == -1) {
|
|
|
|
if (NVOffset) {
|
|
|
|
Mangler.getStream() << NVOffset;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Mangler.getStream() << NVOffset;
|
|
|
|
Mangler.getStream() << VBPtrOffset;
|
|
|
|
Mangler.getStream() << VBIndex;
|
|
|
|
}
|
2015-03-05 08:46:22 +08:00
|
|
|
}
|
|
|
|
|
2014-05-13 08:44:44 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleCXXRTTIBaseClassDescriptor(
|
2014-05-24 00:07:43 +08:00
|
|
|
const CXXRecordDecl *Derived, uint32_t NVOffset, int32_t VBPtrOffset,
|
2014-05-13 14:57:43 +08:00
|
|
|
uint32_t VBTableOffset, uint32_t Flags, raw_ostream &Out) {
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
2014-05-13 08:44:44 +08:00
|
|
|
Mangler.getStream() << "\01??_R1";
|
|
|
|
Mangler.mangleNumber(NVOffset);
|
|
|
|
Mangler.mangleNumber(VBPtrOffset);
|
|
|
|
Mangler.mangleNumber(VBTableOffset);
|
|
|
|
Mangler.mangleNumber(Flags);
|
2014-05-13 14:57:43 +08:00
|
|
|
Mangler.mangleName(Derived);
|
2014-05-24 00:07:43 +08:00
|
|
|
Mangler.getStream() << "8";
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2013-10-03 14:26:13 +08:00
|
|
|
|
2014-05-13 08:44:44 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleCXXRTTIBaseClassArray(
|
|
|
|
const CXXRecordDecl *Derived, raw_ostream &Out) {
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
2014-05-13 08:44:44 +08:00
|
|
|
Mangler.getStream() << "\01??_R2";
|
|
|
|
Mangler.mangleName(Derived);
|
2014-05-24 00:07:43 +08:00
|
|
|
Mangler.getStream() << "8";
|
2014-05-13 08:44:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftMangleContextImpl::mangleCXXRTTIClassHierarchyDescriptor(
|
|
|
|
const CXXRecordDecl *Derived, raw_ostream &Out) {
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
2014-05-13 08:44:44 +08:00
|
|
|
Mangler.getStream() << "\01??_R3";
|
|
|
|
Mangler.mangleName(Derived);
|
2014-05-24 00:07:43 +08:00
|
|
|
Mangler.getStream() << "8";
|
2014-05-13 08:44:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MicrosoftMangleContextImpl::mangleCXXRTTICompleteObjectLocator(
|
2014-05-13 14:57:43 +08:00
|
|
|
const CXXRecordDecl *Derived, ArrayRef<const CXXRecordDecl *> BasePath,
|
|
|
|
raw_ostream &Out) {
|
|
|
|
// <mangled-name> ::= ?_R4 <class-name> <storage-class>
|
|
|
|
// <cvr-qualifiers> [<name>] @
|
|
|
|
// NOTE: <cvr-qualifiers> here is always 'B' (const). <storage-class>
|
|
|
|
// is always '6' for vftables.
|
2016-03-07 16:51:17 +08:00
|
|
|
llvm::SmallString<64> VFTableMangling;
|
|
|
|
llvm::raw_svector_ostream Stream(VFTableMangling);
|
|
|
|
mangleCXXVFTable(Derived, BasePath, Stream);
|
|
|
|
|
|
|
|
if (VFTableMangling.startswith("\01??@")) {
|
|
|
|
assert(VFTableMangling.endswith("@"));
|
|
|
|
Out << VFTableMangling << "??_R4@";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(VFTableMangling.startswith("\01??_7") ||
|
|
|
|
VFTableMangling.startswith("\01??_S"));
|
|
|
|
|
|
|
|
Out << "\01??_R4" << StringRef(VFTableMangling).drop_front(5);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
2013-10-03 14:26:13 +08:00
|
|
|
|
Initial support for Win64 SEH IR emission
The lowering looks a lot like normal EH lowering, with the exception
that the exceptions are caught by executing filter expression code
instead of matching typeinfo globals. The filter expressions are
outlined into functions which are used in landingpad clauses where
typeinfo would normally go.
Major aspects that still need work:
- Non-call exceptions in __try bodies won't work yet. The plan is to
outline the __try block in the frontend to keep things simple.
- Filter expressions cannot use local variables until capturing is
implemented.
- __finally blocks will not run after exceptions. Fixing this requires
work in the LLVM SEH preparation pass.
The IR lowering looks like this:
// C code:
bool safe_div(int n, int d, int *r) {
__try {
*r = normal_div(n, d);
} __except(_exception_code() == EXCEPTION_INT_DIVIDE_BY_ZERO) {
return false;
}
return true;
}
; LLVM IR:
define i32 @filter(i8* %e, i8* %fp) {
%ehptrs = bitcast i8* %e to i32**
%ehrec = load i32** %ehptrs
%code = load i32* %ehrec
%matches = icmp eq i32 %code, i32 u0xC0000094
%matches.i32 = zext i1 %matches to i32
ret i32 %matches.i32
}
define i1 zeroext @safe_div(i32 %n, i32 %d, i32* %r) {
%rr = invoke i32 @normal_div(i32 %n, i32 %d)
to label %normal unwind to label %lpad
normal:
store i32 %rr, i32* %r
ret i1 1
lpad:
%ehvals = landingpad {i8*, i32} personality i32 (...)* @__C_specific_handler
catch i8* bitcast (i32 (i8*, i8*)* @filter to i8*)
%ehptr = extractvalue {i8*, i32} %ehvals, i32 0
%sel = extractvalue {i8*, i32} %ehvals, i32 1
%filter_sel = call i32 @llvm.eh.seh.typeid.for(i8* bitcast (i32 (i8*, i8*)* @filter to i8*))
%matches = icmp eq i32 %sel, %filter_sel
br i1 %matches, label %eh.except, label %eh.resume
eh.except:
ret i1 false
eh.resume:
resume
}
Reviewers: rjmccall, rsmith, majnemer
Differential Revision: http://reviews.llvm.org/D5607
llvm-svn: 226760
2015-01-22 09:36:17 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleSEHFilterExpression(
|
|
|
|
const NamedDecl *EnclosingDecl, raw_ostream &Out) {
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
Initial support for Win64 SEH IR emission
The lowering looks a lot like normal EH lowering, with the exception
that the exceptions are caught by executing filter expression code
instead of matching typeinfo globals. The filter expressions are
outlined into functions which are used in landingpad clauses where
typeinfo would normally go.
Major aspects that still need work:
- Non-call exceptions in __try bodies won't work yet. The plan is to
outline the __try block in the frontend to keep things simple.
- Filter expressions cannot use local variables until capturing is
implemented.
- __finally blocks will not run after exceptions. Fixing this requires
work in the LLVM SEH preparation pass.
The IR lowering looks like this:
// C code:
bool safe_div(int n, int d, int *r) {
__try {
*r = normal_div(n, d);
} __except(_exception_code() == EXCEPTION_INT_DIVIDE_BY_ZERO) {
return false;
}
return true;
}
; LLVM IR:
define i32 @filter(i8* %e, i8* %fp) {
%ehptrs = bitcast i8* %e to i32**
%ehrec = load i32** %ehptrs
%code = load i32* %ehrec
%matches = icmp eq i32 %code, i32 u0xC0000094
%matches.i32 = zext i1 %matches to i32
ret i32 %matches.i32
}
define i1 zeroext @safe_div(i32 %n, i32 %d, i32* %r) {
%rr = invoke i32 @normal_div(i32 %n, i32 %d)
to label %normal unwind to label %lpad
normal:
store i32 %rr, i32* %r
ret i1 1
lpad:
%ehvals = landingpad {i8*, i32} personality i32 (...)* @__C_specific_handler
catch i8* bitcast (i32 (i8*, i8*)* @filter to i8*)
%ehptr = extractvalue {i8*, i32} %ehvals, i32 0
%sel = extractvalue {i8*, i32} %ehvals, i32 1
%filter_sel = call i32 @llvm.eh.seh.typeid.for(i8* bitcast (i32 (i8*, i8*)* @filter to i8*))
%matches = icmp eq i32 %sel, %filter_sel
br i1 %matches, label %eh.except, label %eh.resume
eh.except:
ret i1 false
eh.resume:
resume
}
Reviewers: rjmccall, rsmith, majnemer
Differential Revision: http://reviews.llvm.org/D5607
llvm-svn: 226760
2015-01-22 09:36:17 +08:00
|
|
|
// The function body is in the same comdat as the function with the handler,
|
|
|
|
// so the numbering here doesn't have to be the same across TUs.
|
|
|
|
//
|
|
|
|
// <mangled-name> ::= ?filt$ <filter-number> @0
|
|
|
|
Mangler.getStream() << "\01?filt$" << SEHFilterIds[EnclosingDecl]++ << "@0@";
|
|
|
|
Mangler.mangleName(EnclosingDecl);
|
|
|
|
}
|
|
|
|
|
2015-04-15 04:59:00 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleSEHFinallyBlock(
|
|
|
|
const NamedDecl *EnclosingDecl, raw_ostream &Out) {
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
2015-04-15 04:59:00 +08:00
|
|
|
// The function body is in the same comdat as the function with the handler,
|
|
|
|
// so the numbering here doesn't have to be the same across TUs.
|
|
|
|
//
|
|
|
|
// <mangled-name> ::= ?fin$ <filter-number> @0
|
|
|
|
Mangler.getStream() << "\01?fin$" << SEHFinallyIds[EnclosingDecl]++ << "@0@";
|
|
|
|
Mangler.mangleName(EnclosingDecl);
|
|
|
|
}
|
|
|
|
|
2013-11-20 07:23:00 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleTypeName(QualType T, raw_ostream &Out) {
|
|
|
|
// This is just a made up unique string for the purposes of tbaa. undname
|
|
|
|
// does *not* know how to demangle it.
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, Out);
|
|
|
|
Mangler.getStream() << '?';
|
|
|
|
Mangler.mangleType(T, SourceRange());
|
|
|
|
}
|
|
|
|
|
2013-10-03 14:26:13 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleCXXCtor(const CXXConstructorDecl *D,
|
|
|
|
CXXCtorType Type,
|
|
|
|
raw_ostream &Out) {
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler mangler(*this, MHO, D, Type);
|
2012-12-18 22:30:41 +08:00
|
|
|
mangler.mangle(D);
|
|
|
|
}
|
2013-10-03 14:26:13 +08:00
|
|
|
|
|
|
|
void MicrosoftMangleContextImpl::mangleCXXDtor(const CXXDestructorDecl *D,
|
|
|
|
CXXDtorType Type,
|
|
|
|
raw_ostream &Out) {
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler mangler(*this, MHO, D, Type);
|
2012-12-18 22:30:41 +08:00
|
|
|
mangler.mangle(D);
|
|
|
|
}
|
2013-10-03 14:26:13 +08:00
|
|
|
|
2015-12-30 06:25:14 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleReferenceTemporary(
|
|
|
|
const VarDecl *VD, unsigned ManglingNumber, raw_ostream &Out) {
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
2015-12-30 06:25:14 +08:00
|
|
|
|
|
|
|
Mangler.getStream() << "\01?$RT" << ManglingNumber << '@';
|
|
|
|
Mangler.mangle(VD, "");
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|
|
|
|
|
2015-05-07 14:15:46 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleThreadSafeStaticGuardVariable(
|
|
|
|
const VarDecl *VD, unsigned GuardNum, raw_ostream &Out) {
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
2015-05-07 14:15:46 +08:00
|
|
|
|
|
|
|
Mangler.getStream() << "\01?$TSS" << GuardNum << '@';
|
|
|
|
Mangler.mangleNestedName(VD);
|
2016-05-27 16:52:34 +08:00
|
|
|
Mangler.getStream() << "@4HA";
|
2015-05-07 14:15:46 +08:00
|
|
|
}
|
|
|
|
|
2013-10-03 14:26:13 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleStaticGuardVariable(const VarDecl *VD,
|
|
|
|
raw_ostream &Out) {
|
2014-03-05 16:57:59 +08:00
|
|
|
// <guard-name> ::= ?_B <postfix> @5 <scope-depth>
|
2015-05-08 05:19:06 +08:00
|
|
|
// ::= ?__J <postfix> @5 <scope-depth>
|
2013-09-11 04:14:30 +08:00
|
|
|
// ::= ?$S <guard-num> @ <postfix> @4IA
|
|
|
|
|
|
|
|
// The first mangling is what MSVC uses to guard static locals in inline
|
|
|
|
// functions. It uses a different mangling in external functions to support
|
|
|
|
// guarding more than 32 variables. MSVC rejects inline functions with more
|
|
|
|
// than 32 static locals. We don't fully implement the second mangling
|
|
|
|
// because those guards are not externally visible, and instead use LLVM's
|
|
|
|
// default renaming when creating a new guard variable.
|
2016-03-07 16:51:17 +08:00
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
2013-09-11 04:14:30 +08:00
|
|
|
|
|
|
|
bool Visible = VD->isExternallyVisible();
|
2015-05-07 14:15:46 +08:00
|
|
|
if (Visible) {
|
2015-05-08 05:19:06 +08:00
|
|
|
Mangler.getStream() << (VD->getTLSKind() ? "\01??__J" : "\01??_B");
|
2015-05-07 14:15:46 +08:00
|
|
|
} else {
|
|
|
|
Mangler.getStream() << "\01?$S1@";
|
|
|
|
}
|
2014-03-07 03:57:36 +08:00
|
|
|
unsigned ScopeDepth = 0;
|
|
|
|
if (Visible && !getNextDiscriminator(VD, ScopeDepth))
|
|
|
|
// If we do not have a discriminator and are emitting a guard variable for
|
|
|
|
// use at global scope, then mangling the nested name will not be enough to
|
|
|
|
// remove ambiguities.
|
|
|
|
Mangler.mangle(VD, "");
|
|
|
|
else
|
|
|
|
Mangler.mangleNestedName(VD);
|
2014-03-05 16:57:59 +08:00
|
|
|
Mangler.getStream() << (Visible ? "@5" : "@4IA");
|
2014-03-07 03:57:36 +08:00
|
|
|
if (ScopeDepth)
|
2014-03-05 16:57:59 +08:00
|
|
|
Mangler.mangleNumber(ScopeDepth);
|
2013-09-11 04:14:30 +08:00
|
|
|
}
|
|
|
|
|
2013-10-03 14:26:13 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleInitFiniStub(const VarDecl *D,
|
2016-03-07 16:51:17 +08:00
|
|
|
char CharCode,
|
|
|
|
raw_ostream &Out) {
|
|
|
|
msvc_hashing_ostream MHO(Out);
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, MHO);
|
2013-09-11 04:43:12 +08:00
|
|
|
Mangler.getStream() << "\01??__" << CharCode;
|
2013-09-11 04:14:30 +08:00
|
|
|
Mangler.mangleName(D);
|
2014-03-07 03:10:27 +08:00
|
|
|
if (D->isStaticDataMember()) {
|
|
|
|
Mangler.mangleVariableEncoding(D);
|
|
|
|
Mangler.getStream() << '@';
|
|
|
|
}
|
2013-09-11 04:43:12 +08:00
|
|
|
// This is the function class mangling. These stubs are global, non-variadic,
|
|
|
|
// cdecl functions that return void and take no args.
|
2013-09-11 04:14:30 +08:00
|
|
|
Mangler.getStream() << "YAXXZ";
|
|
|
|
}
|
|
|
|
|
2013-10-03 14:26:13 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleDynamicInitializer(const VarDecl *D,
|
|
|
|
raw_ostream &Out) {
|
2013-09-11 04:43:12 +08:00
|
|
|
// <initializer-name> ::= ?__E <name> YAXXZ
|
2016-03-07 16:51:17 +08:00
|
|
|
mangleInitFiniStub(D, 'E', Out);
|
2013-09-11 04:43:12 +08:00
|
|
|
}
|
|
|
|
|
2013-10-03 14:26:13 +08:00
|
|
|
void
|
|
|
|
MicrosoftMangleContextImpl::mangleDynamicAtExitDestructor(const VarDecl *D,
|
|
|
|
raw_ostream &Out) {
|
2013-09-11 04:43:12 +08:00
|
|
|
// <destructor-name> ::= ?__F <name> YAXXZ
|
2016-03-07 16:51:17 +08:00
|
|
|
mangleInitFiniStub(D, 'F', Out);
|
2013-09-11 04:43:12 +08:00
|
|
|
}
|
|
|
|
|
2014-03-25 05:43:36 +08:00
|
|
|
void MicrosoftMangleContextImpl::mangleStringLiteral(const StringLiteral *SL,
|
|
|
|
raw_ostream &Out) {
|
|
|
|
// <char-type> ::= 0 # char
|
|
|
|
// ::= 1 # wchar_t
|
|
|
|
// ::= ??? # char16_t/char32_t will need a mangling too...
|
|
|
|
//
|
|
|
|
// <literal-length> ::= <non-negative integer> # the length of the literal
|
|
|
|
//
|
|
|
|
// <encoded-crc> ::= <hex digit>+ @ # crc of the literal including
|
|
|
|
// # null-terminator
|
|
|
|
//
|
|
|
|
// <encoded-string> ::= <simple character> # uninteresting character
|
|
|
|
// ::= '?$' <hex digit> <hex digit> # these two nibbles
|
|
|
|
// # encode the byte for the
|
|
|
|
// # character
|
|
|
|
// ::= '?' [a-z] # \xe1 - \xfa
|
|
|
|
// ::= '?' [A-Z] # \xc1 - \xda
|
|
|
|
// ::= '?' [0-9] # [,/\:. \n\t'-]
|
|
|
|
//
|
|
|
|
// <literal> ::= '??_C@_' <char-type> <literal-length> <encoded-crc>
|
|
|
|
// <encoded-string> '@'
|
|
|
|
MicrosoftCXXNameMangler Mangler(*this, Out);
|
|
|
|
Mangler.getStream() << "\01??_C@_";
|
|
|
|
|
|
|
|
// <char-type>: The "kind" of string literal is encoded into the mangled name.
|
2014-11-22 03:57:25 +08:00
|
|
|
if (SL->isWide())
|
2014-03-25 05:43:36 +08:00
|
|
|
Mangler.getStream() << '1';
|
|
|
|
else
|
2014-11-22 03:57:25 +08:00
|
|
|
Mangler.getStream() << '0';
|
2014-03-25 05:43:36 +08:00
|
|
|
|
|
|
|
// <literal-length>: The next part of the mangled name consists of the length
|
|
|
|
// of the string.
|
|
|
|
// The StringLiteral does not consider the NUL terminator byte(s) but the
|
|
|
|
// mangling does.
|
|
|
|
// N.B. The length is in terms of bytes, not characters.
|
|
|
|
Mangler.mangleNumber(SL->getByteLength() + SL->getCharByteWidth());
|
|
|
|
|
2017-01-14 02:55:32 +08:00
|
|
|
auto GetLittleEndianByte = [&SL](unsigned Index) {
|
2014-04-01 01:18:53 +08:00
|
|
|
unsigned CharByteWidth = SL->getCharByteWidth();
|
|
|
|
uint32_t CodeUnit = SL->getCodeUnit(Index / CharByteWidth);
|
2014-04-01 05:46:05 +08:00
|
|
|
unsigned OffsetInCodeUnit = Index % CharByteWidth;
|
|
|
|
return static_cast<char>((CodeUnit >> (8 * OffsetInCodeUnit)) & 0xff);
|
2014-04-01 01:18:53 +08:00
|
|
|
};
|
|
|
|
|
2017-01-14 02:55:32 +08:00
|
|
|
auto GetBigEndianByte = [&SL](unsigned Index) {
|
2014-04-01 01:18:53 +08:00
|
|
|
unsigned CharByteWidth = SL->getCharByteWidth();
|
|
|
|
uint32_t CodeUnit = SL->getCodeUnit(Index / CharByteWidth);
|
2014-04-01 05:46:05 +08:00
|
|
|
unsigned OffsetInCodeUnit = (CharByteWidth - 1) - (Index % CharByteWidth);
|
|
|
|
return static_cast<char>((CodeUnit >> (8 * OffsetInCodeUnit)) & 0xff);
|
2014-04-01 01:18:53 +08:00
|
|
|
};
|
|
|
|
|
2014-03-25 05:43:36 +08:00
|
|
|
// CRC all the bytes of the StringLiteral.
|
2015-09-02 05:24:07 +08:00
|
|
|
llvm::JamCRC JC;
|
2014-04-01 01:18:53 +08:00
|
|
|
for (unsigned I = 0, E = SL->getByteLength(); I != E; ++I)
|
2015-09-02 05:24:07 +08:00
|
|
|
JC.update(GetLittleEndianByte(I));
|
2014-03-25 05:43:36 +08:00
|
|
|
|
|
|
|
// The NUL terminator byte(s) were not present earlier,
|
|
|
|
// we need to manually process those bytes into the CRC.
|
|
|
|
for (unsigned NullTerminator = 0; NullTerminator < SL->getCharByteWidth();
|
|
|
|
++NullTerminator)
|
2015-09-02 05:24:07 +08:00
|
|
|
JC.update('\x00');
|
2014-03-25 05:43:36 +08:00
|
|
|
|
|
|
|
// <encoded-crc>: The CRC is encoded utilizing the standard number mangling
|
|
|
|
// scheme.
|
2015-09-02 05:24:07 +08:00
|
|
|
Mangler.mangleNumber(JC.getCRC());
|
2014-03-25 05:43:36 +08:00
|
|
|
|
2014-03-31 00:38:02 +08:00
|
|
|
// <encoded-string>: The mangled name also contains the first 32 _characters_
|
2014-03-25 05:43:36 +08:00
|
|
|
// (including null-terminator bytes) of the StringLiteral.
|
|
|
|
// Each character is encoded by splitting them into bytes and then encoding
|
|
|
|
// the constituent bytes.
|
|
|
|
auto MangleByte = [&Mangler](char Byte) {
|
|
|
|
// There are five different manglings for characters:
|
|
|
|
// - [a-zA-Z0-9_$]: A one-to-one mapping.
|
|
|
|
// - ?[a-z]: The range from \xe1 to \xfa.
|
|
|
|
// - ?[A-Z]: The range from \xc1 to \xda.
|
|
|
|
// - ?[0-9]: The set of [,/\:. \n\t'-].
|
|
|
|
// - ?$XX: A fallback which maps nibbles.
|
2014-04-01 08:05:57 +08:00
|
|
|
if (isIdentifierBody(Byte, /*AllowDollar=*/true)) {
|
2014-03-25 05:43:36 +08:00
|
|
|
Mangler.getStream() << Byte;
|
2014-04-01 08:05:57 +08:00
|
|
|
} else if (isLetter(Byte & 0x7f)) {
|
|
|
|
Mangler.getStream() << '?' << static_cast<char>(Byte & 0x7f);
|
2014-03-25 05:43:36 +08:00
|
|
|
} else {
|
2014-12-22 14:24:49 +08:00
|
|
|
const char SpecialChars[] = {',', '/', '\\', ':', '.',
|
|
|
|
' ', '\n', '\t', '\'', '-'};
|
|
|
|
const char *Pos =
|
|
|
|
std::find(std::begin(SpecialChars), std::end(SpecialChars), Byte);
|
|
|
|
if (Pos != std::end(SpecialChars)) {
|
|
|
|
Mangler.getStream() << '?' << (Pos - std::begin(SpecialChars));
|
|
|
|
} else {
|
|
|
|
Mangler.getStream() << "?$";
|
|
|
|
Mangler.getStream() << static_cast<char>('A' + ((Byte >> 4) & 0xf));
|
|
|
|
Mangler.getStream() << static_cast<char>('A' + (Byte & 0xf));
|
2014-03-25 05:43:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Enforce our 32 character max.
|
|
|
|
unsigned NumCharsToMangle = std::min(32U, SL->getLength());
|
2014-04-01 01:18:53 +08:00
|
|
|
for (unsigned I = 0, E = NumCharsToMangle * SL->getCharByteWidth(); I != E;
|
|
|
|
++I)
|
2014-11-22 03:57:25 +08:00
|
|
|
if (SL->isWide())
|
|
|
|
MangleByte(GetBigEndianByte(I));
|
|
|
|
else
|
|
|
|
MangleByte(GetLittleEndianByte(I));
|
2014-03-25 05:43:36 +08:00
|
|
|
|
|
|
|
// Encode the NUL terminator if there is room.
|
|
|
|
if (NumCharsToMangle < 32)
|
2014-04-01 01:18:53 +08:00
|
|
|
for (unsigned NullTerminator = 0; NullTerminator < SL->getCharByteWidth();
|
|
|
|
++NullTerminator)
|
|
|
|
MangleByte(0);
|
2014-03-25 05:43:36 +08:00
|
|
|
|
|
|
|
Mangler.getStream() << '@';
|
|
|
|
}
|
|
|
|
|
2013-10-03 14:26:13 +08:00
|
|
|
MicrosoftMangleContext *
|
|
|
|
MicrosoftMangleContext::create(ASTContext &Context, DiagnosticsEngine &Diags) {
|
|
|
|
return new MicrosoftMangleContextImpl(Context, Diags);
|
2012-12-18 22:30:41 +08:00
|
|
|
}
|