r227796 - MS ABI: Implement support for 'novtable'
Aaron Ballman
aaron at aaronballman.com
Mon Feb 2 11:13:30 PST 2015
On Mon, Feb 2, 2015 at 2:07 PM, David Majnemer <david.majnemer at gmail.com> wrote:
> Done in r227838.
Thanks! Looks great to me!
~Aaron
>
> On Mon, Feb 2, 2015 at 4:40 AM, Aaron Ballman <aaron at aaronballman.com>
> wrote:
>>
>> On Mon, Feb 2, 2015 at 5:22 AM, David Majnemer <david.majnemer at gmail.com>
>> wrote:
>> > Author: majnemer
>> > Date: Mon Feb 2 04:22:20 2015
>> > New Revision: 227796
>> >
>> > URL: http://llvm.org/viewvc/llvm-project?rev=227796&view=rev
>> > Log:
>> > MS ABI: Implement support for 'novtable'
>> >
>> > It is common for COM interface classes to be marked as 'novtable' to
>> > tell the compiler that constructors and destructors should not reference
>> > virtual function tables.
>> >
>> > This commit implements this feature in clang.
>> >
>> > Modified:
>> > cfe/trunk/include/clang/Basic/Attr.td
>> > cfe/trunk/lib/CodeGen/CGClass.cpp
>> > cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
>> > cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>> > cfe/trunk/test/Parser/MicrosoftExtensions.cpp
>> >
>> > Modified: cfe/trunk/include/clang/Basic/Attr.td
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=227796&r1=227795&r2=227796&view=diff
>> >
>> > ==============================================================================
>> > --- cfe/trunk/include/clang/Basic/Attr.td (original)
>> > +++ cfe/trunk/include/clang/Basic/Attr.td Mon Feb 2 04:22:20 2015
>> > @@ -1761,6 +1761,12 @@ def TypeTagForDatatype : InheritableAttr
>> >
>> > // Microsoft-related attributes
>> >
>> > +def MsNoVTable : InheritableAttr {
>> > + let Spellings = [Declspec<"novtable">];
>> > + let Subjects = SubjectList<[CXXRecord]>;
>> > + let Documentation = [Undocumented];
>>
>> No undocumented attributes, please.
>>
>> > +}
>> > +
>> > def MsProperty : IgnoredAttr {
>> > let Spellings = [Declspec<"property">];
>> > }
>> >
>> > Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=227796&r1=227795&r2=227796&view=diff
>> >
>> > ==============================================================================
>> > --- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
>> > +++ cfe/trunk/lib/CodeGen/CGClass.cpp Mon Feb 2 04:22:20 2015
>> > @@ -1949,6 +1949,14 @@ CodeGenFunction::InitializeVTablePointer
>> > const CXXRecordDecl
>> > *NearestVBase,
>> > CharUnits
>> > OffsetFromNearestVBase,
>> > const CXXRecordDecl
>> > *VTableClass) {
>> > + const CXXRecordDecl *RD = Base.getBase();
>> > +
>> > + // Don't initialize the vtable pointer if the class is marked with
>> > the
>> > + // 'novtable' attribute.
>> > + if ((RD == VTableClass || RD == NearestVBase) &&
>> > + VTableClass->hasAttr<MsNoVTableAttr>())
>> > + return;
>> > +
>> > // Compute the address point.
>> > bool NeedsVirtualOffset;
>> > llvm::Value *VTableAddressPoint =
>> >
>> > Modified: cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp?rev=227796&r1=227795&r2=227796&view=diff
>> >
>> > ==============================================================================
>> > --- cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp (original)
>> > +++ cfe/trunk/lib/CodeGen/MicrosoftCXXABI.cpp Mon Feb 2 04:22:20 2015
>> > @@ -1582,7 +1582,8 @@ void MicrosoftCXXABI::emitVirtualInherit
>> > for (unsigned I = 0, E = VBGlobals.VBTables->size(); I != E; ++I) {
>> > const VPtrInfo *VBT = (*VBGlobals.VBTables)[I];
>> > llvm::GlobalVariable *GV = VBGlobals.Globals[I];
>> > - emitVBTableDefinition(*VBT, RD, GV);
>> > + if (GV->isDeclaration())
>> > + emitVBTableDefinition(*VBT, RD, GV);
>> > }
>> > }
>> >
>> > @@ -1609,6 +1610,9 @@ MicrosoftCXXABI::getAddrOfVBTable(const
>> > else if (RD->hasAttr<DLLExportAttr>())
>> > GV->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
>> >
>> > + if (!GV->hasExternalLinkage())
>> > + emitVBTableDefinition(VBT, RD, GV);
>> > +
>> > return GV;
>> > }
>> >
>> >
>> > Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=227796&r1=227795&r2=227796&view=diff
>> >
>> > ==============================================================================
>> > --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
>> > +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Feb 2 04:22:20 2015
>> > @@ -4689,6 +4689,9 @@ static void ProcessDeclAttribute(Sema &S
>> > break;
>> >
>> > // Microsoft attributes:
>> > + case AttributeList::AT_MsNoVTable:
>> > + handleSimpleAttribute<MsNoVTableAttr>(S, D, Attr);
>> > + break;
>> > case AttributeList::AT_MsStruct:
>> > handleSimpleAttribute<MsStructAttr>(S, D, Attr);
>> > break;
>> >
>> > Modified: cfe/trunk/test/Parser/MicrosoftExtensions.cpp
>> > URL:
>> > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/MicrosoftExtensions.cpp?rev=227796&r1=227795&r2=227796&view=diff
>> >
>> > ==============================================================================
>> > --- cfe/trunk/test/Parser/MicrosoftExtensions.cpp (original)
>> > +++ cfe/trunk/test/Parser/MicrosoftExtensions.cpp Mon Feb 2 04:22:20
>> > 2015
>> > @@ -339,7 +339,7 @@ void TestProperty() {
>> > //expected-warning at +1 {{C++ operator 'and' (aka '&&') used as a macro
>> > name}}
>> > #define and foo
>> >
>> > -struct __declspec(uuid("00000000-0000-0000-C000-000000000046"))
>> > __declspec(novtable) IUnknown {}; // expected-warning{{__declspec attribute
>> > 'novtable' is not supported}}
>> > +struct __declspec(uuid("00000000-0000-0000-C000-000000000046"))
>> > __declspec(novtable) IUnknown {};
>>
>> I would like to see some tests that ensure it accepts no arguments,
>> and cannot apply to something other than a CXXRecordDecl.
>>
>> Thank you for implementing this!
>>
>> ~Aaron
>>
>> >
>> > typedef bool (__stdcall __stdcall *blarg)(int);
>> >
>> >
>> >
>> > _______________________________________________
>> > cfe-commits mailing list
>> > cfe-commits at cs.uiuc.edu
>> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>
More information about the cfe-commits
mailing list