Mangle tag types (unions, structs, classes, enums) in the Microsoft C++ Mangler.
Also, test that static members with default visibility in a struct have the right mangling. llvm-svn: 106276
This commit is contained in:
parent
6e4ea2db7f
commit
108f5a2748
|
@ -47,6 +47,7 @@ public:
|
||||||
void mangleName(const NamedDecl *ND);
|
void mangleName(const NamedDecl *ND);
|
||||||
void mangleFunctionEncoding(const FunctionDecl *FD);
|
void mangleFunctionEncoding(const FunctionDecl *FD);
|
||||||
void mangleVariableEncoding(const VarDecl *VD);
|
void mangleVariableEncoding(const VarDecl *VD);
|
||||||
|
void mangleNumber(int64_t Number);
|
||||||
void mangleType(QualType T);
|
void mangleType(QualType T);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -67,6 +68,7 @@ private:
|
||||||
#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
|
#define TYPE(CLASS, PARENT) void mangleType(const CLASS##Type *T);
|
||||||
#include "clang/AST/TypeNodes.def"
|
#include "clang/AST/TypeNodes.def"
|
||||||
|
|
||||||
|
void mangleType(const TagType*);
|
||||||
void mangleType(const FunctionType *T, bool IsStructor);
|
void mangleType(const FunctionType *T, bool IsStructor);
|
||||||
void mangleFunctionClass(const FunctionDecl *FD);
|
void mangleFunctionClass(const FunctionDecl *FD);
|
||||||
void mangleCallingConvention(const FunctionType *T);
|
void mangleCallingConvention(const FunctionType *T);
|
||||||
|
@ -285,6 +287,30 @@ void MicrosoftCXXNameMangler::mangleName(const NamedDecl *ND) {
|
||||||
Out << '@';
|
Out << '@';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MicrosoftCXXNameMangler::mangleNumber(int64_t Number) {
|
||||||
|
// <number> ::= [?] <decimal digit> # <= 9
|
||||||
|
// ::= [?] <hex digit>+ @ # > 9; A = 0, B = 1, etc...
|
||||||
|
if (Number < 0) {
|
||||||
|
Out << '?';
|
||||||
|
Number = -Number;
|
||||||
|
}
|
||||||
|
if (Number <= 9) {
|
||||||
|
Out << Number;
|
||||||
|
} else {
|
||||||
|
// We have to build up the encoding in reverse order, so it will come
|
||||||
|
// out right when we write it out.
|
||||||
|
char Encoding[16];
|
||||||
|
char *EndPtr = Encoding+sizeof(Encoding);
|
||||||
|
char *CurPtr = EndPtr;
|
||||||
|
while (Number) {
|
||||||
|
*--CurPtr = 'A' + (Number % 16);
|
||||||
|
Number /= 16;
|
||||||
|
}
|
||||||
|
Out.write(CurPtr, EndPtr-CurPtr);
|
||||||
|
Out << '@';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
MicrosoftCXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
|
MicrosoftCXXNameMangler::mangleUnqualifiedName(const NamedDecl *ND,
|
||||||
DeclarationName Name) {
|
DeclarationName Name) {
|
||||||
|
@ -627,6 +653,12 @@ return;
|
||||||
case Type::Builtin:
|
case Type::Builtin:
|
||||||
mangleType(static_cast<BuiltinType *>(T.getTypePtr()));
|
mangleType(static_cast<BuiltinType *>(T.getTypePtr()));
|
||||||
break;
|
break;
|
||||||
|
case Type::Enum:
|
||||||
|
mangleType(static_cast<EnumType *>(T.getTypePtr()));
|
||||||
|
break;
|
||||||
|
case Type::Record:
|
||||||
|
mangleType(static_cast<RecordType *>(T.getTypePtr()));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
assert(false && "Don't know how to mangle this type!");
|
assert(false && "Don't know how to mangle this type!");
|
||||||
break;
|
break;
|
||||||
|
@ -850,6 +882,37 @@ void MicrosoftCXXNameMangler::mangleThrowSpecification(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// <type> ::= <union-type> | <struct-type> | <class-type> | <enum-type>
|
||||||
|
// <union-type> ::= T <name>
|
||||||
|
// <struct-type> ::= U <name>
|
||||||
|
// <class-type> ::= V <name>
|
||||||
|
// <enum-type> ::= W <size> <name>
|
||||||
|
void MicrosoftCXXNameMangler::mangleType(const EnumType *T) {
|
||||||
|
mangleType(static_cast<const TagType*>(T));
|
||||||
|
}
|
||||||
|
void MicrosoftCXXNameMangler::mangleType(const RecordType *T) {
|
||||||
|
mangleType(static_cast<const TagType*>(T));
|
||||||
|
}
|
||||||
|
void MicrosoftCXXNameMangler::mangleType(const TagType *T) {
|
||||||
|
switch (T->getDecl()->getTagKind()) {
|
||||||
|
case TTK_Union:
|
||||||
|
Out << 'T';
|
||||||
|
break;
|
||||||
|
case TTK_Struct:
|
||||||
|
Out << 'U';
|
||||||
|
break;
|
||||||
|
case TTK_Class:
|
||||||
|
Out << 'V';
|
||||||
|
break;
|
||||||
|
case TTK_Enum:
|
||||||
|
Out << 'W';
|
||||||
|
mangleNumber(getASTContext().getTypeSizeInChars(
|
||||||
|
cast<EnumDecl>(T->getDecl())->getIntegerType()).getQuantity());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
mangleName(T->getDecl());
|
||||||
|
}
|
||||||
|
|
||||||
void MicrosoftMangleContext::mangleName(const NamedDecl *D,
|
void MicrosoftMangleContext::mangleName(const NamedDecl *D,
|
||||||
llvm::SmallVectorImpl<char> &Name) {
|
llvm::SmallVectorImpl<char> &Name) {
|
||||||
assert((isa<FunctionDecl>(D) || isa<VarDecl>(D)) &&
|
assert((isa<FunctionDecl>(D) || isa<VarDecl>(D)) &&
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
// CHECK: @"\01?d@foo@@0FB"
|
// CHECK: @"\01?d@foo@@0FB"
|
||||||
// CHECK: @"\01?e@foo@@1JC"
|
// CHECK: @"\01?e@foo@@1JC"
|
||||||
// CHECK: @"\01?f@foo@@2DD"
|
// CHECK: @"\01?f@foo@@2DD"
|
||||||
|
// CHECK: @"\01?g@bar@@2HA"
|
||||||
|
|
||||||
int a;
|
int a;
|
||||||
|
|
||||||
|
@ -24,6 +25,22 @@ public:
|
||||||
int operator+(int a);
|
int operator+(int a);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct bar {
|
||||||
|
static int g;
|
||||||
|
};
|
||||||
|
|
||||||
|
union baz {
|
||||||
|
int a;
|
||||||
|
char b;
|
||||||
|
double c;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum quux {
|
||||||
|
qone,
|
||||||
|
qtwo,
|
||||||
|
qthree
|
||||||
|
};
|
||||||
|
|
||||||
int foo::operator+(int a) {return a;}
|
int foo::operator+(int a) {return a;}
|
||||||
// CHECK: @"\01??Hfoo@@QAAHH@Z"
|
// CHECK: @"\01??Hfoo@@QAAHH@Z"
|
||||||
|
|
||||||
|
@ -31,6 +48,8 @@ const short foo::d = 0;
|
||||||
volatile long foo::e;
|
volatile long foo::e;
|
||||||
const volatile char foo::f = 'C';
|
const volatile char foo::f = 'C';
|
||||||
|
|
||||||
|
int bar::g;
|
||||||
|
|
||||||
// Static functions are mangled, too.
|
// Static functions are mangled, too.
|
||||||
// Also make sure calling conventions, arglists, and throw specs work.
|
// Also make sure calling conventions, arglists, and throw specs work.
|
||||||
static void __stdcall alpha(float a, double b) throw() {}
|
static void __stdcall alpha(float a, double b) throw() {}
|
||||||
|
@ -42,3 +61,7 @@ bool __fastcall beta(long long a, wchar_t b) throw(signed char, unsigned char) {
|
||||||
|
|
||||||
// CHECK: @"\01?alpha@@YGXMN@@"
|
// CHECK: @"\01?alpha@@YGXMN@@"
|
||||||
|
|
||||||
|
// Make sure tag-type mangling works.
|
||||||
|
void gamma(class foo, struct bar, union baz, enum quux) {}
|
||||||
|
// CHECK: @"\01?gamma@@YAXVfoo@@Ubar@@Tbaz@@W4quux@@@Z"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue