// RUN: %clang_cc1 -Wno-microsoft -fno-rtti -std=c++11 -emit-llvm %s -o - -triple=i386-pc-win32 | FileCheck %s struct U; static_assert(sizeof(void (U::*)()) == 2 * sizeof(void*) + 2 * sizeof(int), ""); struct A { int a; }; struct B { int b; }; struct I { union { struct { int a, b; }; }; }; struct S { int a, b; void f(); virtual void g(); }; 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 C { virtual void f(); }; struct D { virtual void g(); }; struct O : C, D { virtual void g(); }; // override of non-primary // Test data member pointers. template int ReadField(T &o) { return F ? o.*F : 0; } // Redeclare some of the classes so that the implicit attribute goes on the most // recent redeclaration rather than the definition. struct V; void ReadFields() { A a; I i; S s; M m; V v; U u; ReadField(s); ReadField(m); ReadField(v); ReadField(u); ReadField(s); ReadField(m); ReadField(v); ReadField(u); ReadField(s); ReadField(m); ReadField(v); ReadField(u); // Non-polymorphic null data memptr vs first field memptr. ReadField(a); ReadField(a); // Indirect fields injected from anonymous unions and structs ReadField(i); ReadField(i); } // CHECK-LABEL: define {{.*}}ReadFields // CHECK: call {{.*}} @"??$ReadField@US@@$03@@YAHAAUS@@@Z" // CHECK: call {{.*}} @"??$ReadField@UM@@$0M@@@YAHAAUM@@@Z" // CHECK: call {{.*}} @"??$ReadField@UV@@$F7A@@@YAHAAUV@@@Z" // CHECK: call {{.*}} @"??$ReadField@UU@@$G3A@A@@@YAHAAUU@@@Z" // CHECK: call {{.*}} @"??$ReadField@US@@$07@@YAHAAUS@@@Z" // CHECK: call {{.*}} @"??$ReadField@UM@@$0BA@@@YAHAAUM@@@Z" // CHECK: call {{.*}} @"??$ReadField@UV@@$FM@A@@@YAHAAUV@@@Z" // CHECK: call {{.*}} @"??$ReadField@UU@@$G7A@A@@@YAHAAUU@@@Z" // MSVC mangles null member pointers in function templates wrong, but it gets // them right in class templates. // CHECK: call {{.*}} @"??$ReadField@US@@$0A@@@YAHAAUS@@@Z" // CHECK: call {{.*}} @"??$ReadField@UM@@$0A@@@YAHAAUM@@@Z" // CHECK: call {{.*}} @"??$ReadField@UV@@$0A@@@YAHAAUV@@@Z" // CHECK: call {{.*}} @"??$ReadField@UU@@$0A@@@YAHAAUU@@@Z" // Non-polymorphic null data memptr vs first field memptr. MSVC mangles these // the same. // CHECK: call {{.*}} @"??$ReadField@UA@@$0A@@@YAHAAUA@@@Z" // CHECK: call {{.*}} @"??$ReadField@UA@@$0?0@@YAHAAUA@@@Z" // Indirect fields are handled as-if they were simply members of their enclosing // record. // CHECK: call {{.*}} @"??$ReadField@UI@@$0A@@@YAHAAUI@@@Z" // CHECK: call {{.*}} @"??$ReadField@UI@@$03@@YAHAAUI@@@Z" // Test member function pointers. template void CallMethod(T &o) { (o.*MFP)(); } void CallMethods() { S s; M m; V v; U u; O o; // Non-virtual methods. CallMethod(s); CallMethod(m); CallMethod(v); CallMethod(u); // Virtual methods requiring thunk mangling. CallMethod(s); CallMethod(m); CallMethod(v); CallMethod(u); // A member pointer for a non-primary vbase will have a non-zero this // adjustment. CallMethod(o); // Null member pointers. CallMethod(s); CallMethod(m); CallMethod(v); CallMethod(u); } // CHECK-LABEL: define {{.*}}CallMethods // CHECK: call {{.*}} @"??$CallMethod@US@@$1?f@1@QAEXXZ@@YAXAAUS@@@Z" // CHECK: call {{.*}} @"??$CallMethod@UM@@$H?f@1@QAEXXZA@@@YAXAAUM@@@Z" // CHECK: call {{.*}} @"??$CallMethod@UV@@$I?f@1@QAEXXZA@A@@@YAXAAUV@@@Z" // CHECK: call {{.*}} @"??$CallMethod@UU@@$J?f@1@QAEXXZA@A@A@@@YAXAAUU@@@Z" // PR17034: MSVC reuses the same thunk for every virtual g method because they // are all at vftable offset zero. They then mangle the name of the first thunk // created into the name of the template instantiation, which is definitely a // bug. We don't follow them here. Instead of ?_91@ backref below, they would // get ?_9S@@ in every instantiation after the first. // CHECK: call {{.*}} @"??$CallMethod@US@@$1??_91@$BA@AE@@YAXAAUS@@@Z" // CHECK: call {{.*}} @"??$CallMethod@UM@@$H??_91@$BA@AEA@@@YAXAAUM@@@Z" // CHECK: call {{.*}} @"??$CallMethod@UV@@$I??_91@$BA@AEA@A@@@YAXAAUV@@@Z" // CHECK: call {{.*}} @"??$CallMethod@UU@@$J??_91@$BA@AEA@A@A@@@YAXAAUU@@@Z" // CHECK: call {{.*}} @"??$CallMethod@UO@@$H??_91@$BA@AE3@@YAXAAUO@@@Z" // CHECK: call {{.*}} @"??$CallMethod@US@@$0A@@@YAXAAUS@@@Z" // CHECK: call {{.*}} @"??$CallMethod@UM@@$0A@@@YAXAAUM@@@Z" // CHECK: call {{.*}} @"??$CallMethod@UV@@$0A@@@YAXAAUV@@@Z" // CHECK: call {{.*}} @"??$CallMethod@UU@@$0A@@@YAXAAUU@@@Z" namespace NegativeNVOffset { struct A {}; struct B : virtual A {}; struct C : B { virtual void f(); }; } template void CallMethod(NegativeNVOffset::C &); // CHECK-LABEL: define {{.*}} @"??$CallMethod@UC@NegativeNVOffset@@$I??_912@$BA@AEPPPPPPPM@A@@@YAXAAUC@NegativeNVOffset@@@Z"