Commit Graph

1575 Commits

Author SHA1 Message Date
Eric Christopher 5bd52c1b3e Make this test a bit more robust for debug info changes.
llvm-svn: 151518
2012-02-27 08:22:57 +00:00
Richard Smith 0d1f3cb1b5 Special members which are defaulted or deleted on their first declaration are
trivial if the implicit declaration would be. Don't forget to set the Trivial
flag on the special member as well as on the class. It doesn't seem ideal that
we have two separate mechanisms for storing this information, but this patch
does not attempt to address that.

This leaves us in an interesting position where the has_trivial_X trait for a
class says 'yes' for a deleted but trivial X, but is_trivially_Xable says 'no'.
This seems to be what the standard requires.

llvm-svn: 151465
2012-02-26 00:31:33 +00:00
Sebastian Redl aeac3ff82a Richard Smith pointed out that there already is a proposal for init list mangling.
llvm-svn: 151462
2012-02-25 22:59:28 +00:00
Sebastian Redl 4a7eab2545 CodeGen support for global variables of type std::initializer_list<X>.
This emits a backing array with internal linkage and fills it with data,
then has the initializer_list point at the array. Dynamic initialization
and global destructors are correctly supported.

What doesn't work is nested initializer_lists. I have no idea how to
get them to work, either. However, these should be very rare, and so
I'll just call it a known bug and declare generalized initializers
DONE!

llvm-svn: 151457
2012-02-25 20:51:20 +00:00
Sebastian Redl dadc06494d Better mangling for new-expressions. Also, although we can't mangle arbitrary initializer lists yet (we will need this), turn the crash into a controlled error.
llvm-svn: 151455
2012-02-25 20:51:07 +00:00
Douglas Gregor 4f283c8b20 For the purposes of building LLVM types, a forward-declared
enumeration type with a fixed underlying type is complete. Fixes
<rdar://problem/10916155>.

llvm-svn: 151403
2012-02-24 22:40:36 +00:00
Douglas Gregor 3a08c1cd3b Two minor, related fixes for template instantiation with blocks:
- Make sure that the block expression is instantiation-dependent if the
    block is in a dependent context
  - Make sure that the C++ 'this' expression gets captured even if we
  don't rebuild the AST node during template instantiation. This would
  also have manifested as a bug for lambdas.

Fixes <rdar://problem/10832617>.

llvm-svn: 151372
2012-02-24 17:41:38 +00:00
Chad Rosier f62290a19b Reapply r151172 - Unwind path cleanup for array new list initializers - with a
test case that only runs on debug builds.

llvm-svn: 151311
2012-02-24 00:13:55 +00:00
Richard Smith c899892485 PR12067: When emitting an evaluated constant structure in C++11 mode, don't
forget the vptrs.

llvm-svn: 151245
2012-02-23 08:33:23 +00:00
Rafael Espindola 8093fdfab1 Two fixes to how we compute visibility:
* Handle some situations where we should never make a decl more visible,
  even when merging in an explicit visibility.

* Handle attributes in members of classes that are explicitly specialized.

Thanks Nico for the report and testing, Eric for the initial review, and dgregor
for the awesome test27 :-)

llvm-svn: 151236
2012-02-23 04:17:32 +00:00
Chad Rosier 1a3c3d4537 Revert r151172: Unwind path cleanup for array new list initializers.
llvm-svn: 151203
2012-02-22 21:36:06 +00:00
Sebastian Redl 674c77e555 Unwind path cleanup for array new list initializers.
llvm-svn: 151172
2012-02-22 17:37:59 +00:00
Sebastian Redl f862eb6a9f CodeGen for array new list initializers. Doesn't correctly clean up in the face of exceptions yet.
llvm-svn: 151171
2012-02-22 17:37:52 +00:00
NAKAMURA Takumi 0716b50db6 test/CodeGenCXX/thiscall-struct-return.cpp: Relax expressions for -Asserts.
llvm-svn: 151126
2012-02-22 03:36:54 +00:00
Aaron Ballman 3c42441b2c Adding support for Microsoft's thiscall calling convention. Clang side of the patch.
llvm-svn: 151122
2012-02-22 03:04:13 +00:00
Douglas Gregor 6f88e5e0d7 Implement non-internal linkage for lambda closure types that need a
stable mangling, since these lambdas can end up in multiple
translation units. Sema is responsible for deciding when this is the
case, because it's already responsible for choosing the mangling
number.

llvm-svn: 151029
2012-02-21 04:17:39 +00:00
Douglas Gregor 926410d2db Implement name mangling for lambda expressions that occur within the
initializers of data members (both static and non-static).

llvm-svn: 151017
2012-02-21 02:22:07 +00:00
Douglas Gregor 7fcbd902b4 Implement name mangling for lambda expressions that occur within the
default arguments of function parameters. This simple-sounding task is
complicated greatly by two issues:

  (1) Default arguments aren't actually a real context, so we need to
  maintain extra state within lambda expressions to track when a
  lambda was actually in a default argument.
  (2) At the time that we parse a default argument, the FunctionDecl
  doesn't exist yet, so lambda closure types end up in the enclosing
  context. It's not clear that we ever want to change that, so instead
  we introduce the notion of the "effective" context of a declaration
  for the purposes of name mangling.

llvm-svn: 151011
2012-02-21 00:37:24 +00:00
Nick Lewycky 4506204640 Emit the exact size for the invariant intrinsics.
llvm-svn: 151010
2012-02-21 00:26:58 +00:00
Douglas Gregor 43c3f28c23 Make sure that we set up the right declaration contexts when creating
and introducing the lambda closure type and its function call
operator. Previously, we assumed that the lambda closure type would
land directly in the current context, and not some parent context (as
occurs with linkage specifications). Thanks to Richard for the test case.

llvm-svn: 150987
2012-02-20 20:47:06 +00:00
Douglas Gregor d5c4844e02 When we resolve the type of an 'auto' variable, clear out the linkage
of that variable; it will need to be recomputed with the resolved
type.

llvm-svn: 150984
2012-02-20 20:05:29 +00:00
Douglas Gregor 6379854457 Basic support for name mangling of C++11 lambda expressions. Because
name mangling in the Itanium C++ ABI for lambda expressions is so
dependent on context, we encode the number used to encode each lambda
as part of the lambda closure type, and maintain this value within
Sema.

Note that there are a several pieces still missing:
  - We still get the linkage of lambda expressions wrong
  - We aren't properly numbering or mangling lambda expressions that
  occur in default function arguments or in data member initializers.
  - We aren't (de-)serializing the lambda numbering tables

llvm-svn: 150982
2012-02-20 19:44:39 +00:00
Eric Christopher 66562a4a54 Remove the type retaining from the clang frontend. This is now
handled by the caching and rauw. Also fix one cache that wasn't
being added to highlighted by this patch. Update all testcases
accordingly.

This should fix the deall failure.

llvm-svn: 150977
2012-02-20 18:05:24 +00:00
Benjamin Kramer 8558da1930 Harden test against for operator new(unsigned int).
llvm-svn: 150932
2012-02-19 16:20:58 +00:00
Sebastian Redl d026dc499c Make heap-allocation of std::initializer_list 'work'.
llvm-svn: 150931
2012-02-19 16:03:09 +00:00
Sebastian Redl 4e04dd1979 Make std::initializer_list member initializers 'work'.
llvm-svn: 150930
2012-02-19 15:41:54 +00:00
Sebastian Redl 8eb351d72e Get recursive initializer lists to work and add a test. Codegen of std::initializer_list is now complete. Onward to array new.
llvm-svn: 150926
2012-02-19 12:28:02 +00:00
Sebastian Redl 99f6616470 Add a testcase for using objects with list-constructors, and fix a Sema crash by repeating an old hack.
llvm-svn: 150925
2012-02-19 12:27:56 +00:00
Sebastian Redl 1d197174a2 Add a testcase to show that temporaries from the initializer list are destroyed correctly.
llvm-svn: 150924
2012-02-19 12:27:51 +00:00
Sebastian Redl ca89d6841a Add a testcase for start+end implementations of std::initializer_list.
llvm-svn: 150923
2012-02-19 12:27:47 +00:00
Eric Christopher 1c3785aae9 Add in a caching mechanism so that forward declarations are replaced
with full types if they exist.

rdar://10809898 and rdar://10209967 and rdar://10400981

llvm-svn: 150858
2012-02-18 00:50:17 +00:00
Richard Smith 132bea96ad Don't emit optimization-specific intrinsic at -O0.
llvm-svn: 150838
2012-02-17 20:12:52 +00:00
Sebastian Redl c83ed8248e Basic code generation support for std::initializer_list.
We now generate temporary arrays to back std::initializer_list objects
initialized with braces. The initializer_list is then made to point at
the array. We support both ptr+size and start+end forms, although
the latter is untested.

Array lifetime is correct for temporary std::initializer_lists (e.g.
call arguments) and local variables. It is untested for new expressions
and member initializers.

Things left to do:
Massively increase the amount of testing. I need to write tests for
start+end init lists, temporary objects created as a side effect of
initializing init list objects, new expressions, member initialization,
creation of temporary objects (e.g. std::vector) for initializer lists,
and probably more.
Get lifetime "right" for member initializers and new expressions. Not
that either are very useful.
Implement list-initialization of array new expressions.

llvm-svn: 150803
2012-02-17 08:42:25 +00:00
Richard Smith 08a5144621 The clang half of r150794: after the construction of a global or static const
variable ends, if the variable has a trivial destructor and no mutable
subobjects then emit an llvm.invariant.start call for it. globalopt knows to
make the variable const when evaluating this.

llvm-svn: 150798
2012-02-17 07:31:37 +00:00
Richard Smith e070fd2ac8 Bug fix: do not emit static const local variables with mutable members
as constants.

Refactor and simplify all the separate checks for whether a type can be
emitted as a constant.

llvm-svn: 150793
2012-02-17 06:48:11 +00:00
Richard Smith ae819500a1 When performing IRGen on a global, emit it as a constant if:
1) It has a const-qualified type, and
 2) It has no mutable members, and
 3) It has no dynamic initialization, and
 4) It has trivial destruction.
Remove the unnecessary requirement that the type be POD. This allows us to
mark all constexpr objects with no mutable members as 'constant'.

llvm-svn: 150792
2012-02-17 04:54:50 +00:00
Richard Smith 14a941380a Make sure all remaining parts of the constant evaluator are aware that an array
can be represented by an LValue, and use that to simplify the code a little.

llvm-svn: 150789
2012-02-17 03:35:37 +00:00
Douglas Gregor 355efbb2e0 Rework the Sema/AST/IRgen dance for the lambda closure type's
conversion to function pointer. Rather than having IRgen synthesize
the body of this function, we instead introduce a static member
function "__invoke" with the same signature as the lambda's
operator() in the AST. Sema then generates a body for the conversion
to function pointer which simply returns the address of __invoke. This
approach makes it easier to evaluate a call to the conversion function
as a constant, makes the linkage of the __invoke function follow the
normal rules for member functions, and may make life easier down the
road if we ever want to constexpr'ify some of lambdas.

Note that IR generation is responsible for filling in the body of
__invoke (Sema just adds a dummy body), because the body can't
generally be expressed in C++.

Eli, please review!

llvm-svn: 150783
2012-02-17 03:02:34 +00:00
Richard Smith 5d108606cc PR12012: Fix a regression in r150419 where we would try (and fail) to
zero-initialize class types with virtual bases when constant-evaluating an
initializer.

llvm-svn: 150770
2012-02-17 00:44:16 +00:00
Eric Christopher 4c006e557d Reapply r150631:
"Add a completed/incomplete type difference. This allows us to have
    partial types for contexts and forward decls while allowing us to
    complete types later on for debug purposes.

    This piggy-backs on the metadata replacement and rauw changes
    for temporary nodes and takes advantage of the incremental
    support I added in earlier. This allows us to, if we decide,
    to limit adding methods and variables to structures in order
    to limit the amount of debug information output into a .o file.

    The caching is a bit complicated though so any thoughts on
    untangling that are welcome."

with a fix:

 - Remove all RAUW during type construction by adding stub versions
   of types that we later complete.

and some TODOs:

 - Add an RAUW cache for forward declared types so that we can replace
   them at the end of compilation.
 - Remove the code that updates on completed types because we no
   longer need to have that happen. We emit incomplete types on
   purpose and only want to know when we want to complete them.

llvm-svn: 150752
2012-02-16 22:54:45 +00:00
Eli Friedman b971d49765 Elide copy construction in new expressions. PR11757.
llvm-svn: 150738
2012-02-16 22:45:48 +00:00
Richard Smith 4297375561 C++11 allows unions to have static data members. Remove the corresponding
restriction and add some tests.

llvm-svn: 150721
2012-02-16 20:41:22 +00:00
Eric Christopher 9a89705d03 Revert "Add a completed/incomplete type difference. This allows us to have"
This reverts commit 9a68d4584afcd0853b930bd80235b58736e785b4.

llvm-svn: 150637
2012-02-15 23:51:20 +00:00
Eric Christopher 7381907e65 Add a completed/incomplete type difference. This allows us to have
partial types for contexts and forward decls while allowing us to
complete types later on for debug purposes.

This piggy-backs on the metadata replacement and rauw changes
for temporary nodes and takes advantage of the incremental
support I added in earlier. This allows us to, if we decide,
to limit adding methods and variables to structures in order
to limit the amount of debug information output into a .o file.

The caching is a bit complicated though so any thoughts on
untangling that are welcome.

llvm-svn: 150631
2012-02-15 23:25:18 +00:00
John McCall c62bb39142 Split reinterpret_casts of member pointers out from CK_BitCast; this
is general goodness because representations of member pointers are
not always equivalent across member pointer types on all ABIs
(even though this isn't really standard-endorsed).

Take advantage of the new information to teach IR-generation how
to do these reinterprets in constant initializers.  Make sure this
works when intermingled with hierarchy conversions (although
this is not part of our motivating use case).  Doing this in the
constant-evaluator would probably have been better, but that would
require a *lot* of extra structure in the representation of
constant member pointers:  you'd really have to track an arbitrary
chain of hierarchy conversions and reinterpretations in order to
get this right.  Ultimately, this seems less complex.  I also
wasn't quite sure how to extend the constant evaluator to handle
foldings that we don't actually want to treat as extended
constant expressions.

llvm-svn: 150551
2012-02-15 01:22:51 +00:00
Richard Smith 1bfe068e71 PR11650: Implement resolution of core issue 1301. Value initialization can't be
used to construct an object of union type with a deleted default constructor
(plus fixes for some related value-initialization corner cases).

llvm-svn: 150502
2012-02-14 21:14:13 +00:00
Eli Friedman 4412b23e7e Add a coverage test for lambda expression IRGen.
llvm-svn: 150458
2012-02-14 03:07:59 +00:00
Richard Smith 6331c408b5 Deal with a horrible C++11 special case. If a non-literal type has a constexpr
constructor, and that constructor is used to initialize an object of static
storage duration such that all members and bases are initialized by constant
expressions, constant initialization is performed. In this case, the object
can still have a non-trivial destructor, and if it does, we must emit a dynamic
initializer which performs no initialization and instead simply registers that
destructor.

llvm-svn: 150419
2012-02-13 22:16:19 +00:00
Eric Christopher d752e3d280 Testcase for previous commit.
PR11970.

llvm-svn: 150389
2012-02-13 15:04:15 +00:00
Eric Christopher 8a41bd88d7 Temporarily walk back a few of my recent debug info limiting changes
while reworking how we handle wanting to emit only parts of structures.

Fixes PR11970.

llvm-svn: 150388
2012-02-13 14:56:11 +00:00