Commit Graph

107 Commits

Author SHA1 Message Date
David Majnemer 5a1b2045dc [-cxx-abi microsoft] Canonicalize array parameters better
Summary:
More accurately characterize the nature of array parameters. Doing this
removes false back-reference opportunities.  Remove some hacks now that
we characterize these better.

Reviewers: rnk, timurrrr, whunt, cdavis5x

CC: cfe-commits

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

llvm-svn: 190488
2013-09-11 04:44:30 +00:00
Reid Kleckner 1ece9fc806 [ms-cxxabi] Mangle dynamic initializer stubs the same way MSVC does
Summary: Dynamic initializers are mangled as ??__E <name> YAXXZ.

Reviewers: timurrrr

CC: cfe-commits

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

llvm-svn: 190434
2013-09-10 20:43:12 +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
Charles Davis b5a214e4f3 Add ms_abi and sysv_abi attribute handling.
Based on a patch by Benno Rice!

llvm-svn: 189644
2013-08-30 04:39:01 +00:00
Reid Kleckner 78af0708b7 Delete CC_Default and use the target default CC everywhere
Summary:
Makes functions with implicit calling convention compatible with
function types with a matching explicit calling convention.  This fixes
things like calls to qsort(), which has an explicit __cdecl attribute on
the comparator in Windows headers.

Clang will now infer the calling convention from the declarator.  There
are two cases when the CC must be adjusted during redeclaration:
1. When defining a non-inline static method.
2. When redeclaring a function with an implicit or mismatched
convention.

Fixes PR13457, and allows clang to compile CommandLine.cpp for the
Microsoft C++ ABI.

Excellent test cases provided by Alexander Zinenko!

Reviewers: rsmith

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

llvm-svn: 189412
2013-08-27 23:08:25 +00:00
David Majnemer 08177c5053 [-cxx-abi microsoft] Remove ArgIndex, we handle all template argument kinds!
TemplateExpansion cannot happen here because MSVC doesn't mangle
anything but the fully substituted template arguments.

llvm-svn: 189325
2013-08-27 08:21:25 +00:00
Timur Iskhodzhanov f46993e40a Fix virtual destructor mangling when using "-cxx-abi microsoft" on x64
llvm-svn: 189214
2013-08-26 10:32:04 +00:00
David Majnemer a4778cc2f1 [-cxx-abi microsoft] Unnamed types are mangled less wrong
llvm-svn: 189208
2013-08-26 02:35:51 +00:00
David Majnemer f0a84f200a Parse: Do not 'HandleTopLevelDecl' on templated functions.
Summary:
HandleTopLevelDecl on a templated function leads us to try and mangle
it.

Reviewers: rsmith

Reviewed By: rsmith

CC: cfe-commits

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

llvm-svn: 188536
2013-08-16 08:29:13 +00:00
David Majnemer 6dda7bb08d [-cxx-abi microsoft] Mangle member pointers better
Summary:
There were several things going wrong:
- We mangled in useless qualifiers like "volatile void" return types.
- We didn't propagate 64-bit pointer markers sufficiently.
- We mangled qualifiers belonging to the pointee incorrectly.

This fixes PR16844 and PR16848.

Reviewers: rnk, whunt

Reviewed By: rnk

CC: cfe-commits

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

llvm-svn: 188450
2013-08-15 08:13:23 +00:00
David Majnemer e9cab2faa6 Fix typo in comment.
Thanks Kim Gräsman!

llvm-svn: 188257
2013-08-13 09:17:25 +00:00
David Majnemer 8eaab6ff8e [-cxx-abi microsoft] Mangle __uuidof correctly into template parameters
Summary:
It seems that __uuidof introduces a global extern "C" declaration of
type __s_GUID.  However, our implementation of __uuidof does not provide
such a declaration and thus must open-code the mangling for __uuidof in
template parameters.

This allows us to codegen scoped COM pointers and other such things.

This fixes PR16836.
Depends on D1356.

Reviewers: rnk, cdavis5x, rsmith

Reviewed By: rnk

CC: cfe-commits

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

llvm-svn: 188252
2013-08-13 06:32:20 +00:00
David Majnemer e8fdc06e0d [-cxx-abi microsoft] Mangle TemplateArgument::Declaration for references
Summary:
Properly mangle declarations showing up in template arguments that are
reference parameters.  Fun-fact: undname cannot handle these!

Reviewers: rnk, cdavis5x

Reviewed By: rnk

CC: cfe-commits

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

llvm-svn: 188245
2013-08-13 01:25:35 +00:00
David Majnemer a2724ae4b3 Revert "[-cxx-abi microsoft] Mangle UUIDs correctly, stick them in the proper section"
This commit reverts r188053.

It is breaking the build bots.

llvm-svn: 188055
2013-08-09 05:56:24 +00:00
David Majnemer 94a76b64e0 [-cxx-abi microsoft] Mangle UUIDs correctly, stick them in the proper section
We mangled them like:
L___uuid_12345678-1234-1234-1234-123456789abc

We should've mangled them like:
__GUID_12345678_1234_1234_1234_123456789abc

Furthermore, they are external symbols.

llvm-svn: 188053
2013-08-09 05:09:04 +00:00
David Majnemer 89594f3733 [ms-cxxabi] Properly mangle member pointers
There were three things missing from the original implementation:

- We would omit the 'E' qualifier for members int 64-bit mode.
- We would not exmaine the qualifiers in 'IsMember' mode.
- We didn't generate the correct backref to the base class.

llvm-svn: 187753
2013-08-05 22:43:06 +00:00
David Majnemer 0db0ca4364 [ms-cxxabi] Handle template-template arguments
Template-template arguments appear to be a rather simple encoding of the
template's templated tag type.

llvm-svn: 187751
2013-08-05 22:26:46 +00:00
David Majnemer ae465ef7cc [ms-cxxabi] Mangle nullptr template arguments
MSVC mangles nullptr template arguments identically to zero literals.

llvm-svn: 187741
2013-08-05 21:33:59 +00:00
Timur Iskhodzhanov df7e7fb642 Add MicrosoftVFTableContext to AST
llvm-svn: 187409
2013-07-30 09:46:19 +00:00
Reid Kleckner e7de47efbe [ms-cxxabi] Emit linkonce complete dtors in TUs that need them
Based on Peter Collingbourne's destructor patches.

Prior to this change, clang was considering ?1 to be the complete
destructor and the base destructor, which was wrong.  This lead to
crashes when clang tried to emit two LLVM functions with the same name.

In this ABI, TUs with non-inline dtors might not emit a complete
destructor.  They are emitted as inline thunks in TUs that need them,
and they always delegate to the base dtors of the complete class and its
virtual bases.  This change uses the DeferredDecls machinery to emit
complete dtors as needed.

Currently in clang try body destructors can catch exceptions thrown by
virtual base destructors.  In the Microsoft C++ ABI, clang may not have
the destructor definition, in which case clang won't wrap the virtual
virtual base destructor calls in a try-catch.  Diagnosing this in user
code is TODO.

Finally, for classes that don't use virtual inheritance, MSVC always
calls the base destructor (?1) directly.  This is a useful code size
optimization that avoids emitting lots of extra thunks or aliases.
Implementing it also means our existing tests continue to pass, and is
consistent with MSVC's output.

We can do the same for Itanium by tweaking GetAddrOfCXXDestructor, but
it will require further testing.

Reviewers: rjmccall

CC: cfe-commits

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

llvm-svn: 186828
2013-07-22 13:51:44 +00:00
Reid Kleckner c16c44714b [ms-cxxabi] Don't consider function templates for name backrefs
They don't seem to be used for back references, presumably because a
function template is unlikely to reoccur, while a class template name
may reoccur as a type.

This fixes a mangling issue for llvm::hash_combine() in Hashing.h.

Reviewers: timurrrr

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

llvm-svn: 186233
2013-07-13 00:43:39 +00:00
Eli Friedman 8978a9dd0a Get rid of dead/useless code for block mangling.
llvm-svn: 185989
2013-07-10 01:13:27 +00:00
Reid Kleckner f0ae35b88c [ms-cxxabi] Mangle variadic template parameter packs
Unlike Itanium, there is no code to indicate the beginning of a
parameter pack.  I tested this with MSVC 2013, which is the only version
that implements variadic templates so far.

This is needed to compile APInt.cpp for the MS C++ ABI.

Reviewers: timurrrr

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

llvm-svn: 185454
2013-07-02 18:10:07 +00:00
Reid Kleckner 18da98ef99 [ms-cxxabi] Use sugared types in the mangler instead of canonical types
At this point, it's clear that the MSVC mangler uses the type-as-written
instead of the canonical type, so this should bring us closer to MSVC.
The main thrust of this change is to fix the way we mangle decayed array
parameters of function pointer parameters.  With a DecayedType sugar
node, this code can now be much simpler.

Fixes PR16096.

This also fixes a separate issue that Richard spotted in review.
Because separate declarations of the same entity can be spelled and
mangled differently, MSVC always mangles the earliest declaration in an
attempt to avoid link errors.  Clang now does the same.

Reviewers: rsmith

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

llvm-svn: 184777
2013-06-24 19:21:52 +00:00
Reid Kleckner 7810af0a43 [ms-cxxabi] Emit and install appropriately mangled vbtables
In Itanium, dynamic classes have one vtable with several different
address points for dynamic base classes that can't share vtables.

In the MS C++ ABI, each vbtable that can't be shared gets its own
symbol, similar to how ctor vtables work in Itanium.  However, instead
of mangling the subobject offset into the symbol, the unique portions of
the inheritance path are mangled into the symbol to make it unique.

This patch implements the MSVC 2012 scheme for forming unique vbtable
symbol names.  MSVC 2010 use the same mangling with a different subset
of the path.  Implementing that mangling and possibly others is TODO.

Each vbtable is an array of i32 offsets from the vbptr that points to it
to another virtual base subobject.  The first entry of a vbtable always
points to the base of the current subobject, implying that it is the
same no matter which parent class contains it.

Reviewers: rjmccall

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

llvm-svn: 184309
2013-06-19 15:20:38 +00:00
Reid Kleckner fdf02a7abd Remove unused #include <map>
llvm-svn: 182500
2013-05-22 18:46:02 +00:00
Reid Kleckner 7dafb23232 Use StringMap in MicrosoftMangle to resolve FIXME.
llvm-svn: 182488
2013-05-22 17:16:39 +00:00
David Blaikie 014399c0de Fix clang -Werror build due to -Wreorder violation introduced in r181825
llvm-svn: 181834
2013-05-14 21:31:46 +00:00
Reid Kleckner 369f316ef8 [ms-cxxabi] Mangle in an implicit 'E' for certain types on win64
Most of the complexity of this patch is figuring out which types get the
qualifier and which don't.  If we implement __ptr32/64, then we should
check the qualifier instead of assuming all pointers are 64-bit.

This fixes PR13792.

Patch by Warren Hunt!

llvm-svn: 181825
2013-05-14 20:30:42 +00:00
Rafael Espindola 3ae00052cd Cleanup handling of UniqueExternalLinkage.
This patch renames getLinkage to getLinkageInternal. Only code that
needs to handle UniqueExternalLinkage specially should call this.

Linkage, as defined in the c++ standard, is provided by
getFormalLinkage. It maps UniqueExternalLinkage to ExternalLinkage.

Most places in the compiler actually want isExternallyVisible, which
handles UniqueExternalLinkage as internal.

llvm-svn: 181677
2013-05-13 00:12:11 +00:00
Ben Langmuir 3b4c30b7e7 CodeGen for CapturedStmts
EmitCapturedStmt creates a captured struct containing all of the captured
variables, and then emits a call to the outlined function.  This is similar in
principle to EmitBlockLiteral.

GenerateCapturedFunction actually produces the outlined function.  It is based
on GenerateBlockFunction, but is much simpler.  The function type is determined
by the parameters that are in the CapturedDecl.

Some changes have been added to this patch that were reviewed as part of the
serialization patch and moving the parameters to the captured decl.

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

llvm-svn: 181536
2013-05-09 19:17:11 +00:00
Peter Collingbourne 2816c023ea [ms-cxxabi] Fix a number of bugs in the mangler.
This includes the following fixes:
 - Implement 4 subtly different variants of qualifier mangling and use them
   in what I believe are the right places.
 - Fix handling of array types.  Previously we were always decaying them,
   which is wrong if the type appears as a template argument, pointee,
   referent etc.
Fixes PR13182.

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

llvm-svn: 180250
2013-04-25 04:25:40 +00:00
Reid Kleckner 5fdaac15ec [ms-cxxabi] Add "$$C" when mangling template arg QualTypes
Credit goes to Timur Iskhodzhanov for finding the problem and solution.

llvm-svn: 179093
2013-04-09 12:47:38 +00:00
Reid Kleckner e7e64d8a7b [ms-cxxabi] Mangle vector types
Summary:
The only vector types a user can pass from MSVC code to clang code are
the ones from *mmintrin.h, so we only have to match the MSVC mangling
for these types.  MSVC mangles the __m128 family of types as tag types,
which we match.  For other vector types, we emit a unique tag type
mangling that won't match anything produced by MSVC.

Reviewers: rjmccall

CC: chandlerc, timurrrr, cfe-commits

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

llvm-svn: 178036
2013-03-26 16:56:59 +00:00
Reid Kleckner 831b71e0b5 [ms-cxxabi] Mangle function pointer template arguments correctly
Reviewers: rjmccall

CC: timurrrr, llvm-commits

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

llvm-svn: 177589
2013-03-20 22:29:42 +00:00
Reid Kleckner 5251886cd8 [ms-cxxabi] Fix assertion on unhandled function template arg types
This code was changed in r158376 to get template argument source info
for better diagnostics, but the current code asserts for any kind of
unsupported template argument before it can issue a diagnostic.  This change
goes back to the Itanium implementation of isTemplate() and puts the argument
index into the diagnostic instead of a source location.

Review URL: http://llvm-reviews.chandlerc.com/D553

llvm-svn: 177471
2013-03-20 01:40:23 +00:00
Timur Iskhodzhanov 57cbe5c790 Better support for constructors with -cxx-abi microsoft, partly fixes PR12784
llvm-svn: 176186
2013-02-27 13:46:31 +00:00
David Blaikie 6adc78e0df Replace TypeLoc llvm::cast support to be well-defined.
The TypeLoc hierarchy used the llvm::cast machinery to perform undefined
behavior by casting pointers/references to TypeLoc objects to derived types
and then using the derived copy constructors (or even returning pointers to
derived types that actually point to the original TypeLoc object).

Some context is in this thread:
http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-December/056804.html
Though it's spread over a few months which can be hard to read in the mail
archive.

llvm-svn: 175462
2013-02-18 22:06:02 +00:00
Timur Iskhodzhanov ee6bc53365 Emit virtual/deleting destructors properly with -cxx-abi microsoft, PR15058
llvm-svn: 175045
2013-02-13 08:37:51 +00:00
Guy Benyei 610541989a Add OpenCL samplers as Clang builtin types and check sampler related restrictions.
llvm-svn: 174601
2013-02-07 10:55:47 +00:00
Guy Benyei 1b4fb3e08b Implement OpenCL event_t as Clang builtin type, including event_t related OpenCL restrictions (OpenCL 1.2 spec 6.9)
llvm-svn: 172973
2013-01-20 12:31:11 +00:00
Guy Benyei d8a08ea98d Re-commit r170428 changes with Linux style file endings.
Add OpenCL images as clang builtin types.

llvm-svn: 170432
2012-12-18 14:38:23 +00:00
Guy Benyei 11169dded0 Revert changes from r170428, as I accidentally changed the line endings of these files to Windows style.
llvm-svn: 170431
2012-12-18 14:30:41 +00:00
Guy Benyei b13abb952a Add OpenCL images as clang builtin types.
llvm-svn: 170428
2012-12-18 12:30:03 +00:00
Benjamin Kramer ea70eb30a0 Pull the Attr iteration parts out of Attr.h, so including DeclBase.h doesn't pull in all the generated Attr code.
Required to pull some functions out of line, but this shouldn't have a perf impact.
No functionality change.

llvm-svn: 169092
2012-12-01 15:09:41 +00:00
Timur Iskhodzhanov 6732d350ef [-cxx-abi microsoft] Also spill the argument-back-references context when mangling templates
llvm-svn: 168862
2012-11-29 08:58:47 +00:00
Timur Iskhodzhanov 09848e709c Fix PR14413 - incorrect mangling of anonymous namespaces with -cxx-abi microsoft
llvm-svn: 168583
2012-11-26 08:55:48 +00:00
Matt Beaumont-Gay c08fa18596 Fix PR14321, a crash when Clang is built with GCC 4.7 at -O1 or greater.
GCC 4.7 reuses stack slots fairly aggressively, which exposes more temporary
lifetime bugs.

No new test, this was caught by the existing CodeGenCXX/mangle-ms-templates.cpp.

llvm-svn: 168124
2012-11-16 01:14:52 +00:00
Nico Weber 3ad723ca2e [ms] Make mangleIntegerLiteral less aware of exact type of the literal.
Integer literal mangling does not actually depend on exact type of the literal.
This will simplify calling mangleIntegerLiteral when literal type is not known,
for example, when sizes or offsets are mangled as integer literals.

Also, call mangleNumber instead of directly printing mangled values of 0/1, to
avoid this knowledge from being in multiple places.

Patch from Evgeny Eltsin!

llvm-svn: 167878
2012-11-13 22:09:44 +00:00
Nico Weber 5ed8a8a06a [ms] Implement int64_t version of mangleNumber() in terms of the APSInt version.
No intended functionality change.

llvm-svn: 167602
2012-11-09 00:05:56 +00:00