[PATCH] [-cxx-abi microsoft] Mangle TemplateArgument::Declaration correctly for member pointers and references

David Majnemer david.majnemer at gmail.com
Thu Aug 8 03:00:21 PDT 2013


    - Didn't mean to include this file.

Hi rnk, cdavis5x,

http://llvm-reviews.chandlerc.com/D1323

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D1323?vs=3278&id=3279#toc

Files:
  lib/AST/MicrosoftMangle.cpp
  test/CodeGenCXX/mangle-ms-templates.cpp

Index: lib/AST/MicrosoftMangle.cpp
===================================================================
--- lib/AST/MicrosoftMangle.cpp
+++ lib/AST/MicrosoftMangle.cpp
@@ -882,9 +882,17 @@
     mangleType(T, SourceRange(), QMM_Escape);
     break;
   }
-  case TemplateArgument::Declaration:
-    mangle(cast<NamedDecl>(TA.getAsDecl()), "$1?");
+  case TemplateArgument::Declaration: {
+    const NamedDecl *ND = cast<NamedDecl>(TA.getAsDecl());
+    if (isa<FieldDecl>(ND)) {
+      llvm::APSInt Offset(/*BitWidth=*/64, /*isUnsigned=*/true);
+      Offset = getASTContext().getFieldOffset(cast<FieldDecl>(ND)) /
+               getASTContext().getCharWidth();
+      mangleIntegerLiteral(Offset, false);
+    } else
+      mangle(ND, TA.isDeclForReferenceParam() ? "$E?" : "$1?");
     break;
+  }
   case TemplateArgument::Integral:
     mangleIntegerLiteral(TA.getAsIntegral(),
                          TA.getIntegralType()->isBooleanType());
Index: test/CodeGenCXX/mangle-ms-templates.cpp
===================================================================
--- test/CodeGenCXX/mangle-ms-templates.cpp
+++ test/CodeGenCXX/mangle-ms-templates.cpp
@@ -161,3 +161,22 @@
 template <decltype(nullptr)> struct S1 {};
 void f(S1<nullptr>) {}
 // CHECK: "\01?f@@YAXU?$S1@$0A@@@@Z"
+
+struct record {
+  int first;
+  int second;
+};
+template <const record &>
+struct type1 {
+};
+extern const record inst;
+void recref(type1<inst>) {}
+// CHECK: "\01?recref@@YAXU?$type1@$E?inst@@3Urecord@@B@@@Z"
+
+template <int record::*>
+struct type2 {
+};
+void memptr1(type2<&record::first>) {}
+// CHECK: "\01?memptr1@@YAXU?$type2@$0A@@@@Z"
+void memptr2(type2<&record::second>) {}
+// CHECK: "\01?memptr2@@YAXU?$type2@$03@@@Z"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1323.2.patch
Type: text/x-patch
Size: 1715 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130808/4e41b7fd/attachment.bin>


More information about the cfe-commits mailing list