r200921 - MS ABI: Handle indirect field decls in template args
David Majnemer
david.majnemer at gmail.com
Thu Feb 6 04:46:52 PST 2014
Author: majnemer
Date: Thu Feb 6 06:46:52 2014
New Revision: 200921
URL: http://llvm.org/viewvc/llvm-project?rev=200921&view=rev
Log:
MS ABI: Handle indirect field decls in template args
Properly support fields that come from anonymous unions and structs
when used as template arguments for pointer to data member params.
Modified:
cfe/trunk/lib/AST/MicrosoftMangle.cpp
cfe/trunk/test/CodeGenCXX/mangle-ms-templates-memptrs.cpp
Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=200921&r1=200920&r2=200921&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Thu Feb 6 06:46:52 2014
@@ -122,7 +122,7 @@ public:
void mangleDeclaration(const NamedDecl *ND);
void mangleFunctionEncoding(const FunctionDecl *FD);
void mangleVariableEncoding(const VarDecl *VD);
- void mangleMemberDataPointer(const CXXRecordDecl *RD, const FieldDecl *FD);
+ void mangleMemberDataPointer(const CXXRecordDecl *RD, const ValueDecl *VD);
void mangleMemberFunctionPointer(const CXXRecordDecl *RD,
const CXXMethodDecl *MD);
void mangleVirtualMemPtrThunk(
@@ -378,7 +378,7 @@ void MicrosoftCXXNameMangler::mangleVari
}
void MicrosoftCXXNameMangler::mangleMemberDataPointer(const CXXRecordDecl *RD,
- const FieldDecl *FD) {
+ const ValueDecl *VD) {
// <member-data-pointer> ::= <integer-literal>
// ::= $F <number> <number>
// ::= $G <number> <number> <number>
@@ -386,8 +386,8 @@ void MicrosoftCXXNameMangler::mangleMemb
int64_t FieldOffset;
int64_t VBTableOffset;
MSInheritanceAttr::Spelling IM = RD->getMSInheritanceModel();
- if (FD) {
- FieldOffset = getASTContext().getFieldOffset(FD);
+ if (VD) {
+ FieldOffset = getASTContext().getFieldOffset(VD);
assert(FieldOffset % getASTContext().getCharWidth() == 0 &&
"cannot take address of bitfield");
FieldOffset /= getASTContext().getCharWidth();
@@ -1083,8 +1083,9 @@ void MicrosoftCXXNameMangler::mangleTemp
}
case TemplateArgument::Declaration: {
const NamedDecl *ND = cast<NamedDecl>(TA.getAsDecl());
- if (const FieldDecl *FD = dyn_cast<FieldDecl>(ND)) {
- mangleMemberDataPointer(cast<CXXRecordDecl>(FD->getParent()), FD);
+ if (isa<FieldDecl>(ND) || isa<IndirectFieldDecl>(ND)) {
+ mangleMemberDataPointer(cast<CXXRecordDecl>(ND->getDeclContext()),
+ cast<ValueDecl>(ND));
} else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(ND)) {
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD);
if (MD && MD->isInstance())
Modified: cfe/trunk/test/CodeGenCXX/mangle-ms-templates-memptrs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-templates-memptrs.cpp?rev=200921&r1=200920&r2=200921&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-ms-templates-memptrs.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms-templates-memptrs.cpp Thu Feb 6 06:46:52 2014
@@ -10,6 +10,7 @@ struct S { int a, b; void f(
struct M : A, B { int a, b; void f(); virtual void g(); };
struct V : virtual A { int a, b; void f(); virtual void g(); };
struct U { int a, b; void f(); virtual void g(); };
+struct I { union { struct { int a, b; }; }; void f(); virtual void g(); };
struct C { virtual void f(); };
struct D { virtual void g(); };
@@ -27,10 +28,12 @@ void ReadFields() {
M m;
V v;
U u;
+ ReadField<I, &S::a>(s);
ReadField<S, &S::a>(s);
ReadField<M, &M::a>(m);
ReadField<V, &V::a>(v);
ReadField<U, &U::a>(u);
+ ReadField<I, &S::b>(s);
ReadField<S, &S::b>(s);
ReadField<M, &M::b>(m);
ReadField<V, &V::b>(v);
@@ -46,10 +49,12 @@ void ReadFields() {
}
// CHECK-LABEL: define {{.*}}ReadFields
+// CHECK: call {{.*}} @"\01??$ReadField at UI@@$03@@YAHAAUS@@@Z"
// CHECK: call {{.*}} @"\01??$ReadField at US@@$03@@YAHAAUS@@@Z"
// CHECK: call {{.*}} @"\01??$ReadField at UM@@$0M@@@YAHAAUM@@@Z"
// CHECK: call {{.*}} @"\01??$ReadField at UV@@$F7A@@@YAHAAUV@@@Z"
// CHECK: call {{.*}} @"\01??$ReadField at UU@@$G3A at A@@@YAHAAUU@@@Z"
+// CHECK: call {{.*}} @"\01??$ReadField at UI@@$07@@YAHAAUS@@@Z"
// CHECK: call {{.*}} @"\01??$ReadField at US@@$07@@YAHAAUS@@@Z"
// CHECK: call {{.*}} @"\01??$ReadField at UM@@$0BA@@@YAHAAUM@@@Z"
// CHECK: call {{.*}} @"\01??$ReadField at UV@@$FM at A@@@YAHAAUV@@@Z"
More information about the cfe-commits
mailing list