r205727 - Mangle the vbptr offset into pointers to member functions
Reid Kleckner
reid at kleckner.net
Mon Apr 7 11:07:03 PDT 2014
Author: rnk
Date: Mon Apr 7 13:07:03 2014
New Revision: 205727
URL: http://llvm.org/viewvc/llvm-project?rev=205727&view=rev
Log:
Mangle the vbptr offset into pointers to member functions
This can actually be non-zero if you override a function from a virtual
base and you have forced the most_general pointer to member
representation.
Added:
cfe/trunk/test/CodeGenCXX/mangle-ms-templates-memptrs-2.cpp
Modified:
cfe/trunk/lib/AST/MicrosoftMangle.cpp
Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=205727&r1=205726&r2=205727&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Mon Apr 7 13:07:03 2014
@@ -470,6 +470,9 @@ void MicrosoftCXXNameMangler::mangleMemb
mangleNumber(FieldOffset);
+ // 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.
if (MSInheritanceAttr::hasVBPtrOffsetField(IM))
mangleNumber(0);
if (MSInheritanceAttr::hasVBTableOffsetField(IM))
@@ -509,6 +512,7 @@ MicrosoftCXXNameMangler::mangleMemberFun
// thunk.
uint64_t NVOffset = 0;
uint64_t VBTableOffset = 0;
+ uint64_t VBPtrOffset = 0;
if (MD->isVirtual()) {
MicrosoftVTableContext *VTContext =
cast<MicrosoftVTableContext>(getASTContext().getVTableContext());
@@ -518,11 +522,8 @@ MicrosoftCXXNameMangler::mangleMemberFun
NVOffset = ML.VFPtrOffset.getQuantity();
VBTableOffset = ML.VBTableIndex * 4;
if (ML.VBase) {
- DiagnosticsEngine &Diags = Context.getDiags();
- unsigned DiagID = Diags.getCustomDiagID(
- DiagnosticsEngine::Error,
- "cannot mangle pointers to member functions from virtual bases");
- Diags.Report(MD->getLocation(), DiagID);
+ const ASTRecordLayout &Layout = getASTContext().getASTRecordLayout(RD);
+ VBPtrOffset = Layout.getVBPtrOffset().getQuantity();
}
} else {
mangleName(MD);
@@ -532,7 +533,7 @@ MicrosoftCXXNameMangler::mangleMemberFun
if (MSInheritanceAttr::hasNVOffsetField(/*IsMemberFunction=*/true, IM))
mangleNumber(NVOffset);
if (MSInheritanceAttr::hasVBPtrOffsetField(IM))
- mangleNumber(0);
+ mangleNumber(VBPtrOffset);
if (MSInheritanceAttr::hasVBTableOffsetField(IM))
mangleNumber(VBTableOffset);
}
Added: cfe/trunk/test/CodeGenCXX/mangle-ms-templates-memptrs-2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-templates-memptrs-2.cpp?rev=205727&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-ms-templates-memptrs-2.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms-templates-memptrs-2.cpp Mon Apr 7 13:07:03 2014
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -Wno-microsoft -fms-extensions -fno-rtti -std=c++11 -emit-llvm %s -o - -triple=i386-pc-win32 | FileCheck %s
+
+#pragma pointers_to_members(full_generality, virtual_inheritance)
+
+struct S {
+ int a, b;
+ void f();
+ virtual void g();
+};
+
+struct GeneralBase {
+ virtual void h();
+};
+struct MostGeneral : S, virtual GeneralBase {
+ virtual void h();
+};
+template <void (MostGeneral::*MP)()>
+struct ClassTemplate {
+ ClassTemplate() {}
+};
+
+template struct ClassTemplate<&MostGeneral::h>;
+
+// Test that we mangle in the vbptr offset, which is 12 here.
+//
+// CHECK: define weak_odr x86_thiscallcc %struct.ClassTemplate* @"\01??0?$ClassTemplate@$J??_9MostGeneral@@$BA at AEA@M at 3@@QAE at XZ"
More information about the cfe-commits
mailing list