summaryrefslogtreecommitdiffstats
path: root/test/CodeGenCXX/temporaries.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Support lifetime-extension of conditional temporaries.Richard Smith2018-07-231-3/+95
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337767 91177308-0d34-0410-b5e6-96231b3b80d8
* [clang]: Add support for "-fno-delete-null-pointer-checks"Manoj Gupta2018-07-191-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Support for this option is needed for building Linux kernel. This is a very frequently requested feature by kernel developers. More details : https://lkml.org/lkml/2018/4/4/601 GCC option description for -fdelete-null-pointer-checks: This Assume that programs cannot safely dereference null pointers, and that no code or data element resides at address zero. -fno-delete-null-pointer-checks is the inverse of this implying that null pointer dereferencing is not undefined. This feature is implemented in as the function attribute "null-pointer-is-valid"="true". This CL only adds the attribute on the function. It also strips "nonnull" attributes from function arguments but keeps the related warnings unchanged. Corresponding LLVM change rL336613 already updated the optimizations to not treat null pointer dereferencing as undefined if the attribute is present. Reviewers: t.p.northover, efriedma, jyknight, chandlerc, rnk, srhines, void, george.burgess.iv Reviewed By: jyknight Subscribers: drinkcat, xbolva00, cfe-commits Differential Revision: https://reviews.llvm.org/D47894 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337433 91177308-0d34-0410-b5e6-96231b3b80d8
* Restructure checking for, and warning on, lifetime extension.Richard Smith2018-07-171-27/+0
| | | | | | | | | | | | | This change implements C++ DR1696, which makes initialization of a reference member of a class from a temporary object ill-formed. The standard wording here is imprecise, but we interpret it as meaning that any time a mem-initializer would result in lifetime extension, the program is ill-formed. This reinstates r337226, reverted in r337255, with a fix for the InitializedEntity alignment problem that was breaking ARM buildbots. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337329 91177308-0d34-0410-b5e6-96231b3b80d8
* Temporarily revert r337226 "Restructure checking for, and warning on, ↵Florian Hahn2018-07-171-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | lifetime extension." This change breaks on ARM because pointers to clang::InitializedEntity are only 4 byte aligned and do not have 3 bits to store values. A possible solution would be to change the fields in clang::InitializedEntity to enforce a bigger alignment requirement. The error message is llvm/include/llvm/ADT/PointerIntPair.h:132:3: error: static_assert failed "PointerIntPair with integer size too large for pointer" static_assert(IntBits <= PtrTraits::NumLowBitsAvailable, include/llvm/ADT/PointerIntPair.h:73:13: note: in instantiation of template class 'llvm::PointerIntPairInfo<const clang::InitializedEntity *, 3, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *> >' requested here Value = Info::updateInt(Info::updatePointer(0, PtrVal), llvm/include/llvm/ADT/PointerIntPair.h:51:5: note: in instantiation of member function 'llvm::PointerIntPair<const clang::InitializedEntity *, 3, (anonymous namespace)::LifetimeKind, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *>, llvm::PointerIntPairInfo<const clang::InitializedEntity *, 3, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *> > >::setPointerAndInt' requested here setPointerAndInt(PtrVal, IntVal); ^ llvm/tools/clang/lib/Sema/SemaInit.cpp:6237:12: note: in instantiation of member function 'llvm::PointerIntPair<const clang::InitializedEntity *, 3, (anonymous namespace)::LifetimeKind, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *>, llvm::PointerIntPairInfo<const clang::InitializedEntity *, 3, llvm::PointerLikeTypeTraits<const clang::InitializedEntity *> > >::PointerIntPair' requested here return {Entity, LK_Extended}; Full log here: http://lab.llvm.org:8011/builders/clang-cmake-armv7-global-isel/builds/1330 http://lab.llvm.org:8011/builders/clang-cmake-armv7-full/builds/1394 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337255 91177308-0d34-0410-b5e6-96231b3b80d8
* Restructure checking for, and warning on, lifetime extension.Richard Smith2018-07-171-27/+0
| | | | | | | | | | This change implements C++ DR1696, which makes initialization of a reference member of a class from a temporary object ill-formed. The standard wording here is imprecise, but we interpret it as meaning that any time a mem-initializer would result in lifetime extension, the program is ill-formed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337226 91177308-0d34-0410-b5e6-96231b3b80d8
* DR1213: element access on an array xvalue or prvalue produces an xvalue. In theRichard Smith2016-12-051-0/+30
| | | | | | | | | | | | | | | latter case, a temporary array object is materialized, and can be lifetime-extended by binding a reference to the member access. Likewise, in an array-to-pointer decay, an rvalue array is materialized before being converted into a pointer. This caused IR generation to stop treating file-scope array compound literals as having static storage duration in some cases in C++; that has been rectified by modeling such a compound literal as an lvalue. This also improves clang's compatibility with GCC for those cases. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@288654 91177308-0d34-0410-b5e6-96231b3b80d8
* Update Clang tests to handle explicitly typed load changes in LLVM.David Blaikie2015-02-271-3/+3
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@230795 91177308-0d34-0410-b5e6-96231b3b80d8
* Update Clang tests to handle explicitly typed gep changes in LLVM.David Blaikie2015-02-271-11/+11
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@230783 91177308-0d34-0410-b5e6-96231b3b80d8
* CodeGen: static constexpr data members should have a linkonce_odr initDavid Majnemer2015-02-191-8/+8
| | | | | | | | | Classes can be defined in multiple translation units. This means that the static constexpr data members should have identical initializers in all translation units. Implement this by giving the reference temporary linkonce_odr linkage. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@229900 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix temporary lifetime extension from an initializer using braced "functional"Richard Smith2015-01-101-0/+7
| | | | | | | cast notation T{...} when T is a reference type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225571 91177308-0d34-0410-b5e6-96231b3b80d8
* Mark C++ reference parameters as dereferenceableHal Finkel2014-07-181-9/+9
| | | | | | | | | | | | | | Because references must be initialized using some evaluated expression, they must point to something, and a callee can assume the reference parameter is dereferenceable. Taking advantage of a new attribute just added to LLVM, mark them as such. Because dereferenceability in addrspace(0) implies nonnull in the backend, we don't need both attributes. However, we need to know the size of the object to use the dereferenceable attribute, so for incomplete types we still emit only nonnull. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213386 91177308-0d34-0410-b5e6-96231b3b80d8
* PR20227: materialize a temporary when dynamic_casting a class prvalue to aRichard Smith2014-07-081-0/+15
| | | | | | | reference type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212551 91177308-0d34-0410-b5e6-96231b3b80d8
* Add 'nonnull' parameter or return attribute when producing an llvm pointer ↵Nick Lewycky2014-05-281-10/+10
| | | | | | type in a function type where the C++ type is a reference. Update the tests. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209723 91177308-0d34-0410-b5e6-96231b3b80d8
* AST: Update reference temporary manglingDavid Majnemer2014-05-061-26/+26
| | | | | | | | | | | | | | | Summary: Update our mangling to match the discussion on cxx-abi-dev. This involves using a seq-id instead of an optional number. Reviewers: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D3631 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208140 91177308-0d34-0410-b5e6-96231b3b80d8
* CHECK-LABEL-ify some code gen tests to improve diagnostic experience when ↵Stephen Lin2013-08-151-12/+12
| | | | | | tests fail. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188447 91177308-0d34-0410-b5e6-96231b3b80d8
* Testcase for PR14130, which was probably fixed by r183859.Richard Smith2013-07-041-0/+8
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185613 91177308-0d34-0410-b5e6-96231b3b80d8
* PR16263: Implement current direction of core issue 1376. Binding a reference toRichard Smith2013-06-151-0/+28
| | | | | | | | | | | | the result of a cast-to-reference-type lifetime-extends the object to which the reference inside the cast binds. This requires us to look for subobject adjustments on both the inside and the outside of the MaterializeTemporaryExpr when looking for a temporary to lifetime-extend (which we also need for core issue 616, and possibly 1213). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184024 91177308-0d34-0410-b5e6-96231b3b80d8
* Reapply r183721, reverted in r183776, with a fix for a bug in the former (weRichard Smith2013-06-121-7/+110
| | | | | | | | | | | | | | | | | | | | | | | | were lacking ExprWithCleanups nodes in some cases where the new approach to lifetime extension needed them). Original commit message: Rework IR emission for lifetime-extended temporaries. Instead of trying to walk into the expression and dig out a single lifetime-extended entity and manually pull its cleanup outside the expression, instead keep a list of the cleanups which we'll need to emit when we get to the end of the full-expression. Also emit those cleanups early, as EH-only cleanups, to cover the case that the full-expression does not terminate normally. This allows IR generation to properly model temporary lifetime when multiple temporaries are extended by the same declaration. We have a pre-existing bug where an exception thrown from a temporary's destructor does not clean up lifetime-extended temporaries created in the same expression and extended to automatic storage duration; that is not fixed by this patch. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183859 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r183721. It caused cleanups to be delayed too long in some cases.Richard Smith2013-06-111-81/+7
| | | | | | | Testcase to follow. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183776 91177308-0d34-0410-b5e6-96231b3b80d8
* Rework IR emission for lifetime-extended temporaries. Instead of trying to walkRichard Smith2013-06-111-7/+81
| | | | | | | | | | | | | | | | | | into the expression and dig out a single lifetime-extended entity and manually pull its cleanup outside the expression, instead keep a list of the cleanups which we'll need to emit when we get to the end of the full-expression. Also emit those cleanups early, as EH-only cleanups, to cover the case that the full-expression does not terminate normally. This allows IR generation to properly model temporary lifetime when multiple temporaries are extended by the same declaration. We have a pre-existing bug where an exception thrown from a temporary's destructor does not clean up lifetime-extended temporaries created in the same expression and extended to automatic storage duration; that is not fixed by this patch. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183721 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove some unreachable (and wrong) code and replace it with an assertion.Richard Smith2013-06-041-0/+22
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183206 91177308-0d34-0410-b5e6-96231b3b80d8
* Convert some Unicode whitespace to ASCII whitespace.Richard Smith2013-06-031-4/+4
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183116 91177308-0d34-0410-b5e6-96231b3b80d8
* Do not walk through member-accesses on bitfields when looking for the objectRichard Smith2013-06-031-0/+12
| | | | | | | | | which is lifetime-extended by a reference binding. An additional temporary is created for such a bitfield access (although we have no explicit AST representation for it). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183095 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix handling of pointers-to-members and comma expressions whenRichard Smith2013-06-031-1/+47
| | | | | | | lifetime-extending temporaries in reference bindings. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183089 91177308-0d34-0410-b5e6-96231b3b80d8
* Update the tests.Bill Wendling2013-01-311-3/+3
| | | | | | | | This update coincides with r174110. That change ordered the attributes alphabetically. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174111 91177308-0d34-0410-b5e6-96231b3b80d8
* Modify the tests for the (sorted) order that the attributes come out as now.Bill Wendling2013-01-291-3/+3
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173762 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix some wrong-code bugs in implicitly-defined assignment operators:Richard Smith2012-11-131-0/+21
| | | | | | | | - In C++11, perform overload resolution over all assignment operators, rather than just looking for copy/move assignment operators. - Clean up after temporaries produced by operator= immediately, rather than accumulating them until the end of the function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@167798 91177308-0d34-0410-b5e6-96231b3b80d8
* In Sema::MaybeBindToTemporary, create a CXXBindTemporaryExpr for anPeter Collingbourne2011-11-271-0/+18
| | | | | | array of objects with non-trivial destructors. PR11365. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@145203 91177308-0d34-0410-b5e6-96231b3b80d8
* Track whether an AggValueSlot is potentially aliased, and do notJohn McCall2011-08-251-3/+3
| | | | | | | | | | | | emit call results into potentially aliased slots. This allows us to properly mark indirect return slots as noalias, at the cost of requiring an extra memcpy when assigning an aggregate call result into a l-value. It also brings us into compliance with the x86-64 ABI. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138599 91177308-0d34-0410-b5e6-96231b3b80d8
* A number of array-related IR-gen cleanups.John McCall2011-07-091-13/+9
| | | | | | | | | | | | | | | - Emit default-initialization of arrays that were partially initialized with initializer lists with a loop, rather than emitting the default initializer N times; - support destroying VLAs of non-trivial type, although this is not yet exposed to users; and - support the partial destruction of arrays initialized with initializer lists when an initializer throws an exception. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134784 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix some obvious bugs in the conditional-cleanup code and then make theJohn McCall2011-01-261-4/+2
| | | | | | | | dtor cleanup use it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124309 91177308-0d34-0410-b5e6-96231b3b80d8
* Reset the lifetime-managed flag between emission of the agg conditionalJohn McCall2010-11-171-0/+32
| | | | | | | | branches. Fixes PR8623. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@119408 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix a bug with binding l-values to elided temporaries, and leave a coupleJohn McCall2010-09-181-1/+18
| | | | | | | | helpful asserts behind. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114250 91177308-0d34-0410-b5e6-96231b3b80d8
* Right, there are *two* cases of pr-value class-type expressions that don'tJohn McCall2010-09-161-0/+34
| | | | | | | | | derive from temporaries of the same type. Black-list member expressions as well. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114071 91177308-0d34-0410-b5e6-96231b3b80d8
* Test hardening.John McCall2010-09-151-6/+6
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113963 91177308-0d34-0410-b5e6-96231b3b80d8
* one piece of code is responsible for the lifetime of every aggregateJohn McCall2010-09-151-0/+104
| | | | | | | | | | | | | | | slot. The easiest way to do that was to bundle up the information we care about for aggregate slots into a new structure which demands that its creators at least consider the question. I could probably be convinced that the ObjC 'needs GC' bit should be rolled into this structure. Implement generalized copy elision. The main obstacle here is that IR-generation must be much more careful about making sure that exactly git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113962 91177308-0d34-0410-b5e6-96231b3b80d8
* Reinstate the fix for PR7556. A silly use of isTrivial() wasDouglas Gregor2010-07-081-0/+18
| | | | | | | suppressing copies of objects with trivial copy constructors. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107857 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert r107828 and r107827, the fix for PR7556, which seems to beDouglas Gregor2010-07-071-18/+0
| | | | | | | breaking bootstrap on Linux. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107837 91177308-0d34-0410-b5e6-96231b3b80d8
* Do not use CXXZeroValueInitExpr for class types. Instead, useDouglas Gregor2010-07-071-0/+18
| | | | | | | | | | CXXConstructExpr/CXXTemporaryObjectExpr/CXXNewExpr as appropriate. Fixes PR7556, and provides a slide codegen improvement when copy-initializing a POD class type from a value-initialized temporary. Previously, we weren't eliding the copy. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107827 91177308-0d34-0410-b5e6-96231b3b80d8
* Tweak test for destruction of copied temporary objectsDouglas Gregor2010-04-251-0/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102291 91177308-0d34-0410-b5e6-96231b3b80d8
* When copying a temporary object to initialize an entity for which theDouglas Gregor2010-04-251-0/+18
| | | | | | | | temporary needs to be bound, bind the copy object. Otherwise, we won't end up calling the destructor for the copy. Fixes Boost.Optional. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102290 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix PR6648 by not creating a temporary with the type of aRafael Espindola2010-03-211-0/+13
| | | | | | | | | | | | | CXXExprWithTemporaries. Not emitting the expression as an aggregate might be the right thing to do, but is orthogonal. Emitting it as an scalar expression will still try to create a temporary for the incomplete type of the CXXExprWithTemporaries and fail. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99134 91177308-0d34-0410-b5e6-96231b3b80d8
* Give explicit template instantiations weak ODR linkage. FormerDouglas Gregor2010-03-131-1/+1
| | | | | | | | | | iterations of this patch gave explicit template instantiation link-once ODR linkage, which permitted the back end to eliminate unused symbols. Weak ODR linkage still requires the symbols to be generated. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98441 91177308-0d34-0410-b5e6-96231b3b80d8
* Re-revert the explicit template instantiation linkage patch. I am beginning ↵Douglas Gregor2010-03-131-1/+1
| | | | | | to look incompetent git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98425 91177308-0d34-0410-b5e6-96231b3b80d8
* Reinstate patch to turn explicit template instantiations into weak symbolsDouglas Gregor2010-03-131-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98424 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert the linkage change for explicit template instantiations; something is ↵Douglas Gregor2010-03-121-1/+1
| | | | | | amiss git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98332 91177308-0d34-0410-b5e6-96231b3b80d8
* Give explicit template instantiations weak linkage (but don't deferDouglas Gregor2010-03-121-1/+1
| | | | | | | them). Fixes PR6578. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98328 91177308-0d34-0410-b5e6-96231b3b80d8
* When binding an lvalue to a reference, we always need to pop temporaries.Anders Carlsson2010-02-041-0/+21
| | | | | | | | | | | | | | With this fix, and the other fixes committed today a make check-all with a clang-built LLVM now gives: Expected Passes : 6933 Expected Failures : 46 Unsupported Tests : 40 Unexpected Failures: 27 which means that we pass 99.96% of all tests :) The resulting 27 tests are all LLVMC tests and seem to be because of differences in the clang and gcc drivers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95313 91177308-0d34-0410-b5e6-96231b3b80d8
* Check in a test case and a nasty workaround for PR6199.Anders Carlsson2010-02-021-0/+18
| | | | git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95076 91177308-0d34-0410-b5e6-96231b3b80d8
* When transforming CXXExprWithTemporaries and CXXBindTemporaryExprDouglas Gregor2009-12-241-0/+14
| | | | | | | | | | expressions (e.g., for template instantiation), just transform the subexpressions and return those, since the temporary-related nodes will be implicitly regenerated. Fixes PR5867, but I said that before... git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92135 91177308-0d34-0410-b5e6-96231b3b80d8