Commit Graph

435 Commits

Author SHA1 Message Date
Reid Kleckner 489cfe1401 [COFF] Don't try to emit weak aliases on COFF
This comes up when a derived class destructor is equivalent to a base
class destructor defined in the same TU, and we try to alias them.

A COFF weak alias cannot satisfy a normal undefined symbol reference
from another TU. The other TU must also mark the referenced symbol as
weak, and we can't rely on that.

Clang already has a special case here for dllexport, but we failed to
realize that the problem also applies to other non-discardable symbols
such as those from explicit template instantiations.

Fixes PR25477.

llvm-svn: 252659
2015-11-10 22:23:58 +00:00
Evgeniy Stepanov 6b2a61d3a5 Revert "Always_inline codegen rewrite" and 2 follow-ups.
Revert "Update cxx-irgen.cpp test to allow signext in alwaysinline functions."
Revert "[CodeGen] Remove wrapper-free always_inline functions from COMDATs"
Revert "Always_inline codegen rewrite."

Reason for revert: PR24793.

llvm-svn: 247620
2015-09-14 21:35:16 +00:00
David Blaikie 2a791d7d21 [opaque pointer type] Fix a few uses of PointerType::getElementType in favor of uses of types already available elsewhere
These are a few cleanups I happened to have from trying to go in a
different direction recently, so just flushing them out while I have
them.

llvm-svn: 247593
2015-09-14 18:38:22 +00:00
David Blaikie aff29d3031 Revert "[opaque pointer type] update for LLVM API change"
This was the wrong direction to take anyway (because ultimately the
GlobalValue needed the pointee type again and /it/ used
PointerType::getElementType eventually anyway)... let's go a different way.

This reverts commit r236161.

llvm-svn: 247586
2015-09-14 18:02:04 +00:00
Evgeniy Stepanov 93db40a147 Always_inline codegen rewrite.
Current implementation may end up emitting an undefined reference for
an "inline __attribute__((always_inline))" function by generating an
"available_externally alwaysinline" IR function for it and then failing to
inline all the calls. This happens when a call to such function is in dead
code. As the inliner is an SCC pass, it does not process dead code.

Libc++ relies on the compiler never emitting such undefined reference.

With this patch, we emit a pair of
1. internal alwaysinline definition (called F.alwaysinline)
2a. A stub F() { musttail call F.alwaysinline }
  -- or, depending on the linkage --
2b. A declaration of F.

The frontend ensures that F.inlinefunction is only used for direct
calls, and the stub is used for everything else (taking the address of
the function, really). Declaration (2b) is emitted in the case when
"inline" is meant for inlining only (like __gnu_inline__ and some
other cases).

This approach, among other nice properties, ensures that alwaysinline
functions are always internal, making it impossible for a direct call
to such function to produce an undefined symbol reference.

This patch is based on ideas by Chandler Carruth and Richard Smith.

llvm-svn: 247494
2015-09-12 01:07:37 +00:00
Evgeniy Stepanov 67037ee21e Revert "Specify target triple in alwaysinline tests."
Revert "Always_inline codegen rewrite."

Breaks gdb & lldb tests.
Breaks on Fedora 22 x86_64.

llvm-svn: 247491
2015-09-11 23:48:37 +00:00
Evgeniy Stepanov 072e83500e Always_inline codegen rewrite.
Current implementation may end up emitting an undefined reference for
an "inline __attribute__((always_inline))" function by generating an
"available_externally alwaysinline" IR function for it and then failing to
inline all the calls. This happens when a call to such function is in dead
code. As the inliner is an SCC pass, it does not process dead code.

Libc++ relies on the compiler never emitting such undefined reference.

With this patch, we emit a pair of
1. internal alwaysinline definition (called F.alwaysinline)
2a. A stub F() { musttail call F.alwaysinline }
  -- or, depending on the linkage --
2b. A declaration of F.

The frontend ensures that F.inlinefunction is only used for direct
calls, and the stub is used for everything else (taking the address of
the function, really). Declaration (2b) is emitted in the case when
"inline" is meant for inlining only (like __gnu_inline__ and some
other cases).

This approach, among other nice properties, ensures that alwaysinline
functions are always internal, making it impossible for a direct call
to such function to produce an undefined symbol reference.

This patch is based on ideas by Chandler Carruth and Richard Smith.

llvm-svn: 247465
2015-09-11 20:29:07 +00:00
John McCall 7f416cc426 Compute and preserve alignment more faithfully in IR-generation.
Introduce an Address type to bundle a pointer value with an
alignment.  Introduce APIs on CGBuilderTy to work with Address
values.  Change core APIs on CGF/CGM to traffic in Address where
appropriate.  Require alignments to be non-zero.  Update a ton
of code to compute and propagate alignment information.

As part of this, I've promoted CGBuiltin's EmitPointerWithAlignment
helper function to CGF and made use of it in a number of places in
the expression emitter.

The end result is that we should now be significantly more correct
when performing operations on objects that are locally known to
be under-aligned.  Since alignment is not reliably tracked in the
type system, there are inherent limits to this, but at least we
are no longer confused by standard operations like derived-to-base
conversions and array-to-pointer decay.  I've also fixed a large
number of bugs where we were applying the complete-object alignment
to a pointer instead of the non-virtual alignment, although most of
these were hidden by the very conservative approach we took with
member alignment.

Also, because IRGen now reliably asserts on zero alignments, we
should no longer be subject to an absurd but frustrating recurring
bug where an incomplete type would report a zero alignment and then
we'd naively do a alignmentAtOffset on it and emit code using an
alignment equal to the largest power-of-two factor of the offset.

We should also now be emitting much more aggressive alignment
attributes in the presence of over-alignment.  In particular,
field access now uses alignmentAtOffset instead of min.

Several times in this patch, I had to change the existing
code-generation pattern in order to more effectively use
the Address APIs.  For the most part, this seems to be a strict
improvement, like doing pointer arithmetic with GEPs instead of
ptrtoint.  That said, I've tried very hard to not change semantics,
but it is likely that I've failed in a few places, for which I
apologize.

ABIArgInfo now always carries the assumed alignment of indirect and
indirect byval arguments.  In order to cut down on what was already
a dauntingly large patch, I changed the code to never set align
attributes in the IR on non-byval indirect arguments.  That is,
we still generate code which assumes that indirect arguments have
the given alignment, but we don't express this information to the
backend except where it's semantically required (i.e. on byvals).
This is likely a minor regression for those targets that did provide
this information, but it'll be trivial to add it back in a later
patch.

I partially punted on applying this work to CGBuiltin.  Please
do not add more uses of the CreateDefaultAligned{Load,Store}
APIs; they will be going away eventually.

llvm-svn: 246985
2015-09-08 08:05:57 +00:00
Naomi Musgrave 866af2d6d1 Refactored dtor sanitizing into EHScopeStack
Summary:
Dtor sanitization handled amidst other dtor cleanups,
between cleaning bases and fields. Sanitizer call pushed onto
stack of cleanup operations.

Reviewers: eugenis, kcc

Differential Revision: http://reviews.llvm.org/D12022

Refactoring dtor sanitizing emission order.

- Support multiple inheritance by poisoning after
 member destructors are invoked, and before base
 class destructors are invoked.
- Poison for virtual destructor and virtual bases.
- Repress dtor aliasing when sanitizing in dtor.
- CFE test for dtor aliasing, and repression of aliasing in dtor
 code generation.
- Poison members on field-by-field basis, with collective poisoning
 of trivial members when possible.
- Check msan flags and existence of fields, before dtor sanitizing,
 and when determining if aliasing is allowed.
- Testing sanitizing bit fields.

llvm-svn: 246815
2015-09-03 23:02:30 +00:00
Andrey Bokhanko cab5858e1b PR17829: Proper diagnostic of mangled names conflicts
Proper diagnostic and resolution of mangled names conflicts between C++ methods
and C functions. This patch implements support for functions/methods only;
support for variables is coming separately.

Differential Revision: http://reviews.llvm.org/D11297

llvm-svn: 246438
2015-08-31 13:20:44 +00:00
Hans Wennborg bb4f962ad6 Get the dll storage class right for structors of classes exported/imported via explicit instantiation (PR23667)
This is a follow-up to r238266. It turned out structors are codegened through a different path,
and didn't get the storage class set in EmitGlobalFunctionDefinition.

llvm-svn: 238443
2015-05-28 17:44:56 +00:00
Duncan P. N. Exon Smith d6616acb2c CGCXX: Use cast in getAddrOfCXXStructor()
All callers should be passing `CXXConstructorDecl` or
`CXXDestructorDecl` here, so use `cast<>` instead of `dyn_cast<>` when
setting up the `GlobalDecl`.

llvm-svn: 236651
2015-05-06 22:18:39 +00:00
David Blaikie 881b23402e [opaque pointer type] update for LLVM API change
llvm-svn: 236161
2015-04-29 21:22:47 +00:00
Nico Weber f867c17ab5 Don't use a doc comment in a function body.
llvm-svn: 225701
2015-01-12 21:22:27 +00:00
Kostya Serebryany 5f1b4e8f58 ignore -mconstructor-aliases when adding field paddings for asan
Summary:
When we are adding field paddings for asan even an empty dtor has to remain in the code,
so we ignore -mconstructor-aliases if the paddings are going to be added.

Test Plan: added a test

Reviewers: rsmith, rnk, rafael

Reviewed By: rafael

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D6038

llvm-svn: 220986
2014-10-31 19:01:02 +00:00
David Majnemer 4b9d964925 CodeGen: Don't form weak dllexport aliases
The MS linker cannot do anything interesting with these, it doesn't make
sense to emit them.

This fixes PR21373.

Differential Revision: http://reviews.llvm.org/D5986

llvm-svn: 220595
2014-10-24 22:05:27 +00:00
Rafael Espindola e04a17da81 Allow dllexport alias to base destructors.
We used to avoid these, but it looks like we did so just because we were
not handling dllexport alias correctly.

Dario Domizioli fixed that, so allow these aliases.

Based on a patch by Dario Domizioli!

llvm-svn: 219206
2014-10-07 13:34:42 +00:00
Rafael Espindola 5368618d72 Reduce code duplication a bit more. NFC.
llvm-svn: 217811
2014-09-15 19:34:18 +00:00
Rafael Espindola 91f68b43c3 Move emitCXXStructor to CGCXXABI.
A followup patch will address the code duplication.

llvm-svn: 217807
2014-09-15 19:20:10 +00:00
Rafael Espindola 02b77f4248 Create a emitCXXStructor function and make the existing emitCXXConstructor and
emitCXXDestructor static helpers.

A next patch will make it a helper in CGCXXABI.

llvm-svn: 217804
2014-09-15 18:46:13 +00:00
Rafael Espindola 1ac0ec86b7 Merge GetAddrOfCXXConstructor and GetAddrOfCXXDonstructor. NFC.
llvm-svn: 217598
2014-09-11 15:42:06 +00:00
Rafael Espindola 8d2a19b478 Handle constructors and destructors a bit more uniformly in CodeGen.
There were code paths that are duplicated for constructors and destructors just
because we have both CXXCtorType and CXXDtorsTypes.

This patch introduces an unified enum and reduces code deplication a bit.

llvm-svn: 217383
2014-09-08 16:01:27 +00:00
Rafael Espindola 27c60b512a Update for llvm API change.
Aliases in llvm now hold an arbitrary expression.

llvm-svn: 210063
2014-06-03 02:42:01 +00:00
Hans Wennborg 853ae94660 Start adding support for dllimport/dllexport on classes (PR11170)
This implements the central part of support for dllimport/dllexport on
classes: allowing the attribute on class declarations, inheriting it
to class members, and forcing emission of exported members. It's based
on Nico Rieck's patch from http://reviews.llvm.org/D1099.

This patch doesn't propagate dllexport to bases that are template
specializations, which is an interesting problem. It also doesn't
look at the rules when redeclaring classes with different attributes,
I'd like to do that separately.

Differential Revision: http://reviews.llvm.org/D3877

llvm-svn: 209908
2014-05-30 16:59:42 +00:00
Craig Topper 8a13c4180e [C++11] Use 'nullptr'. CodeGen edition.
llvm-svn: 209272
2014-05-21 05:09:00 +00:00
Rafael Espindola 234405bd0f Update for llvm api change.
llvm-svn: 209077
2014-05-17 21:30:14 +00:00
Rafael Espindola 6172277e9f Update for llvm api change.
llvm-svn: 209074
2014-05-17 19:58:16 +00:00
Rafael Espindola b2633b9793 Update for llvm api change.
Now that llvm cannot represent alias cycles, we have to diagnose erros just
before trying to close the cycle. This degrades the errors a bit. The real
solution is what it was before: if we want to provide good errors for these
cases, we have to be able to find a clang level decl given a mangled name
and produce the error from Sema.

llvm-svn: 209008
2014-05-16 19:35:48 +00:00
Rafael Espindola 9750ce7ebd Update for llvm API change.
llvm-svn: 208984
2014-05-16 13:34:28 +00:00
Rafael Espindola 2ae250c36a Use auto to avoid duplicating the type.
llvm-svn: 208374
2014-05-09 00:08:36 +00:00
Rafael Espindola e033c8c58c Cleanup setFunctionDefinitionAttributes.
Use more specific type, update comments and name style.

llvm-svn: 208328
2014-05-08 15:26:12 +00:00
Aaron Ballman 574705ed7f [C++11] Replacing CXXRecordDecl iterators bases_begin() and bases_end() with iterator_range bases(). Updating all of the usages of the iterators with range-based for loops.
llvm-svn: 203803
2014-03-13 15:41:46 +00:00
Aaron Ballman e8a8baef44 [C++11] Replacing RecordDecl iterators field_begin() and field_end() with iterator_range fields(). Updating all of the usages of the iterators with range-based for loops.
llvm-svn: 203355
2014-03-08 20:12:42 +00:00
Rafael Espindola 191b95125a Don't produce an alias between destructors with different calling conventions.
Fixes pr19007.

llvm-svn: 203007
2014-03-05 21:04:41 +00:00
Reid Kleckner 340ad862d9 [ms-abi] Always generate complete constructors in the Microsoft C++ ABI
Fixes PR18435, where we generated a base ctor instead of a complete
ctor, and so failed to construct virtual bases when constructing the
complete object.

llvm-svn: 199160
2014-01-13 22:57:31 +00:00
Rafael Espindola 94abb8ffed Avoid adding some decls to DeferredDeclsToEmit.
Before this patch GetOrCreateLLVMFunction would add a decl to
DeferredDeclsToEmit even when it was being called by the function trying to
emit that decl.

llvm-svn: 196753
2013-12-09 04:29:47 +00:00
Alp Toker f6a24ce40f Fix a tranche of comment, test and doc typos
llvm-svn: 196510
2013-12-05 16:25:25 +00:00
Joerg Sonnenberger 374c2bb37e Adjust r194296 to not apply the alias replacement for externally
available always-inline functions. This breaks libc++'s locale
implementation. Code generation for this case should be fixed, but this
is a stop gap fix for clang 3.4.

llvm-svn: 195501
2013-11-22 21:34:35 +00:00
Rafael Espindola d967badc64 Don't use alias from derived dtor to base dtor at -O0.
This patch disables aliasing (and rauw) of derived dtors to base dtors at -O0.
This optimization can have a negative impact on the debug quality.

This was a latent bug for some time with local classes, but got noticed when it
was generalized and broke gdb's destrprint.exp.

llvm-svn: 194618
2013-11-13 23:20:45 +00:00
Rafael Espindola 7cf6f00f56 Drop windows specific handling of equivalent destructors.
Now that the relevant tests use -mconstructor-aliases and the missing
features have been implemented, we can just drop this.

No functionality change.

llvm-svn: 194595
2013-11-13 18:46:32 +00:00
Rafael Espindola 129d313c8d Avoid producing mismatched comdats.
The problem was that given

template<typename T>
struct foo {
  ~foo() {}
};
template class foo<int>;

We would produce a alias, creating a comdat with D0 and D1, since the symbols
have to be weak. Another TU is not required to have a explicit template
instantiation definition or an explict template instantiation declaration and
for

template<typename T>
struct foo {
  ~foo() {}
};
foo<int> a;

we would produce a comdat with only one symbol in it.

llvm-svn: 194520
2013-11-12 22:06:46 +00:00
Rafael Espindola b15683e635 Fix pr17875.
The assert this patch deletes was valid only when aliasing D2 to D1, not when
looking at a base class. Since the assert was in the path where we had already
decided to not produce an alias, just drop it.

llvm-svn: 194411
2013-11-11 19:35:06 +00:00
Rafael Espindola 961ba21a47 Don't emit an internal destructor that is identical to an external one.
It is not safe to emit alias to undefined (not supported by ELF or COFF), but
it is safe to rauw when the alias would have been internal or linkonce_odr.

llvm-svn: 194307
2013-11-09 01:57:21 +00:00
Rafael Espindola 23d3751170 Use rauw for all discardable aliases, not just linkonce_odr.
llvm-svn: 194296
2013-11-08 23:46:20 +00:00
Rafael Espindola e2ec6faa36 If a linkonce_odr dtor/ctor is identical to another one, just rauw.
Unlike an alias a rauw is always safe, so we don't need to avoid this
optimization when the replacement is not know to be available in every TU.

llvm-svn: 194288
2013-11-08 22:59:46 +00:00
Rafael Espindola 5fb3a13ba7 Fix the -cxx-abi microsoft -mconstructor-aliases combination.
On the microsoft ABI clang is producing one weak_odr and one linkonce_odr
destructor, which is reasonable since only one is required.

The fix is simply to move the assert past the special case treatment of
linkonce_odr.

llvm-svn: 194158
2013-11-06 19:18:55 +00:00
Rafael Espindola 2e2995bf50 Produce direct calls instead of alias to linkonce_odr functions.
This is a small optimization on linux, but should help more on windows
where msvc only outputs one destructor if there would be two identical ones.

llvm-svn: 194095
2013-11-05 21:37:29 +00:00
Timur Iskhodzhanov 5877663622 Fix vbtable indices when a class shares the vbptr with a non-virtual base
llvm-svn: 194082
2013-11-05 15:54:58 +00:00
Rafael Espindola b5ac86865a Revert "Produce direct calls instead of alias to linkonce_odr functions."
This reverts commit r194046.
Debugging a bootstrap issue.

llvm-svn: 194047
2013-11-05 05:29:54 +00:00
Rafael Espindola 5d79a51a45 Produce direct calls instead of alias to linkonce_odr functions.
This is a small optimization on linux, but should help more on windows
where msvc only outputs one destructor if there would be two identical ones.

llvm-svn: 194046
2013-11-05 05:22:36 +00:00