summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExprObjC.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Implement the Objective-C __kindof type qualifier.Douglas Gregor2015-07-071-10/+17
| | | | | | | | | | The __kindof type qualifier can be applied to Objective-C object (pointer) types to indicate id-like behavior, which includes implicit "downcasting" of __kindof types to subclasses and id-like message-send behavior. __kindof types provide better type bounds for substitutions into unspecified generic types, which preserves more type information. llvm-svn: 241548
* Substitute type arguments into uses of Objective-C interface members.Douglas Gregor2015-07-071-28/+49
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Handle Objective-C type arguments.Douglas Gregor2015-07-071-2/+4
| | | | | | | | | | | | | | | | | | | | | Objective-C type arguments can be provided in angle brackets following an Objective-C interface type. Syntactically, this is the same position as one would provide protocol qualifiers (e.g., id<NSCopying>), so parse both together and let Sema sort out the ambiguous cases. This applies both when parsing types and when parsing the superclass of an Objective-C class, which can now be a specialized type (e.g., NSMutableArray<T> inherits from NSArray<T>). Check Objective-C type arguments against the type parameters of the corresponding class. Verify the length of the type argument list and that each type argument satisfies the corresponding bound. Specializations of parameterized Objective-C classes are represented in the type system as distinct types. Both specialized types (e.g., NSArray<NSString *> *) and unspecialized types (NSArray *) are represented, separately. llvm-svn: 241542
* Parsing, semantic analysis, and AST for Objective-C type parameters.Douglas Gregor2015-07-071-6/+9
| | | | | | | | | | | | | | | | | | | | Produce type parameter declarations for Objective-C type parameters, and attach lists of type parameters to Objective-C classes, categories, forward declarations, and extensions as appropriate. Perform semantic analysis of type bounds for type parameters, both in isolation and across classes/categories/extensions to ensure consistency. Also handle (de-)serialization of Objective-C type parameter lists, along with sundry other things one must do to add a new declaration to Clang. Note that Objective-C type parameters are typedef name declarations, like typedefs and C++11 type aliases, in support of type erasure. Part of rdar://problem/6294649. llvm-svn: 241541
* [ObjC] Add NSValue support for objc_boxed_expressionsAlex Denisov2015-06-261-8/+119
| | | | | | | | | | | | | Patch extends ObjCBoxedExpr to accept records (structs and unions): typedef struct __attribute__((objc_boxable)) _Color { int r, g, b; } Color; Color color; NSValue *boxedColor = @(color); // [NSValue valueWithBytes:&color objCType:@encode(Color)]; llvm-svn: 240761
* Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko2015-06-221-2/+2
| | | | llvm-svn: 240353
* Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko2015-06-221-2/+2
| | | | | | | | | | | | 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
* Introduced pragmas for audited nullability regions.Douglas Gregor2015-06-191-0/+4
| | | | | | | | | | | | | | | | | Introduce the clang pragmas "assume_nonnull begin" and "assume_nonnull end" in which we make default assumptions about the nullability of many unannotated pointers: - Single-level pointers are inferred to __nonnull - NSError** in a (function or method) parameter list is inferred to NSError * __nullable * __nullable. - CFErrorRef * in a (function or method) parameter list is inferred to CFErrorRef __nullable * __nullable. - Other multi-level pointers are never inferred to anything. Implements rdar://problem/19191042. llvm-svn: 240156
* Extend type nullability qualifiers for Objective-C.Douglas Gregor2015-06-191-16/+117
| | | | | | | | | | | | | | | Introduce context-sensitive, non-underscored nullability specifiers (nonnull, nullable, null_unspecified) for Objective-C method return types, method parameter types, and properties. Introduce Objective-C-specific semantics, including computation of the nullability of the result of a message send, merging of nullability information from the @interface of a class into its @implementation, etc . This is the Objective-C part of rdar://problem/18868820. llvm-svn: 240154
* [Objective-C Sema]This patch fixes the warning when clang issuesFariborz Jahanian2015-04-151-6/+15
| | | | | | | | | | "multiple methods named '<selector>' found" warning by noting the method that is actualy used. It also cleans up and refactors code in this area and selects a method that matches actual arguments in case of receiver being a forward class object. rdar://19265430 llvm-svn: 235023
* [Objective-C Sema] Fixes a typo which did not allow Fariborz Jahanian2015-04-101-1/+1
| | | | | | | bridge casting to super class of object's bridge type. rdar://18311183 llvm-svn: 234652
* [Objective-C Sema] It is permissable to bridge cast to 'id'Fariborz Jahanian2015-04-091-5/+6
| | | | | | | of a CFType bridged to some unknown Objective-C type. rdar://20113785 llvm-svn: 234545
* [Modules] Make Sema's map of referenced selectors have a deterministicChandler Carruth2015-03-271-9/+4
| | | | | | | | | | | order based on order of insertion. This should cause both our warnings about these and the modules serialization to be deterministic as a consequence. Found by inspection. llvm-svn: 233343
* [Objective-C Sema]. Remove -Wreceiver-is-weak warning.Fariborz Jahanian2015-03-101-67/+0
| | | | | | | It is incorrect and better warning is issued under -Warc-repeated-use-of-weak. rdar://16316934. llvm-svn: 231851
* Recognize objc_bridge(id) on bridged casts to CF types.John McCall2015-03-101-0/+3
| | | | | | Fixes <rdar://20107345>. llvm-svn: 231814
* New ObjC warning: circular containers.Alex Denisov2015-03-041-1/+3
| | | | | | | | | | | | | | | | | | | | | This commit adds new warning to prevent user from creating 'circular containers'. Mutable collections from NSFoundation allows user to add collection to itself, e.g.: NSMutableArray *a = [NSMutableArray new]; [a addObject:a]; The code above leads to really weird behaviour (crashes, 'endless' recursion) and retain cycles (collection retains itself) if ARC enabled. Patch checks the following collections: - NSMutableArray, - NSMutableDictionary, - NSMutableSet, - NSMutableOrderedSet, - NSCountedSet. llvm-svn: 231265
* Allow (Object *)kMyGlobalCFObj casts without bridgingBen Langmuir2015-02-251-6/+9
| | | | | | | | | | | | | | | | Previously we allowed these casts only for constants declared in system headers, which we assume are retain/release-neutral. Now also allow them for constants in user headers, treating them as +0. Practically, this means that we will now allow: id x = (id)kMyGlobalConst; But unlike with system headers we cannot mix them with +1 values: id y = (id)(b ? kMyGlobalConst : [Obj newValAtPlusOne]); // error id z = (id)(b ? kSystemGlobalConst: [Obj newValAtPlusOne]); // OK Thanks to John for suggesting this improvement. llvm-svn: 230534
* Fix crash when clang tries to build NSNumber literal after forward declarationAlex Denisov2015-02-161-1/+3
| | | | | | | | | | | Bug report: http://llvm.org/bugs/show_bug.cgi?id=22561 Clang tries to create ObjCBoxedExpression of type 'NSNumber' when 'NSNumber' has only forward declaration, this cause a crash later, when 'Sema' refers to a nil QualType of the whole expression. Please, refer to the bug report for the better explanation. llvm-svn: 229402
* Patch fixes PR21932 crash on invalid code. UsingFariborz Jahanian2015-01-201-21/+22
| | | | | | | property-dot syntax on 'super' with no super class. Patch by Jason Haslam. llvm-svn: 226578
* Address review feedback on r221933.Nico Weber2014-12-271-3/+4
| | | | | | | | | | | Remove ObjCMethodList::Count, instead store a "has more than one decl" bit in the low bit of the ObjCMethodDecl pointer, using a PointerIntPair. Most of this patch is replacing ".Method" with ".getMethod()". No intended behavior change. llvm-svn: 224876
* [Objective-C]. This patch extends objc_bridge attribute to support ↵Fariborz Jahanian2014-12-111-0/+3
| | | | | | | | | | objc_bridge(id). This means that a pointer to the struct type to which the attribute appertains is a CF type (and therefore an Objective-C object of some type), but not of any specific class. rdar://19157264 llvm-svn: 224072
* Fix the indentation: Nesting level does not match indentation (CID 1254863)Sylvestre Ledru2014-11-171-2/+2
| | | | llvm-svn: 222152
* Objective-C. Fixes a regression caused by implementationFariborz Jahanian2014-11-131-2/+1
| | | | | | | | of new warning for deprecated method call for receiver of type 'id'. This addresses rdar://18960378 where unintended warnings being issued. llvm-svn: 221933
* [Objective-C Sema]. Issue availability/deprecated warning when Fariborz Jahanian2014-11-071-1/+5
| | | | | | | there is a uinque method found when message is sent to receiver of 'id' type. // rdar://18848183 llvm-svn: 221562
* Objective-C. revert patch for rdar://17554063.Fariborz Jahanian2014-10-281-63/+12
| | | | llvm-svn: 220812
* [Objective-C]. revert r220740,r220727Fariborz Jahanian2014-10-281-16/+5
| | | | llvm-svn: 220802
* Objective-C ARC [qoi]. Issue diagnostic if __bridge castingFariborz Jahanian2014-10-271-5/+16
| | | | | | to C type a collection literal. rdar://18768214 llvm-svn: 220727
* Pass around CorrectionCandidateCallbacks as unique_ptrs soKaelyn Takata2014-10-271-9/+9
| | | | | | TypoCorrectionConsumer can keep the callback around as long as needed. llvm-svn: 220693
* Objective-C. Under a special flag, -Wcstring-format-directive,Fariborz Jahanian2014-09-111-11/+24
| | | | | | | | | off by default, issue a warning if %s directive is used in formart argument of a function/method declared as __attribute__((format(CF/NSString, ...))) To complete rdar://18182443 llvm-svn: 217619
* Objective-C. Under a special flag, -Wcstring-format-directive,Fariborz Jahanian2014-09-091-1/+31
| | | | | | | | off by default, issue a warning if %s directive is used in certain CF/NS formatting APIs, to assist user in deprecating use of such %s in these APIs. rdar://18182443 llvm-svn: 217467
* Use llvm::makeArrayRef instead of explicitly calling ArrayRef constructor ↵Craig Topper2014-08-301-1/+1
| | | | | | and mentioning the type. This works now that we have a conversion from ArrayRef<T*> to ArrayRef<const T*>. llvm-svn: 216824
* Objective-C. Allow [super initialize] in an +initializeFariborz Jahanian2014-08-251-8/+19
| | | | | | | implementation but not anywhere else. rdar://16628028 llvm-svn: 216408
* Objective-C. Warn when @encode'ing provides an incompleteFariborz Jahanian2014-08-221-1/+5
| | | | | | | | type encoding because in certain cases, such as for vector types, because we still haven't designed encoding for them. rdar://9255564 llvm-svn: 216301
* Objective-C. Update my previous patch to not warn ifFariborz Jahanian2014-08-221-2/+3
| | | | | | | +initialize is called on 'super' in its implementation. rdar://16628028 llvm-svn: 216282
* Objective-C. Warn if user has made explicit callFariborz Jahanian2014-08-221-0/+13
| | | | | | | to +initilize as this results in an extra call to this method. rdar://16628028 llvm-svn: 216271
* Objective-C [qoi]. Provide fix-it hint when sendingFariborz Jahanian2014-08-191-5/+13
| | | | | | class method to an object receiver. rdar://16263395 llvm-svn: 216038
* Objective-C. Do not warn if user is using property-dox syntax to name aFariborz Jahanian2014-08-151-1/+5
| | | | | | | user provided setter name (as declared in @property attribute declaration). rdar://18022762 llvm-svn: 215736
* Objective-C. Handle case of multiple class methodsFariborz Jahanian2014-08-131-1/+5
| | | | | | found in global pool as well. rdar://16808765 llvm-svn: 215603
* Objective-C. Minor refactoring of my last patch.Fariborz Jahanian2014-08-131-7/+4
| | | | | | // rdar://16808765 llvm-svn: 215581
* Objective-C. This patch is to resolve the method used in methodFariborz Jahanian2014-08-131-0/+7
| | | | | | | expression to the best method found in global method pools. This is wip. // rdar://16808765 llvm-svn: 215577
* Objective-C [qoi]. Patch to not do Fix-It for fixingFariborz Jahanian2014-08-121-3/+6
| | | | | | | | | a messaging expression except in the simple case of a unary selector. We cannot reliably provide such a fixit due to numerous reasons where a matching selector could not be found. rdar://15756038 llvm-svn: 215480
* Objective-C [qoi]. Issue warning and fixit if property-dot syntaxFariborz Jahanian2014-08-081-0/+12
| | | | | | | use mis-cased property name (which is currently accepted silently due to the way property setters are named). rdar://17911746 llvm-svn: 215250
* Objective-C. Minor refactoring of my previous patch.Fariborz Jahanian2014-08-081-36/+29
| | | | | | rdar://17554063 llvm-svn: 215235
* Objective-C ARC. Use of non-retain/autorelease APIFariborz Jahanian2014-08-081-6/+35
| | | | | | | for building Objective-C array literals in ARC mode. rdar://17554063 llvm-svn: 215232
* Objective-C arc. Switch the Objective-C dictionary literal in ARC modeFariborz Jahanian2014-08-071-6/+9
| | | | | | | to use non-retain/autorelease API variants of ObjC objects. wip. rdar://17554063 llvm-svn: 215146
* Objective-C ARC. More code for Objective-C'sFariborz Jahanian2014-08-061-2/+28
| | | | | | new APIs for literals. nfc. wip. rdar://17554063 llvm-svn: 215043
* Objective-C ARC. First patch toward generating new APIsFariborz Jahanian2014-08-061-2/+2
| | | | | | | for Objective-C's array and dictionary literals. rdar://17554063. This is wip. llvm-svn: 214983
* Replacing some more complex logic with a helper function call to ↵Aaron Ballman2014-08-011-6/+2
| | | | | | ObjCMethod::getReturnTypeSourceRange. No functional changes intended. llvm-svn: 214511
* Obective-C. Patch to fix the incorrect ObjcMessageExpr argument source ranges, Fariborz Jahanian2014-07-311-1/+1
| | | | | | | when arguments are structures or classes. PR16392. patch by Karlis Senko llvm-svn: 214409
* Objective-C. Warn if protocol used in an @protocolFariborz Jahanian2014-07-251-0/+2
| | | | | | | expression is a forward declaration as this results in undefined behavior. rdar://17768630 llvm-svn: 213968
OpenPOWER on IntegriCloud