Commit Graph

26 Commits

Author SHA1 Message Date
Reid Kleckner c0dca6ded7 MS ABI: Implement #pragma vtordisp() and clang-cl /vdN
These features are new in VS 2013 and are necessary in order to layout
std::ostream correctly.  Currently we have an ABI incompatibility when
self-hosting with the 2013 stdlib in our convertible_fwd_ostream wrapper
in gtest.

This change adds another implicit attribute, MSVtorDispAttr, because
implicit attributes are currently the best way to make sure the
information stays on class templates through instantiation.

Reviewers: majnemer

Differential Revision: http://llvm-reviews.chandlerc.com/D2746

llvm-svn: 201274
2014-02-12 23:50:26 +00:00
David Majnemer 4bb0980d96 MS ABI: Add support for #pragma pointers_to_members
Introduce a notion of a 'current representation method' for
pointers-to-members.

When starting out, this is set to 'best case' (representation method is
chosen by examining the class, selecting the smallest representation
that would work given the class definition or lack thereof).

This pragma allows the translation unit to dictate exactly what
representation to use, similar to how the inheritance model keywords
operate.

N.B.  PCH support is forthcoming.

Differential Revision: http://llvm-reviews.chandlerc.com/D2723

llvm-svn: 201105
2014-02-10 19:50:15 +00:00
Reid Kleckner 96f8f9339d MS ABI: Mangle member pointer template arguments
Member pointers are mangled as they would be represented at runtime.
They can be a single integer literal, single decl, or a tuple with some
more numbers tossed in.  With Clang today, most of those numbers will be
zero because we reject pointers to members of virtual bases.

This change required moving VTableContextBase ownership from
CodeGenVTables to ASTContext, because mangling now depends on vtable
layout.

I also hoisted the inheritance model helpers up to be inline static
methods of MSInheritanceAttr.  This makes the AST code that deals with
member pointers much more readable.

MSVC doesn't appear to have stable manglings of null member pointers:
- Null data memptrs in function templates have a mangling collision with
  the first field of a non-polymorphic single inheritance class.
- The mangling of null data memptrs changes if you add casts.
- Large null function memptrs in class templates crash MSVC.

Clang uses the class template mangling for null data memptrs and the
function template mangling for null function memptrs to deal with this.

Reviewers: majnemer

Differential Revision: http://llvm-reviews.chandlerc.com/D2695

llvm-svn: 200857
2014-02-05 17:27:08 +00:00
Reid Kleckner bd63b33854 [ms-cxxabi] Raise aggregate memptr alignment to 8 for x86_32
With this change, we give different results for __alignof than MSVC, but
our record layout is compatible.

Some data member pointers also now have a size that is not a multiple of
their alignment.

Fixes PR18618.

Reviewers: majnemer

Differential Revision: http://llvm-reviews.chandlerc.com/D2669

llvm-svn: 200585
2014-01-31 22:28:50 +00:00
David Majnemer 2c4e00ac1c Sema: Diagnose improper application of inheritance keywords
We would previously allow inappropriate inheritance keywords to appear
on class declarations.  We would also allow inheritance keywords on
templates which were not fully specialized; this was divergent from
MSVC.

Differential Revision: http://llvm-reviews.chandlerc.com/D2585

llvm-svn: 200423
2014-01-29 22:07:36 +00:00
David Majnemer 1cdd96d6ad Revert "Revert r199416, "MS ABI: Improve selection of an inheritance model""
This reverts commit r199475 (which reverted r199416) with fixes for the
breakages.

We wouldn't lock an inheritance model if we saw a pointer-to-member
formed as a result of the address-of operator.

llvm-svn: 199482
2014-01-17 09:01:00 +00:00
NAKAMURA Takumi 5c486cf3f3 Revert r199416, "MS ABI: Improve selection of an inheritance model"
It broke tests for targeting x86_64-pc-win32:

    Clang Tools :: clang-modernize/LoopConvert/array.cpp
    Clang :: CodeGenCXX/2010-05-10-Var-DbgInfo.cpp
    Clang :: CodeGenCXX/member-call-parens.cpp
    Clang :: CodeGenCXX/ptr-to-datamember.cpp
    Clang :: SemaTemplate/instantiate-function-1.cpp

llvm-svn: 199475
2014-01-17 07:33:47 +00:00
David Majnemer 37054dd4e7 MS ABI: Improve selection of an inheritance model
The MSVC ABI is rather finicky about the exact representation of it's
pointer-to-member representation.  The exact position of when and where
it will go with one representation versus another appears to be when it
desires the pointer-to-member to be complete.

To properly implement this in clang, do several things:
- Give up on tracking the polymorphic nature of the class.  It isn't
  useful to Sema and is only pertinent when choosing CodeGen-time
  details like whether the field-offset can be 0 instead of -1.
- Insist on locking-in the inheritance model when we ask our
  pointer-to-member type to be complete.  From there, grab the
  underlying CXXRecordDecl and try to make *that* complete.  Once we've
  done this, we can calculate it's inheritance model and apply it using
  an attribute.

N.B. My first bullet point is a lie.  We will eventually care about the
specifics of whether or not a CXXRecordDecl is or is not polymorphic
because MSVC compatible mangling of such things depends on it.  However,
I believe we will handle this in a rather different way.

llvm-svn: 199416
2014-01-16 20:05:57 +00:00
Chandler Carruth 5553d0d4ca Sort all the #include lines with LLVM's utils/sort_includes.py which
encodes the canonical rules for LLVM's style. I noticed this had drifted
quite a bit when cleaning up LLVM, so wanted to clean up Clang as well.

llvm-svn: 198686
2014-01-07 11:51:46 +00:00
Aaron Ballman 8edb5c2081 Refactor the Microsoft inheritance attribute handling so that it no longer has special treatment. Also fixes a minor bug where the attributes were being parsed as though they were GNU-style attributes when they were in fact keyword attributes.
llvm-svn: 197629
2013-12-18 23:44:18 +00:00
Reid Kleckner d8110b6558 [ms-cxxabi] Implement guard variables for static initialization
Static locals requiring initialization are not thread safe on Windows.
Unfortunately, it's possible to create static locals that are actually
externally visible with inline functions and templates.  As a result, we
have to implement an initialization guard scheme that is compatible with
TUs built by MSVC, which makes thread safety prohibitively difficult.

MSVC's scheme is that every function that requires a guard gets an i32
bitfield.  Each static local is assigned a bit that indicates if it has
been initialized, up to 32 bits, at which point a new bitfield is
created.  MSVC rejects inline functions with more than 32 static locals,
and the externally visible mangling (?_B) only allows for one guard
variable per function.

On Eli's recommendation, I used MangleNumberingContext to track which
bit each static corresponds to.

Implements PR16888.

Reviewers: rjmccall, eli.friedman

Differential Revision: http://llvm-reviews.chandlerc.com/D1416

llvm-svn: 190427
2013-09-10 20:14:30 +00:00
Reid Kleckner 2341ae3856 [ms-cxxabi] Implement member pointer emission and dereferencing
Summary:
Handles all inheritance models for both data and function member
pointers.

Also implements isZeroInitializable() and refactors some of the null
member pointer code.

MSVC supports converting member pointers through virtual bases, which
clang does not (yet?) support.  Implementing that extension is covered
by http://llvm.org/15713

Reviewers: rjmccall

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D613

llvm-svn: 179305
2013-04-11 18:13:19 +00:00
Benjamin Kramer 08db461ca7 Make helpers static & 80 cols.
llvm-svn: 178767
2013-04-04 17:07:04 +00:00
Reid Kleckner 08a39a686e [ms-cxxabi] Rename enum and remove dead case per Jordan's suggestion
The IHM_ prefix was a fairly gross abbreviation to try to hit three
characters for uniqueness.

llvm-svn: 178551
2013-04-02 17:40:19 +00:00
Reid Kleckner daa0f3176e [ms-cxxabi] Remove unused variable
llvm-svn: 178550
2013-04-02 17:24:20 +00:00
Reid Kleckner be377cd518 [ms-cxxabi] Move MS inheritance model calculation into MemberPointerType
Summary:
This makes it possible to share code between lib/AST/MicrosoftCXXABI.cpp
and lib/CodeGen/MicrosoftCXXABI.cpp.  No functionality change.

Also adds comments about the layout of the member pointer structs as I
currently understand them.

Reviewers: rjmccall

CC: timurrrr, cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D590

llvm-svn: 178548
2013-04-02 16:23:57 +00:00
Reid Kleckner 3a52abf553 [ms-cxxabi] Correctly compute the size of member pointers
Summary:
This also relaxes the requirement on Windows that the member pointer
class type be a complete type (http://llvm.org/PR12070).  We still ask
for a complete type to instantiate any templates (MSVC does this), but
if that fails we continue as normal, relying on any inheritance
attributes on the declaration.

Reviewers: rjmccall

CC: triton, timurrrr, cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D568

llvm-svn: 178283
2013-03-28 20:02:56 +00:00
Joao Matos e30771fdbd Revert r163078 per chandlerc's request.
llvm-svn: 163145
2012-09-04 17:18:12 +00:00
Joao Matos 26b2095401 Added a diagnostic for mismatched MS inheritance attributes. Also fixed the incomplete type member pointer size calculation under the MS ABI.
llvm-svn: 163078
2012-09-02 00:13:48 +00:00
Timur Iskhodzhanov c5098ad371 [Windows] Use thiscall as the default calling convention for class methods. PR12785
llvm-svn: 160121
2012-07-12 09:50:54 +00:00
Douglas Gregor e8bbc12152 Extend the ASTContext constructor to delay the initialization of
builtin types (When requested). This is another step toward making
ASTUnit build the ASTContext as needed when loading an AST file,
rather than doing so after the fact. No actual functionality change (yet).

llvm-svn: 138985
2011-09-02 00:18:52 +00:00
Chris Lattner 57540c5be0 fix a bunch of comment typos found by codespell. Patch by
Luis Felipe Strano Moraes!

llvm-svn: 129559
2011-04-15 05:22:18 +00:00
Ken Dyck 316d6f69bc Convert RecordLayout::NonVirtualSize from bit units to CharUnits.
llvm-svn: 124646
2011-02-01 01:52:10 +00:00
Anders Carlsson 60a6263ee8 Move isNearlyEmpty out into the ASTContext so it can be called from CodeGen as well.
llvm-svn: 120137
2010-11-25 01:51:53 +00:00
Charles Davis 31575f758c Add a hook to the CXXABI object to get the default method calling convention.
This isn't used yet, because someone more experienced than I needs to look
at the type system about gutting getCanonicalCallConv().

llvm-svn: 117638
2010-10-29 03:25:11 +00:00
Charles Davis 53c59df2f7 Implement support for member pointers under the Microsoft C++ ABI in the
AST library.

This also adds infrastructure for supporting multiple C++ ABIs in the AST.

llvm-svn: 111117
2010-08-16 03:33:14 +00:00