summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExpr.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Improve the diagnostic in ARC mode when a conditional with an Objective-C ↵Eli Friedman2012-02-251-0/+16
| | | | | | type and void* is used. <rdar://problem/10486347>. llvm-svn: 151416
* Implement C++11 [over.match.copy]p1b2, which allows the use ofDouglas Gregor2012-02-241-2/+5
| | | | | | | | | | | explicit conversion functions to initialize the argument to a copy/move constructor that itself is the subject of direct initialization. Since we don't have that much context in overload resolution, we end up threading more flags :(. Fixes <rdar://problem/10903741> / PR10456. llvm-svn: 151409
* Pull the OpaqueValueExpr's source expression into its constructor, soDouglas Gregor2012-02-231-1/+2
| | | | | | that we can correctly compute value-dependence of the OVE. llvm-svn: 151291
* Implement C++11 [expr.call]p11: If the operand to a decltype-specifier is aRichard Smith2012-02-221-2/+11
| | | | | | | | | | | | | | | | | | function call (or a comma expression with a function call on its right-hand side), possibly parenthesized, then the return type is not required to be complete and a temporary is not bound. Other subexpressions inside a decltype expression do not get this treatment. This is implemented by deferring the relevant checks for all calls immediately within a decltype expression, then, when the expression is fully-parsed, checking the relevant constraints and stripping off any top-level temporary binding. Deferring the completion of the return type exposed a bug in overload resolution where completion of the argument types was not attempted, which is also fixed by this change. llvm-svn: 151117
* Improve our handling of lambda expressions that occur within defaultDouglas Gregor2012-02-211-4/+22
| | | | | | | | | | | | | | | | | | | arguments. There are two aspects to this: - Make sure that when marking the declarations referenced in a default argument, we don't try to mark local variables, both because it's a waste of time and because the semantics are wrong: we're not in a place where we could capture these variables again even if it did make sense. - When a lambda expression occurs in a default argument of a function template, make sure that the corresponding closure type is considered dependent, so that it will get properly instantiated. The second bit is a bit of a hack; to fix it properly, we may have to rearchitect our handling of default arguments, parsing them only after creating the function definition. However, I'd like to separate that work from the lambdas work. llvm-svn: 151076
* Implement name mangling for lambda expressions that occur within theDouglas Gregor2012-02-211-2/+4
| | | | | | | | | | | | | | | | 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
* Fix wrong-code bug: __imag on a scalar lvalue should produce a zero rvalue,Richard Smith2012-02-181-4/+10
| | | | | | rather than an lvalue referring to the scalar. llvm-svn: 150889
* Remove unused but set variable.Benjamin Kramer2012-02-181-3/+0
| | | | llvm-svn: 150877
* Rewrite variable capture within lambda expressions and blocks,Douglas Gregor2012-02-181-196/+205
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | eliminating a bunch of redundant code and properly modeling how the captures of outside blocks/lambdas affect the types seen by inner captures. This new scheme makes two passes over the capturing scope stack. The first pass goes up the stack (from innermost to outermost), assessing whether the capture looks feasible and stopping when it either hits the scope where the variable is declared or when it finds an existing capture. The second pass then walks down the stack (from outermost to innermost), capturing the variable at each step and updating the captured type and the type that an expression referring to that captured variable would see. It also checks type-specific restrictions, such as the inability to capture an array within a block. Note that only the first odr-use of each variable needs to do the full walk; subsequent uses will find the capture immediately, so multiple walks need not occur. The same routine that builds the captures can also compute the type of the captures without signaling errors and without actually performing the capture. This functionality is used to determine the type of declaration references as well as implementing the weird decltype((x)) rule within lambda expressions. The capture code now explicitly takes sides in the debate over C++ core issue 1249, which concerns the type of captures within nested lambdas. We opt to use the more permissive, more useful definition implemented by GCC rather than the one implemented by EDG. llvm-svn: 150875
* Unify our computation of the type of a captured reference to aDouglas Gregor2012-02-181-41/+40
| | | | | | | variable; it was previously duplicated, and one of the copies failed to account for outer non-mutable lambda captures. llvm-svn: 150872
* Only add 'const' to the type of variables captured in a lambda whenDouglas Gregor2012-02-171-2/+7
| | | | | | we're capturing it by value in a non-mutable lambda. llvm-svn: 150791
* Lambda closure types are always considered to be like "local" classes,Douglas Gregor2012-02-161-0/+1
| | | | | | | | | even if they are not within a function scope. Teach template instantiation to treat them as such, and make sure that we have a local instantiation scope when instantiating default arguments and static data members. llvm-svn: 150725
* Revert "Revert "Make CXXNewExpr contain only a single initialier, and not ↵Sebastian Redl2012-02-161-3/+1
| | | | | | | | hold the used constructor itself."" This reintroduces commit r150682 with a fix for the Bullet benchmark crash. llvm-svn: 150685
* Revert "Make CXXNewExpr contain only a single initialier, and not hold the ↵Sebastian Redl2012-02-161-1/+3
| | | | | | | | | | used constructor itself." It leads to a compiler crash in the Bullet benchmark. This reverts commit r12014. llvm-svn: 150684
* Make CXXNewExpr contain only a single initialier, and not hold the used ↵Sebastian Redl2012-02-161-3/+1
| | | | | | | | | | constructor itself. Holding the constructor directly makes no sense when list-initialized arrays come into play. The constructor is now held in a CXXConstructExpr, if construction is what is done. The new design can also distinguish properly between list-initialization and direct-initialization, as well as implicit default-initialization constructors and explicit value-initialization constructors. Finally, doing it this way removes redundance from the AST because CXXNewExpr doesn't try to handle both the allocation and the initialization responsibilities. This breaks the static analysis of new expressions. I've filed PR12014 to track this. llvm-svn: 150682
* Implicitly define a lambda's conversion functions (to functionDouglas Gregor2012-02-161-1/+8
| | | | | | | | | | | | | pointers and block pointers). We use dummy definitions to keep the invariant that an implicit, used definition has a body; IR generation will substitute the actual contents, since they can't be represented as C++. For the block pointer case, compute the copy-initialization needed to capture the lambda object in the block, which IR generation will need later. llvm-svn: 150645
* Introduce a new initialization entity for lambda captures, andDouglas Gregor2012-02-151-3/+2
| | | | | | specialize location information and diagnostics for this entity. llvm-svn: 150588
* If a static data member of a class template which could be used in a constantRichard Smith2012-02-151-10/+14
| | | | | | | | expression is referenced, defined, then referenced again, make sure we instantiate it the second time it's referenced. This is the static data member analogue of r150518. llvm-svn: 150560
* If a constexpr function template specialization is referenced, and then theRichard Smith2012-02-141-9/+19
| | | | | | | | template is defined, and then the specialization is referenced again, don't forget to instantiate the template on the second reference. Use the source location of the first reference as the point of instantiation, though. llvm-svn: 150518
* Implement support for lambda capture pack expansions, e.g.,Douglas Gregor2012-02-141-2/+3
| | | | | | [&values...] { print(values...); } llvm-svn: 150497
* Use a simpler (and more efficient) pattern to pad vectors.Benjamin Kramer2012-02-141-4/+2
| | | | llvm-svn: 150475
* Introduce support for template instantiation of lambdaDouglas Gregor2012-02-131-2/+0
| | | | | | | | | | | | | | | | | | expressions. This is mostly a simple refact, splitting the main "start a lambda expression" function into smaller chunks that are driven either from the parser (Sema::ActOnLambdaExpr) or during AST transformation (TreeTransform::TransformLambdaExpr). A few minor interesting points: - Added new entry points for TreeTransform, so that we can explicitly establish the link between the lambda closure type in the template and the lambda closure type in the instantiation. - Added a bit into LambdaExpr specifying whether it had an explicit result type or not. We should have had this anyway. This code is 'lightly' tested. llvm-svn: 150417
* Keep track of the set of array index variables we use when weDouglas Gregor2012-02-131-1/+3
| | | | | | | synthesize a by-copy captured array in a lambda. This information will be needed by IR generation. llvm-svn: 150396
* Within the body of a lambda expression, decltype((x)) for anDouglas Gregor2012-02-121-80/+122
| | | | | | | | | | | | | | | | id-expression 'x' will compute the type based on the assumption that 'x' will be captured, even if it isn't captured, per C++11 [expr.prim.lambda]p18. There are two related refactors that go into implementing this: 1) Split out the check that determines whether we should capture a particular variable reference, along with the computation of the type of the field, from the actual act of capturing the variable. 2) Always compute the result of decltype() within Sema, rather than AST, because the decltype() computation is now context-sensitive. llvm-svn: 150347
* Change the way we store initialization kinds so that all direct inits can ↵Sebastian Redl2012-02-121-1/+2
| | | | | | distinguish between list and parens form. This allows us to correctly diagnose the last test cases from litb. llvm-svn: 150343
* Represent C++ direct initializers as ParenListExprs before semantic analysisSebastian Redl2012-02-111-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | instead of having a special-purpose function. - ActOnCXXDirectInitializer, which was mostly duplication of AddInitializerToDecl (leading e.g. to PR10620, which Eli fixed a few days ago), is dropped completely. - MultiInitializer, which was an ugly hack I added, is dropped again. - We now have the infrastructure in place to distinguish between int x = {1}; int x({1}); int x{1}; -- VarDecl now has getInitStyle(), which indicates which of the above was used. -- CXXConstructExpr now has a flag to indicate that it represents list- initialization, although this is not yet used. - InstantiateInitializer was renamed to SubstInitializer and simplified. - ActOnParenOrParenListExpr has been replaced by ActOnParenListExpr, which always produces a ParenListExpr. Placed that so far failed to convert that back to a ParenExpr containing comma operators have been fixed. I'm pretty sure I could have made a crashing test case before this. The end result is a (I hope) considerably cleaner design of initializers. More importantly, the fact that I can now distinguish between the various initialization kinds means that I can get the tricky generalized initializer test cases Johannes Schaub supplied to work. (This is not yet done.) This commit passed self-host, with the resulting compiler passing the tests. I hope it doesn't break more complicated code. It's a pretty big change, but one that I feel is necessary. llvm-svn: 150318
* [libclang] Indexing API: Fully index implict template instantiations.Argyrios Kyrtzidis2012-02-101-1/+5
| | | | llvm-svn: 150267
* Add test from [expr.prim.lambda]p12, which deals with odr-use andDouglas Gregor2012-02-101-3/+0
| | | | | | | | nested captures. We currently don't get odr-use correct in array bounds, so that bit is commented out while we sort out what we need to do. llvm-svn: 150255
* Add various tests for captures and the reaching scope of the lambdaDouglas Gregor2012-02-101-1/+5
| | | | | | | expression. Implement C++11 [expr.prim.lambda]p12's requirement that capturing a variable will odr-use it. llvm-svn: 150237
* Revert r145999. This turned out to be a bad idea. Unfortunately, 'id' is ↵Ted Kremenek2012-02-101-9/+8
| | | | | | | | | used so profusely in many APIs and large codebases that this made the deprecated warning trigger happy to the point of not being useful. llvm-svn: 150223
* Implement C++ [expr.prim.lambda]p2, which bans lambda expressions inDouglas Gregor2012-02-091-2/+34
| | | | | | | unevaluated operands. Be certain that we're marking everything referenced within a capture initializer as odr-used. llvm-svn: 150163
* Implement capture-by-copy for arrays in lambdas.Douglas Gregor2012-02-091-7/+66
| | | | llvm-svn: 150138
* When we create a non-static data member in the closure object for aDouglas Gregor2012-02-091-0/+1
| | | | | | capture, make sure we actually add the field. llvm-svn: 150135
* Factor the logic for capturing variables in a lambda into its ownDouglas Gregor2012-02-091-82/+88
| | | | | | function; it's going to get longer soon. No functionality change. llvm-svn: 150132
* Various interrelated cleanups for lambdas:Douglas Gregor2012-02-091-1/+18
| | | | | | | | | | | | | | - Complete the lambda class when we finish the lambda expression (previously, it was left in the "being completed" state) - Actually return the LambdaExpr object and bind to the resulting temporary when needed. - Detect when cleanups are needed while capturing a variable into a lambda (e.g., due to default arguments in the copy constructor), and make sure those cleanups apply for the whole of the lambda expression. llvm-svn: 150123
* When computing the type of a local variable reference within a lambda,Douglas Gregor2012-02-081-1/+11
| | | | | | | | only add 'const' for variables captured by copy in potentially evaluated expressions of non-mutable lambdas. (The "by copy" part was missing). llvm-svn: 150088
* When completing a lambda expression, make sure to check and attach theDouglas Gregor2012-02-081-2/+0
| | | | | | body of the lambda to the function call operator. llvm-svn: 150087
* Revise the SplitQualType interface to make it its own thing instead ofJohn McCall2012-02-081-2/+2
| | | | | | | | | | | | | | a typedef of std::pair. This slightly improves type-safety, but mostly makes code using it clearer to read as well as making it possible to add methods to the type. Add such a method for efficiently single-step desugaring a split type. Add a method to single-step desugaring a locally-unqualified type. Implement both the SplitQualType and QualType methods in terms of that. Also, fix a typo ("ObjCGLifetime"). llvm-svn: 150028
* Introduce basic ASTs for lambda expressions. This covers:Douglas Gregor2012-02-071-6/+72
| | | | | | | | | | | | | | | | | | | | | | | | - Capturing variables by-reference and by-copy within a lambda - The representation of lambda captures - The creation of the non-static data members in the lambda class that store the captured variables - The initialization of the non-static data members from the captured variables - Pretty-printing lambda expressions There are a number of FIXMEs, both explicit and implied, including: - Creating a field for a capture of 'this' - Improved diagnostics for initialization failures when capturing variables by copy - Dealing with temporaries created during said initialization - Template instantiation - AST (de-)serialization - Binding and returning the lambda expression; turning it into a proper temporary - Lots and lots of semantic constraints - Parameter pack captures llvm-svn: 149977
* Misc improvements to the diagnostic when a variable is odr-used in a context ↵Eli Friedman2012-02-071-12/+30
| | | | | | | | that is not allowed to capture variables. Fixes PR11883. llvm-svn: 149937
* Fix a minor regression from my potentially-evaluated expression changes.Eli Friedman2012-02-061-0/+8
| | | | llvm-svn: 149930
* Fixed instantiation of DependentScopeDeclRefExpr.Abramo Bagnara2012-02-061-4/+4
| | | | llvm-svn: 149868
* Move instantiateTemplateAttribute into the sema namespace, make helpers static.Benjamin Kramer2012-02-061-1/+1
| | | | llvm-svn: 149864
* Basic: import SmallString<> into clang namespaceDylan Noblesmith2012-02-051-4/+4
| | | | | | | (I was going to fix the TODO about DenseMap too, but that would break self-host right now. See PR11922.) llvm-svn: 149799
* In C++11 mode, when an integral constant expression is desired and we have aRichard Smith2012-02-041-29/+77
| | | | | | | | | | | | | | | | | | value of class type, look for a unique conversion operator converting to integral or unscoped enumeration type and use that. Implements [expr.const]p5. Sema::VerifyIntegerConstantExpression now performs the conversion and returns the converted result. Some important callers of Expr::isIntegralConstantExpr have been switched over to using it (including all of those required for C++11 conformance); this switch brings a side-benefit of improved diagnostics and, in several cases, simpler code. However, some language extensions and attributes have not been moved across and will not perform implicit conversions on constant expressions of literal class type where an ICE is required. In passing, fix static_assert to perform a contextual conversion to bool on its argument. llvm-svn: 149776
* Suppress the used-but-not-defined warning for static data members while I ↵Eli Friedman2012-02-041-1/+3
| | | | | | look into a rather nasty bug in the new odr-use marking code. llvm-svn: 149731
* Make explicit captures which cause implicit captures work correctly.Eli Friedman2012-02-031-2/+8
| | | | llvm-svn: 149719
* Implement implicit capture for lambda expressions.Eli Friedman2012-02-031-39/+107
| | | | | | Still left: explicit captures in lambdas need to cause implicit capture, and I need to take a look at the diagnostics for some cases. llvm-svn: 149718
* Move isSentinelNullExpr() from Sema to ASTContext to make it more widelyArgyrios Kyrtzidis2012-02-031-19/+1
| | | | | | available. llvm-svn: 149675
* Refactor capture in blocks to use new-style capture hooks. Start adding a ↵Eli Friedman2012-02-031-256/+195
| | | | | | bit of the code for lambdas. The only visible changes are that we use the C++11 odr-used rules to figure out when a variable is captured, and type-checking in lambdas is slightly more accurate. llvm-svn: 149663
OpenPOWER on IntegriCloud