summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Expr.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Substitute type arguments into uses of Objective-C interface members.Douglas Gregor2015-07-071-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When messaging a method that was defined in an Objective-C class (or category or extension thereof) that has type parameters, substitute the type arguments for those type parameters. Similarly, substitute into property accesses, instance variables, and other references. This includes general infrastructure for substituting the type arguments associated with an ObjCObject(Pointer)Type into a type referenced within a particular context, handling all of the substitutions required to deal with (e.g.) inheritance involving parameterized classes. In cases where no type arguments are available (e.g., because we're messaging via some unspecialized type, id, etc.), we substitute in the type bounds for the type parameters instead. Example: @interface NSSet<T : id<NSCopying>> : NSObject <NSCopying> - (T)firstObject; @end void f(NSSet<NSString *> *stringSet, NSSet *anySet) { [stringSet firstObject]; // produces NSString* [anySet firstObject]; // produces id<NSCopying> (the bound) } When substituting for the type parameters given an unspecialized context (i.e., no specific type arguments were given), substituting the type bounds unconditionally produces type signatures that are too strong compared to the pre-generics signatures. Instead, use the following rule: - In covariant positions, such as method return types, replace type parameters with “id” or “Class” (the latter only when the type parameter bound is “Class” or qualified class, e.g, “Class<NSCopying>”) - In other positions (e.g., parameter types), replace type parameters with their type bounds. - When a specialized Objective-C object or object pointer type contains a type parameter in its type arguments (e.g., NSArray<T>*, but not NSArray<NSString *> *), replace the entire object/object pointer type with its unspecialized version (e.g., NSArray *). llvm-svn: 241543
* Switch users of the 'for (StmtRange range = stmt->children(); range; ↵Benjamin Kramer2015-07-021-4/+4
| | | | | | | | | ++range)‘ pattern to range for loops. The pattern was born out of the lack of range-based for loops in C++98 and is somewhat obscure. No functionality change intended. llvm-svn: 241300
* Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko2015-06-221-3/+3
| | | | llvm-svn: 240353
* Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko2015-06-221-3/+3
| | | | | | | | | | | | The patch is generated using this command: $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ work/llvm/tools/clang To reduce churn, not touching namespaces spanning less than 10 lines. llvm-svn: 240270
* some StmtExprs do not have side-effectsScott Douglass2015-06-101-1/+29
| | | | | | Differential Revision: http://reviews.llvm.org/D10211 llvm-svn: 239476
* add ConstEvaluatedExprVisitorScott Douglass2015-06-101-14/+14
| | | | | | Differential Revision: http://reviews.llvm.org/D10210 llvm-svn: 239474
* Implementing C99 partial re-initialization behavior (DR-253)Yunzhong Gao2015-06-101-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | | Based on previous discussion on the mailing list, clang currently lacks support for C99 partial re-initialization behavior: Reference: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-April/029188.html Reference: http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_253.htm This patch attempts to fix this problem. Given the following code snippet, struct P1 { char x[6]; }; struct LP1 { struct P1 p1; }; struct LP1 l = { .p1 = { "foo" }, .p1.x[2] = 'x' }; // this example is adapted from the example for "struct fred x[]" in DR-253; // currently clang produces in l: { "\0\0x" }, // whereas gcc 4.8 produces { "fox" }; // with this fix, clang will also produce: { "fox" }; Differential Review: http://reviews.llvm.org/D5789 llvm-svn: 239446
* Properly implement warn_unused_result checking for classes/structs.Kaelyn Takata2015-04-091-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The previous implementation would copy the attribute from the class to functions that have the class as their return type when the functions are first declared. This proved to have two flaws: 1) if the class is forward-declared without the attribute and a function or method with the class as a its return type is declared, and afterward the class is defined with warn_unused_result, the function or method would never inherit the attribute, and 2) the check simply failed for functions and methods that are part of a template instantiation, regardless of whether the class with warn_unused_result is part of a specific instantiation or part of the template itself (presumably because those function/method declaration does not hit the same code path as a non-template one and so never inherits the attribute). The new approach is to instead modify the two places where a function or method call is checked for the warn_unused_result attribute on the decl by extending the checks to also look for the attribute on the decl's return type. Additionally, the check for return types that have the warn_unused_result now excludes pointers and references to such types, as such return types do not necessarily imply a transfer of ownership for the underlying object being referred to by the return value. This does not change the behavior of functions that are directly given the warn_unused_result attribute. llvm-svn: 234526
* HasSideEffects() should return false for calls to pure and const functions.Michael Kuperstein2015-04-061-3/+11
| | | | | | Differential Revision: http://reviews.llvm.org/D8548 llvm-svn: 234152
* Track the source location of the dot or arrow operator in a MemberExpr.Aaron Ballman2015-03-241-12/+8
| | | | | | Patch by Joe Ranieri! llvm-svn: 233085
* Use delegating ctors to reduce code duplication. NFC.Benjamin Kramer2015-03-061-30/+3
| | | | llvm-svn: 231476
* Sema: Parenthesized bound destructor member expressions can be calledDavid Majnemer2015-02-251-10/+15
| | | | | | | | | We would wrongfully reject (a.~A)() in both the destructor and pseudo-destructor cases. This fixes PR22668. llvm-svn: 230512
* [Objctive-C sema]. Do not do the unused-getter-return-valueFariborz Jahanian2015-02-161-3/+1
| | | | | | | warning when property getter is used in direct method call and return value of property is unused. rdar://19773512 llvm-svn: 229458
* AST: alignof might be dependent because of alignment attributesDavid Majnemer2015-01-151-0/+38
| | | | | | | Dependent alignment attributes should make an alignof expression dependent as well. llvm-svn: 226156
* Rename RefersToCapturedVariable to RefersToEnclosingVariableOrCapture, NFCAlexey Bataev2015-01-121-6/+7
| | | | llvm-svn: 225624
* Sema: Dependent array designators cannot be checkedDavid Majnemer2015-01-091-2/+2
| | | | | | | | | | | We forgot to mark designated initializer expression that contain type dependent array designators as type dependent. This would lead to crashes when we try to determine which array element we were trying to initialize. This fixes PR22056. llvm-svn: 225494
* Volatile reads are side-effecting operations, but in the general case of ↵Aaron Ballman2015-01-031-0/+7
| | | | | | | | | | | access through a volatile-qualified type, we're not certain of the underlying object's side-effects on access. Treat volatile accesses as "maybe" instead of "definite" side effects for the purposes of warning on evaluations in an unevaluated context. No longer diagnose on idiomatic code like: int * volatile v; (void)sizeof(*v); llvm-svn: 225116
* Adding a -Wunused-value warning for expressions with side effects used in an ↵Aaron Ballman2014-12-171-20/+37
| | | | | | unevaluated expression context, such as sizeof(), or decltype(). Also adds a similar warning when the expression passed to typeid() *is* evaluated, since it is equally likely that the user would expect the expression operand to be unevaluated in that case. llvm-svn: 224465
* Renamed RefersToEnclosingLocal bitfield to RefersToCapturedVariable.Alexey Bataev2014-12-161-6/+6
| | | | | | | Bitfield RefersToEnclosingLocal of Stmt::DeclRefExprBitfields renamed to RefersToCapturedVariable to reflect latest changes introduced in commit 224323. Also renamed method Expr::refersToEnclosingLocal() to Expr::refersToCapturedVariable() and comments for constant arguments. No functional changes. llvm-svn: 224329
* Handle use of default member initializers before end of outermost classReid Kleckner2014-11-171-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Specifically, when we have this situation: struct A { template <typename T> struct B { int m1 = sizeof(A); }; B<int> m2; }; We can't parse m1's initializer eagerly because we need A to be complete. Therefore we wait until the end of A's class scope to parse it. However, we can trigger instantiation of B before the end of A, which will attempt to instantiate the field decls eagerly, and it would build a bad field decl instantiation that said it had an initializer but actually lacked one. Fixed by deferring instantiation of default member initializers until they are needed during constructor analysis. This addresses a long standing FIXME in the code. Fixes PR19195. Reviewed By: rsmith Differential Revision: http://reviews.llvm.org/D5690 llvm-svn: 222192
* [c++1z] N4295: fold-expressions.Richard Smith2014-11-081-0/+1
| | | | | | | | | | | | | | | | This is a new form of expression of the form: (expr op ... op expr) where one of the exprs is a parameter pack. It expands into (expr1 op (expr2onwards op ... op expr)) (and likewise if the pack is on the right). The non-pack operand can be omitted; in that case, an empty pack gives a fallback value or an error, depending on the operator. llvm-svn: 221573
* Objective-C. revert patch for rdar://17554063.Fariborz Jahanian2014-10-281-11/+4
| | | | llvm-svn: 220812
* Add the initial TypoExpr AST node for delayed typo correction.Kaelyn Takata2014-10-271-0/+1
| | | | llvm-svn: 220692
* Add frontend support for __vectorcallReid Kleckner2014-10-241-0/+1
| | | | | | | | | | | | | Wire it through everywhere we have support for fastcall, essentially. This allows us to parse the MSVC "14" CTP headers, but we will miscompile them because LLVM doesn't support __vectorcall yet. Reviewed By: Aaron Ballman Differential Revision: http://reviews.llvm.org/D5808 llvm-svn: 220573
* Towards PR21289: don't lose track of unexpanded parameter packs withRichard Smith2014-10-171-28/+17
| | | | | | | non-dependent types, in CXXScalarValueInitExprs and in the nested-name-specifier or template arguments of a DeclRefExpr in particular. llvm-svn: 220028
* Bugfix for predefined expressions in dependent context.Alexey Bataev2014-10-101-1/+1
| | | | | | This bug break compilation with precompiled headers and predefined expressions in dependent context. llvm-svn: 219525
* Fix for bug http://llvm.org/PR17427.Alexey Bataev2014-10-091-3/+50
| | | | | | | | Assertion failed: "Computed __func__ length differs from type!" Reworked PredefinedExpr representation with internal StringLiteral field for function declaration. Differential Revision: http://reviews.llvm.org/D5365 llvm-svn: 219393
* Fix handling of preincrement on bit-fields. This gives a bit-field in C++, butRichard Smith2014-09-241-0/+4
| | | | | | | | | | | we were failing to find that bit-field when performing integer promotions. This brings us closer to following the standard, and closer to GCC. In C, this change is technically a regression: we get bit-field promotions completely wrong in C, promoting cases that are categorically not bit-field designators. This change makes us do so slightly more consistently, though. llvm-svn: 218428
* Range'ify some for loops over RecordDecl::fields()Hans Wennborg2014-08-211-3/+2
| | | | | | No functionality change. llvm-svn: 216183
* Make sure CallExpr::getLocStart doesn't segfaultKeno Fischer2014-08-151-2/+2
| | | | | | | | | | | | | | | | | Summary: When the CallExpr passed to Sema::ConvertArgumentsForCall has all default parameters, and the number of actual arguments passed is zero, this function will segfault in the call to Call->getLocStart() if the Callee has an invalid getLocStart(), the reason being that since ConvertArgumentsForCall has set the correct number of arguments, but has not filled them in yet, getLocStart() will try to access the first (not yet existent) argument and thus segfaults. This fixes that by making getLocStart return an invalid source location if the queried argument is NULL rather than segfaulting. Reviewers: rnk Reviewed By: rnk Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D4917 llvm-svn: 215686
* Objective-C ARC. First patch toward generating new APIsFariborz Jahanian2014-08-061-4/+11
| | | | | | | for Objective-C's array and dictionary literals. rdar://17554063. This is wip. llvm-svn: 214983
* Improve -UNDEBUG binary size. We don't need a different assert fail message forRichard Smith2014-07-261-2/+2
| | | | | | each different enum value here. llvm-svn: 213996
* Objective-C. Patch to warn if the result of calling a property getter Fariborz Jahanian2014-07-181-6/+9
| | | | | | | | is unused (this is match behavior when property-dot syntax is used to use same getter). rdar://17514245 Patch by Anders Carlsson with minor refactoring by me. llvm-svn: 213423
* Convert StringLiteralParser constructor to use ArrayRef instead of a pointer ↵Craig Topper2014-06-261-1/+1
| | | | | | and count. llvm-svn: 211763
* Improved location for non-constant initializers diagnostics.Abramo Bagnara2014-05-221-18/+33
| | | | llvm-svn: 209466
* Ignore void returning overloaded functions fom -Wunused-comparison. PR19791.Richard Trieu2014-05-201-1/+2
| | | | llvm-svn: 209186
* When an overloaded comparison operator returns a reference, do not considerRichard Trieu2014-05-141-0/+2
| | | | | | it for -Wunused-comparion warnings. This fixes PR19724. llvm-svn: 208824
* [C++11] Use 'nullptr'. AST edition.Craig Topper2014-05-121-22/+23
| | | | llvm-svn: 208517
* -Wunreachable-code: refine recognition of unreachable "sigil" to cope with ↵Ted Kremenek2014-04-161-0/+21
| | | | | | | | implicit casts in C++. Fixes <rdar://problem/16631033>. llvm-svn: 206360
* Add support for MSVC's __FUNCSIG__Reid Kleckner2014-04-081-2/+14
| | | | | | | | | | | It is very similar to GCC's __PRETTY_FUNCTION__, except it prints the calling convention. Reviewers: majnemer Differential Revision: http://reviews.llvm.org/D3311 llvm-svn: 205780
* Extend -Wtautological-constant-out-of-range-compare to handle boolean valuesRichard Trieu2014-04-041-0/+2
| | | | | | | | | | | | | | | better. This warning will now trigger on the following conditionals: bool b; int i; if (b > 1) {} // always false if (0 <= (i > 5)) {} // always true if (-1 > b) {} // always false Patch by Per Viberg. llvm-svn: 205608
* Move the warning about unused relational comparison from -Wunused-value toRichard Trieu2014-03-111-4/+11
| | | | | | | -Wunused-comparison. Also, newly warn on unused result from overloaded relational comparisons, now also in -Wunused-comparison. llvm-svn: 203535
* Replace OwningPtr with std::unique_ptr.Ahmed Charles2014-03-071-1/+1
| | | | | | This compiles cleanly with lldb/lld/clang-tools-extra/llvm. llvm-svn: 203279
* Sema: When merging objc string literals, give the result a constant array type.Benjamin Kramer2014-02-251-0/+3
| | | | | | | | Also assert that we never create non-array string literals again. PR18939. llvm-svn: 202147
* [Sema] Revert the change in r200622 that allowed integer casts to silence ↵Argyrios Kyrtzidis2014-02-111-3/+0
| | | | | | | | | | -Wnon-literal-null-conversion in C code. It is actually useful to warn in such cases, thanks to Dmitri for pushing on this and making us see the light! Related to rdar://15925483 and rdar://15922612. The latter radar is where the usefulness of the warning is most clear. llvm-svn: 201165
* Clean up some particularly ugly casting.Benjamin Kramer2014-02-051-12/+3
| | | | | | No functionality change. llvm-svn: 200877
* Fix typo in CastExpr::getCastKindName.Jordan Rose2014-02-051-1/+1
| | | | | | Patch by Mathieu Baudet! llvm-svn: 200817
* [Sema] Follow-up on r200521 for the -Wnon-literal-null-conversion warning ↵Argyrios Kyrtzidis2014-02-021-0/+3
| | | | | | and revert its behavior for C++. llvm-svn: 200622
* Rename getResultType() on function and method declarations to getReturnType()Alp Toker2014-01-251-5/+7
| | | | | | | | | | | | | | | A return type is the declared or deduced part of the function type specified in the declaration. A result type is the (potentially adjusted) type of the value of an expression that calls the function. Rule of thumb: * Declarations have return types and parameters. * Expressions have result types and arguments. llvm-svn: 200082
* Harden InitListExpr::isStringLiteralInit() against getInit() returning null.Ted Kremenek2014-01-191-1/+5
| | | | | | | | This led to a crash on invalid code (sorry, no good test case). Fixes <rdar://problem/15831804>. llvm-svn: 199571
OpenPOWER on IntegriCloud