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.

llvm-svn: 200921
diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp
index f02dfc7..4ecbab4 100644
--- a/clang/lib/AST/MicrosoftMangle.cpp
+++ b/clang/lib/AST/MicrosoftMangle.cpp
@@ -122,7 +122,7 @@
   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::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 @@
   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 @@
   }
   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())