aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaLambda.cpp
AgeCommit message (Collapse)AuthorFilesLines
2017-07-05fix trivial typos in comments; NFCHiroshi Inoue1-1/+1
llvm-svn: 307123
2017-06-13Fix spurious Wunused-lambda-capture warningYi Kong1-5/+11
Summary: Clang emits unused-lambda-capture warning for captures in generic lambdas even though they are actually used. Fixes PR31815. Reviewers: malcolm.parsons, aaron.ballman, rsmith Reviewed By: malcolm.parsons Subscribers: ahatanak, cfe-commits Differential Revision: https://reviews.llvm.org/D33526 llvm-svn: 305315
2017-06-03Added LLVM_FALLTHROUGH to address warning: this statement may fall through. NFC.Galina Kistanova1-0/+1
llvm-svn: 304651
2017-05-24[coroutines] Make generic lambda coroutines workGor Nishanov1-0/+1
Summary: 1. Coroutine cannot be constexpr (added a check in SemaLambda.cpp not to mark coroutine as constexpr) 2. TransformCoroutineBodyStmt should transform ResultDecl and ReturnStmt Reviewers: rsmith, GorNishanov Reviewed By: GorNishanov Subscribers: EricWF, cfe-commits Differential Revision: https://reviews.llvm.org/D33498 llvm-svn: 303764
2017-04-06Fix lambda to block conversion in C++17 by avoiding copy elision for theAlex Lorenz1-4/+3
lambda capture used by the created block The commit r288866 introduced guaranteed copy elision to C++ 17. This unfortunately broke the lambda to block conversion in C++17 (the compiler crashes when performing IRGen). This commit fixes the conversion by avoiding copy elision for the capture that captures the lambda that's used in the block created by the lambda to block conversion process. rdar://31385153 Differential Revision: https://reviews.llvm.org/D31669 llvm-svn: 299646
2017-04-01[NFC, Scoped Enum] Convert Sema::ExpressionEvaluationContext into a scoped EnumFaisal Vali1-8/+9
- also replace direct equality checks against the ConstantEvaluated enumerator with isConstantEvaluted(), in anticipation of adding finer granularity to the various ConstantEvaluated contexts and reinstating certain restrictions on where lambda expressions can occur in C++17. - update the clang tablegen backend that uses these Enumerators, and add the relevant scope where needed. llvm-svn: 299316
2017-03-30Spelling mistakes in comments. NFCI. (PR27635)Simon Pilgrim1-1/+1
llvm-svn: 299083
2017-03-01[Sema] Improve side effect checking for unused-lambda-capture warningMalcolm Parsons1-2/+24
Summary: Don't warn about unused lambda captures that involve copying a value of a type that cannot be trivially copied and destroyed. Fixes PR31977 Reviewers: rsmith, aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D30327 llvm-svn: 296602
2017-02-21Factor out function to determine whether we're performing a templateRichard Smith1-1/+1
instantiation. In preparation for converting the template stack to a more general context stack (so we can include context notes for other kinds of context). llvm-svn: 295686
2017-01-13[Sema] Add warning for unused lambda capturesMalcolm Parsons1-2/+21
Summary: Warn when a lambda explicitly captures something that is not used in its body. The warning is part of -Wunused and can be enabled with -Wunused-lambda-capture. Reviewers: rsmith, arphaman, jbcoe, aaron.ballman Subscribers: Quuxplusone, arphaman, cfe-commits Differential Revision: https://reviews.llvm.org/D28467 llvm-svn: 291905
2017-01-08[cxx1z-constexpr-lambda] Make conversion function constexpr, and teach the ↵Faisal Vali1-1/+1
expression-evaluator to evaluate the static-invoker. This patch has been sitting in review hell since july 2016 and our lack of constexpr lambda support is getting embarrassing (given that I've had a branch that implements the feature (modulo *this capture) for over a year. While in Issaquah I was enjoying shamelessly trying to convince folks of the lie that this was Richard's fault ;) I won't be able to do so in Kona since I won't be attending - so I'm going to aim to have this feature be implemented by then. I'm quite confident of the approach in this patch, which simply maps the static-invoker 'thunk' back to the corresponding call-operator (specialization). Thanks! llvm-svn: 291397
2017-01-07PR23135: Don't instantiate constexpr functions referenced in unevaluated ↵Richard Smith1-0/+1
operands where possible. This implements something like the current direction of DR1581: we use a narrow syntactic check to determine the set of places where a constant expression could be evaluated, and only instantiate a constexpr function or variable if it's referenced in one of those contexts, or is odr-used. It's not yet clear whether this is the right set of syntactic locations; we currently consider all contexts within templates that would result in odr-uses after instantiation, and contexts within list-initialization (narrowing conversions take another victim...), as requiring instantiation. We could in principle restrict the former cases more (only const integral / reference variable initializers, and contexts in which a constant expression is required, perhaps). However, this is sufficient to allow us to accept libstdc++ code, which relies on GCC's behavior (which appears to be somewhat similar to this approach). llvm-svn: 291318
2016-12-14Remove custom handling of array copies in lambda by-value array capture andRichard Smith1-76/+8
copy constructors of classes with array members, instead using ArrayInitLoopExpr to represent the initialization loop. This exposed a bug in the static analyzer where it was unable to differentiate between zero-initialized and unknown array values, which has also been fixed here. llvm-svn: 289618
2016-11-15[OPENMP] Fix for PR30632: Name mangling issue.Alexey Bataev1-3/+4
Reworked fix after comments from Richard Smith. We must skip all CapturedDecl-based contexts when trying to get correct mangling number context. llvm-svn: 286953
2016-11-11Fix for PR28523: unexpected compilation error.Alexey Bataev1-4/+7
Clang emits error message for the following code: ``` template <class F> void parallel_loop(F &&f) { f(0); } int main() { int x; parallel_loop([&](auto y) { { x = y; }; }); } ``` $ clang++ --std=gnu++14 clang_test.cc -o clang_test clang_test.cc:9:7: error: reference to local variable 'x' declared in enclosing function 'main' x = y; ^ clang_test.cc:2:48: note: in instantiation of function template specialization 'main()::(anonymous class)::operator()<int>' requested here template <class F> void parallel_loop(F &&f) { f(0); } ^ clang_test.cc:6:3: note: in instantiation of function template specialization 'parallel_loop<(lambda at clang_test.cc:6:17)>' requested here parallel_loop([&](auto y) { ^ clang_test.cc:5:7: note: 'x' declared here int x; ^ 1 error generated. Patch fixes this issue. llvm-svn: 286584
2016-11-10[Sema] Avoid -Wshadow warnings for shadowed variables thatAlex Lorenz1-0/+3
aren't captured by lambdas with a default capture specifier This commit is a follow-up to r286354. It avoids the -Wshadow warning for variables which shadow variables that aren't captured by lambdas with a default capture specifier. It provides an additional note that points to location of the capture. The old behaviour is preserved with -Wshadow-all or -Wshadow-uncaptured-local. rdar://14984176 Differential Revision: https://reviews.llvm.org/D26448 llvm-svn: 286465
2016-10-14Fix for PR30632: Name mangling issue.Alexey Bataev1-3/+5
There was a bug in the implementation of captured statements. If it has a lambda expression in it and the same lambda expression is used outside the captured region, clang produced an error: ``` error: definition with same mangled name as another definition ``` Here is an example: ``` struct A { template <typename L> void g(const L&) { } }; template<typename T> void f() { { A().g([](){}); } A().g([](){}); } int main() { f<void>(); } ``` Error report: ``` main.cpp:3:10: error: definition with same mangled name as another definition void g(const L&) { } ^ main.cpp:3:10: note: previous definition is here ``` Patch fixes this bug. llvm-svn: 284229
2016-09-30[CUDA] Make lambdas inherit __host__ and __device__ attributes from the ↵Justin Lebar1-1/+6
scope in which they're created. Summary: NVCC compat. Fixes bug 30567. Reviewers: tra Subscribers: cfe-commits, rnk Differential Revision: https://reviews.llvm.org/D25105 llvm-svn: 282880
2016-07-30Reapply r276069 with workaround for MSVC 2013Hubert Tong1-1/+1
llvm-svn: 277286
2016-07-24[Sema] Replace mem_fn with lambdas. NFC.George Burgess IV1-3/+5
I'm told that some optimizers like lambdas a lot more than mem_fn. Given that the readability difference is basically nil, and we seem to use lambdas basically everywhere else, it seems sensible to just use lambdas. llvm-svn: 276577
2016-07-20Revert r276069: MSVC bots not happyHubert Tong1-1/+1
llvm-svn: 276074
2016-07-20Concepts: Create space for requires-clause in TemplateParameterList; NFCHubert Tong1-1/+1
Summary: Space for storing the //constraint-expression// of the //requires-clause// associated with a `TemplateParameterList` is arranged by taking a bit out of the `NumParams` field for the purpose of determining whether there is a //requires-clause// or not, and by adding to the trailing objects tied to the `TemplateParameterList`. An accessor is provided. An appropriate argument is supplied to `TemplateParameterList::Create` at the various call sites. Serialization changes will addressed as the Concepts implementation becomes more solid. Drive-by fix: This change also replaces the custom `FixedSizeTemplateParameterListStorage` implementation with one that follows the interface provided by `llvm::TrailingObjects`. Reviewers: aaron.ballman, faisalv, rsmith Subscribers: cfe-commits, nwilson Differential Revision: https://reviews.llvm.org/D19322 llvm-svn: 276069
2016-06-24Use even more ArrayRefsDavid Majnemer1-2/+2
No functional change is intended, just a small refactoring. llvm-svn: 273650
2016-06-24Use more ArrayRefsDavid Majnemer1-4/+3
No functional change is intended, just a small refactoring. llvm-svn: 273647
2016-06-23Implement p0292r2 (constexpr if), a likely C++1z feature.Richard Smith1-0/+1
llvm-svn: 273602
2016-06-21Re-commit "[Temporary] Add an ExprWithCleanups for each C++ ↵Tim Shen1-6/+5
MaterializeTemporaryExpr." Since D21243 fixes relative clang-tidy tests. This reverts commit a71d9fbd41e99def9159af2b01ef6509394eaeed. llvm-svn: 273312
2016-06-09Revert "[Temporary] Add an ExprWithCleanups for each C++ ↵Tim Shen1-5/+6
MaterializeTemporaryExpr." This reverts r272296, since there are clang-tidy failures that appear to be caused by this change. llvm-svn: 272310
2016-06-09[Temporary] Add an ExprWithCleanups for each C++ MaterializeTemporaryExpr.Tim Shen1-6/+5
These ExprWithCleanups are added for holding a RunCleanupsScope not for destructor calls; rather, they are for lifetime marks. This requires ExprWithCleanups to keep a bit to indicate whether it have cleanups with side effects (e.g. dtor calls). Differential Revision: http://reviews.llvm.org/D20498 llvm-svn: 272296
2016-04-29[Parser] Clear the TemplateParamScope bit of the current scope's flagAkira Hatanaka1-3/+2
if we are parsing a template specialization. This commit makes changes to clear the TemplateParamScope bit and set the TemplateParamParent field of the current scope to null if a template specialization is being parsed. Before this commit, Sema::ActOnStartOfLambdaDefinition would check whether the parent template scope had any decls to determine whether or not a template specialization was being parsed. This wasn't correct since it couldn't distinguish between a real template specialization and a template defintion with an unnamed template parameter (only template parameters with names are added to the scope's decl list). To fix the bug, this commit changes the code to check the pointer to the parent template scope rather than the decl list. rdar://problem/23440346 Differential Revision: http://reviews.llvm.org/D19175 llvm-svn: 267975
2016-03-26[Cxx1z-constexpr-lambda-P0170R1] Support parsing of constexpr specifier ↵Faisal Vali1-4/+17
(and its inference) on lambda expressions Support the constexpr specifier on lambda expressions - and support its inference from the lambda call operator's body. i.e. auto L = [] () constexpr { return 5; }; static_assert(L() == 5); // OK auto Implicit = [] (auto a) { return a; }; static_assert(Implicit(5) == 5); We do not support evaluation of lambda's within constant expressions just yet. Implementation Strategy: - teach ParseLambdaExpressionAfterIntroducer to expect a constexpr specifier and mark the invented function call operator's declarator's decl-specifier with it; Have it emit fixits for multiple decl-specifiers (mutable or constexpr) in this location. - for cases where constexpr is not explicitly specified, have buildLambdaExpr check whether the invented function call operator satisfies the requirements of a constexpr function, by calling CheckConstexprFunctionDecl/Body. Much obliged to Richard Smith for his patience and his care, in ensuring the code is clang-worthy. llvm-svn: 264513
2016-03-23Make sure to perform dependent access checks when instantiating aRichard Smith1-12/+7
lambda-expression. We don't actually instantiate the closure type / operator() in the template in order to produce the closure type / operator() in the instantiation, so this isn't caught by the normal path. llvm-svn: 264184
2016-03-21[Cxx1z] Implement Lambda Capture of *this by Value as [=,*this] (P0018R3)Faisal Vali1-10/+18
Implement lambda capture of *this by copy. For e.g.: struct A { int d = 10; auto foo() { return [*this] (auto a) mutable { d+=a; return d; }; } }; auto L = A{}.foo(); // A{}'s lifetime is gone. // Below is still ok, because *this was captured by value. assert(L(10) == 20); assert(L(100) == 120); If the capture was implicit, or [this] (i.e. *this was captured by reference), this code would be otherwise undefined. Implementation Strategy: - amend the parser to accept *this in the lambda introducer - add a new king of capture LCK_StarThis - teach Sema::CheckCXXThisCapture to handle by copy captures of the enclosing object (i.e. *this) - when CheckCXXThisCapture does capture by copy, the corresponding initializer expression for the closure's data member direct-initializes it thus making a copy of '*this'. - in codegen, when assigning to CXXThisValue, if *this was captured by copy, make sure it points to the corresponding field member, and not, unlike when captured by reference, what the field member points to. - mark feature as implemented in svn Much gratitude to Richard Smith for his carefully illuminating reviews! llvm-svn: 263921
2016-02-02PR24989: Stop trying to use the C++11 rules for lambda return type inference inRichard Smith1-0/+2
C++14 generic lambdas. It conflicts with the C++14 return type deduction mechanism, and results in us failing to actually deduce the lambda's return type in some cases. llvm-svn: 259609
2015-12-27ArrayRef-ize TemplateParameterList. NFCDavid Majnemer1-3/+4
llvm-svn: 256463
2015-12-02Add the `pass_object_size` attribute to clang.George Burgess IV1-0/+6
`pass_object_size` is our way of enabling `__builtin_object_size` to produce high quality results without requiring inlining to happen everywhere. A link to the design doc for this attribute is available at the Differential review link below. Differential Revision: http://reviews.llvm.org/D13263 llvm-svn: 254554
2015-11-11N3922: direct-list-initialization of an auto-typed variable no longer deduces aRichard Smith1-58/+38
std::initializer_list<T> type. Instead, the list must contain a single element and the type is deduced from that. In Clang 3.7, we warned by default on all the cases that would change meaning due to this change. In Clang 3.8, we will support only the new rules -- per the request in N3922, this change is applied as a Defect Report against earlier versions of the C++ standard. This change is not entirely trivial, because for lambda init-captures we previously did not track the difference between direct-list-initialization and copy-list-initialization. The difference was not previously observable, because the two forms of initialization always did the same thing (the elements of the initializer list were always copy-initialized regardless of the initialization style used for the init-capture). llvm-svn: 252688
2015-10-01Perform Objective-C lifetime adjustments before comparing deduced lambda ↵Douglas Gregor1-1/+2
result types. Objective-C ARC lifetime qualifiers are dropped when canonicalizing function types. Perform the same adjustment before comparing the deduced result types of lambdas. Fixes rdar://problem/22344904. llvm-svn: 249065
2015-08-05[AST] ArrayRefize BlockDecl::setCaptures. No functionality change intended.Benjamin Kramer1-2/+1
llvm-svn: 244027
2015-04-28Fix assertion failure if a lambda array-capture is followed by a this capture.Richard Smith1-3/+4
llvm-svn: 236043
2015-04-28Silencing a -Wuninitialized warning in a different way. This replaces ↵Aaron Ballman1-22/+19
r235981, but is still NFC. llvm-svn: 236002
2015-04-28Silencing a spurious -Wuninitialized warning with this local; NFC.Aaron Ballman1-1/+1
llvm-svn: 235981
2015-04-27PR23334: Perform semantic checking of lambda capture initialization in the ↵Richard Smith1-57/+130
right context. Previously we'd try to perform checks on the captures from the middle of parsing the lambda's body, at the point where we detected that a variable needed to be captured. This was wrong in a number of subtle ways. In PR23334, we couldn't correctly handle the list of potential odr-uses resulting from the capture, and our attempt to recover from that resulted in a use-after-free. We now defer building the initialization expression until we leave the lambda body and return to the enclosing context, where the initialization does the right thing. This patch only covers lambda-expressions, but we should apply the same change to blocks and captured statements too. llvm-svn: 235921
2015-04-01Re-land "MS ABI: lambda call operators are instance methods and should use ↵Reid Kleckner1-15/+20
thiscall" Update the test cases to pass when lambda call operators use thiscall. Update the lambda-to-block conversion operator to use the default free function calling convention instead of the call operator's convention. This reverts commit r233082 and re-instates r233023. llvm-svn: 233835
2014-12-19DR1048: drop top-level cv-qualifiers when deducing the return type of aRichard Smith1-2/+7
lambda-expression in C++11, to match the C++14 rules. llvm-svn: 224620
2014-11-19Update for LLVM API change to make Small(Ptr)Set::insert return ↵David Blaikie1-1/+1
pair<iterator, bool> as per the C++ standard's associative container concept. llvm-svn: 222335
2014-10-27Pass around CorrectionCandidateCallbacks as unique_ptrs soKaelyn Takata1-2/+2
TypoCorrectionConsumer can keep the callback around as long as needed. llvm-svn: 220693
2014-08-28[C++11] Support for capturing of variable length arrays in lambda expression.Alexey Bataev1-0/+6
Differential Revision: http://reviews.llvm.org/D4368 llvm-svn: 216649
2014-08-19C++1y is now C++14!Aaron Ballman1-3/+3
Changes diagnostic options, language standard options, diagnostic identifiers, diagnostic wording to use c++14 instead of c++1y. It also modifies related test cases to use the updated diagnostic wording. llvm-svn: 215982
2014-05-29Refactoring. Remove release and take methods from ActionResult. Rename ↵Nikola Smiljanic1-5/+5
takeAs to getAs. llvm-svn: 209800
2014-05-26[C++11] Use 'nullptr'. Sema edition.Craig Topper1-26/+27
llvm-svn: 209613