summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaObjC
Commit message (Collapse)AuthorAgeFilesLines
...
* Define weak and __weak to mean ARC-style weak references, even in MRC.John McCall2015-10-226-27/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, __weak was silently accepted and ignored in MRC mode. That makes this a potentially source-breaking change that we have to roll out cautiously. Accordingly, for the time being, actual support for __weak references in MRC is experimental, and the compiler will reject attempts to actually form such references. The intent is to eventually enable the feature by default in all non-GC modes. (It is, of course, incompatible with ObjC GC's interpretation of __weak.) If you like, you can enable this feature with -Xclang -fobjc-weak but like any -Xclang option, this option may be removed at any point, e.g. if/when it is eventually enabled by default. This patch also enables the use of the ARC __unsafe_unretained qualifier in MRC. Unlike __weak, this is being enabled immediately. Since variables are essentially __unsafe_unretained by default in MRC, the only practical uses are (1) communication and (2) changing the default behavior of by-value block capture. As an implementation matter, this means that the ObjC ownership qualifiers may appear in any ObjC language mode, and so this patch removes a number of checks for getLangOpts().ObjCAutoRefCount that were guarding the processing of these qualifiers. I don't expect this to be a significant drain on performance; it may even be faster to just check for these qualifiers directly on a type (since it's probably in a register anyway) than to do N dependent loads to grab the LangOptions. rdar://9674298 llvm-svn: 251041
* Some minor ARC diagnostic improvements.John McCall2015-10-212-3/+13
| | | | llvm-svn: 250917
* [Sema/objc] When checking for unimplemented methods treat methods from class ↵Argyrios Kyrtzidis2015-10-132-4/+15
| | | | | | extensions as continuation of the class interface. llvm-svn: 250250
* Fix inference of _Nullable for weak Objective-C properties.Douglas Gregor2015-10-092-4/+12
| | | | | | | | | | | | | | | | | | | | The inference of _Nullable for weak Objective-C properties was broken in several ways: * It was back-patching the type information very late in the process of checking the attributes for an Objective-C property, which is just wrong. * It was using ad hoc checks to try to suppress the warning about missing nullability specifiers (-Wnullability-completeness), which didn't actual work in all cases (rdar://problem/22985457) * It was inferring _Nullable even outside of assumes-nonnull regions, which is wrong. Putting the inference of _Nullable for weak Objective-C properties in the same place as all of the other inference logic fixes all of these ills. llvm-svn: 249896
* [MSVC Compat] Try to treat an implicit, fixed enum as an unfixed enumDavid Majnemer2015-10-081-1/+1
| | | | | | | | | | | | | | | | | | consider the following: enum E *p; enum E { e }; The above snippet is not ANSI C because 'enum E' has not bee defined when we are processing the declaration of 'p'; however, it is a popular extension to make the above work. This would fail using the Microsoft enum semantics because the definition of 'E' would implicitly have a fixed underlying type of 'int' which would trigger diagnostic messages about a mismatch between the declaration and the definition. Instead, treat fixed underlying types as not fixed for the purposes of the diagnostic. llvm-svn: 249674
* Update a few more tests in response to the MS ABI enum semanticsDavid Majnemer2015-10-082-2/+2
| | | | | | | Our self hosting buildbots found a few more tests which weren't updated to reflect that the enum semantics are part of the Microsoft ABI. llvm-svn: 249670
* Don't inherit the "unavailable" attribute from an overridden superclass method.Douglas Gregor2015-09-301-0/+16
| | | | | | Fixes rdar://problem/22922259. llvm-svn: 248950
* Don't inherit availability information when implementing a protocol requirement.Douglas Gregor2015-09-301-0/+72
| | | | | | | | | | When an Objective-C method implements a protocol requirement, do not inherit any availability information from the protocol requirement. Rather, check that the implementation is not less available than the protocol requirement, as we do when overriding a method that has availability. Fixes rdar://problem/22734745. llvm-svn: 248949
* Forbid qualifiers on ObjC generic parameters and arguments, butJohn McCall2015-09-231-0/+107
| | | | | | | | | | | | | | silently ignore them on arguments when they're provided indirectly (.e.g behind a template argument or typedef). This is mostly just good language design --- specifying that a generic argument is __weak doesn't actually do anything --- but it also prevents assertions when trying to apply a different ownership qualifier. rdar://21612439 llvm-svn: 248436
* C11 _Bool bitfield diagnosticRachel Craik2015-09-141-1/+1
| | | | | | | | | | | | Summary: Implement DR262 (for C). This patch will mainly affect bitfields of type _Bool Reviewers: fraggamuffin, rsmith Subscribers: hubert.reinterpretcast, cfe-commits Differential Revision: http://reviews.llvm.org/D10018 llvm-svn: 247618
* [SemaObjC] Remove unused code from test.Alex Denisov2015-08-211-42/+6
| | | | | | Patch by modocache (Brian Gesiak). llvm-svn: 245731
* [Sema] Be consistent about diagnostic wording: always use "cannot".Davide Italiano2015-08-151-1/+1
| | | | | | Discussed with Richard Smith. llvm-svn: 245162
* [ObjC] Circular containers: add support of subclassesAlex Denisov2015-08-061-0/+61
| | | | llvm-svn: 244193
* Update mailing list references to lists.llvm.orgTanya Lattner2015-08-051-1/+1
| | | | llvm-svn: 244000
* [sema] Allow to opt-out of overriding the super class's designated ↵Argyrios Kyrtzidis2015-07-301-1/+11
| | | | | | | | initializers by marking the initializer as unavailable in the subclass. rdar://20281322 llvm-svn: 243676
* [sema] Fix crash when typo-transforming an expression containing an ObjC ↵Argyrios Kyrtzidis2015-07-281-3/+13
| | | | | | | | super message expression. rdar://21427916 llvm-svn: 243387
* Cleanup ObjCInterfaceDecl lookup for ObjC literalsAlex Denisov2015-07-244-14/+14
| | | | llvm-svn: 243092
* Add missing files for objc_boxable feature.Alex Denisov2015-07-231-0/+101
| | | | | | Original patch [r240761] is missing all new files because of committer's mistake. llvm-svn: 243018
* Add __has_feature(attribute_availability_with_version_underscores).Jordan Rose2015-07-161-0/+4
| | | | | | | | This goes with r218884 from, um, last autumn. rdar://problem/21754114 llvm-svn: 242480
* [Sema] Emit a better diagnostic when variable redeclarations disagreeDavid Majnemer2015-07-141-8/+8
| | | | | | | | | | | We referred to all declaration in definitions in our diagnostic messages which is can be inaccurate. Instead, classify the declaration and emit an appropriate diagnostic for the new declaration and an appropriate note pointing to the old one. This fixes PR24116. llvm-svn: 242190
* s/__nonnull/_Nonnull in a test for Objective-C __kindof.Douglas Gregor2015-07-071-1/+1
| | | | llvm-svn: 241563
* Implement variance for Objective-C type parameters.Douglas Gregor2015-07-072-0/+70
| | | | | | | | | | | | | | | Introduce co- and contra-variance for Objective-C type parameters, which allows us to express that (for example) an NSArray is covariant in its type parameter. This means that NSArray<NSMutableString *> * is a subtype of NSArray<NSString *> *, which is expected of the immutable Foundation collections. Type parameters can be annotated with __covariant or __contravariant to make them co- or contra-variant, respectively. This feature can be detected by __has_feature(objc_generics_variance). Implements rdar://problem/20217490. llvm-svn: 241549
* Implement the Objective-C __kindof type qualifier.Douglas Gregor2015-07-072-1/+317
| | | | | | | | | | 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
* Warn when an intended Objective-C specialization was actually a useless ↵Douglas Gregor2015-07-071-1/+9
| | | | | | | | | | | | | | | | | | | | | | protocol qualification. Warn in cases where one has provided redundant protocol qualification that might be a typo for a specialization, e.g., NSArray<NSObject>, which is pointless (NSArray declares that it conforms to NSObject) and is likely to be a typo for NSArray<NSObject *>, i.e., an array of NSObject pointers. This warning is very narrow, only applying when the base type being qualified is parameterized, has the same number of parameters as their are protocols listed, all of the names can also refer to types (including Objective-C class types, of course), and at least one of those types is an Objective-C class (making this a typo for a missing '*'). The limitations are partly for performance reasons (we don't want to do redundant name lookup unless we really need to), and because we want the warning to apply in very limited cases to limit false positives. Part of rdar://problem/6294649. llvm-svn: 241547
* Warn when an Objective-C collection literal element is converted to an ↵Douglas Gregor2015-07-071-0/+52
| | | | | | | | | | | | incompatible type. Objective-C collection literals produce unspecialized NSArray/NSDictionary objects that can then be implicitly converted to specialized versions of these types. In such cases, check that the elements in the collection are suitable for the specialized collection. Part of rdar://problem/6294649. llvm-svn: 241546
* C++ support for Objective-C lightweight generics.Douglas Gregor2015-07-072-4/+12
| | | | | | | | | | | | | | | | | | | Teach C++'s tentative parsing to handle specializations of Objective-C class types (e.g., NSArray<NSString *>) as well as Objective-C protocol qualifiers (id<NSCopying>) by extending type-annotation tokens to handle this case. As part of this, remove Objective-C protocol qualifiers from the declaration specifiers, which never really made sense: instead, provide Sema entry points to make them part of the type annotation token. Among other things, this properly diagnoses bogus types such as "<NSCopying> id" which should have been written as "id <NSCopying>". Implements template instantiation support for, e.g., NSArray<T>* in C++. Note that parameterized classes are not templates in the C++ sense, so that cannot (for example) be used as a template argument for a template template parameter. Part of rdar://problem/6294649. llvm-svn: 241545
* Improve the Objective-C common-type computation used by the ternary operator.Douglas Gregor2015-07-075-5/+61
| | | | | | | | | | | | | | | | The Objective-C common-type computation had a few problems that required a significant rework, including: - Quadradic behavior when finding the common base type; now it's linear. - Keeping around type arguments when computing the common type between a specialized and an unspecialized type - Introducing redundant protocol qualifiers. Part of rdar://problem/6294649. Also fixes rdar://problem/19572837 by addressing a longstanding bug in ASTContext::CollectInheritedProtocols(). llvm-svn: 241544
* Substitute type arguments into uses of Objective-C interface members.Douglas Gregor2015-07-072-15/+375
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-072-8/+141
| | | | | | | | | | | | | | | | | | | | | 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-0/+192
| | | | | | | | | | | | | | | | | | | | 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
* Parse 'technical term' format specifier.Ted Kremenek2015-07-021-0/+13
| | | | | | | | | | | | | | | | | | | | | | | Objective-C format strings now support modifier flags that can be attached to a '@' conversion. Currently the only one supported, as of iOS 9 and OS X 10.11, is the new "technical term", denoted by the flag "tt", for example: %[tt]@ instead of just: %@ The 'tt' stands for "technical term", which is used by the string-localization facilities on Darwin to add the appropriate spacing or quotation depending the language locale. Implements <rdar://problem/20374720>. llvm-svn: 241243
* Replace __double_underscored type nullability qualifiers with ↵Douglas Gregor2015-06-244-66/+66
| | | | | | | | | | | | | | | | _Uppercase_underscored Addresses a conflict with glibc's __nonnull macro by renaming the type nullability qualifiers as follows: __nonnull -> _Nonnull __nullable -> _Nullable __null_unspecified -> _Null_unspecified This is the major part of rdar://problem/21530726, but does not yet provide the Darwin-specific behavior for the old names. llvm-svn: 240596
* Stop moving attributes off of a block literal's decl specifiers.Douglas Gregor2015-06-191-0/+8
| | | | | | | | | | These usually apply to the return type. At one point this was necessary to get some of them to apply to the entire block, but it appears that's working anyway (see block-return.c). rdar://problem/20468034 llvm-svn: 240189
* Handle 'instancetype' in ParseDeclarationSpecifiers.Douglas Gregor2015-06-191-0/+7
| | | | | | | | | | ...instead of as a special case in ParseObjCTypeName with lots of duplicated logic. Besides being a nice refactoring, this also allows "- (instancetype __nonnull)self" in addition to "- (nonnull instancetype)self". rdar://problem/19924646 llvm-svn: 240188
* Allow the cf_returns_[not_]retained attributes to appear on out-parameters.Douglas Gregor2015-06-191-0/+49
| | | | | | | | | | | | | | | | Includes a simple static analyzer check and not much else, but we'll also be able to take advantage of this in Swift. This feature can be tested for using __has_feature(cf_returns_on_parameters). This commit also contains two fixes: - Look through non-typedef sugar when deciding whether something is a CF type. - When (cf|ns)_returns(_not)?_retained is applied to invalid properties, refer to "property" instead of "method" in the error message. rdar://problem/18742441 llvm-svn: 240185
* Introduced pragmas for audited nullability regions.Douglas Gregor2015-06-191-2/+20
| | | | | | | | | | | | | | | | | 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
* Implement the 'null_resettable' attribute for Objective-C properties.Douglas Gregor2015-06-191-0/+39
| | | | | | | | 'null_resettable' properties are those whose getters return nonnull but whose setters take nil, to "reset" the property to some default. Implements rdar://problem/19051334. llvm-svn: 240155
* Extend type nullability qualifiers for Objective-C.Douglas Gregor2015-06-195-6/+192
| | | | | | | | | | | | | | | 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
* Diagnose unsafe uses of nil and __nonnull pointers.Douglas Gregor2015-06-192-0/+24
| | | | | | | | | | | | | | | | | | | This generalizes the checking of null arguments to also work with values of pointer-to-function, reference-to-function, and block pointer type, using the nullability information within the underling function prototype to extend non-null checking, and diagnoses returns of 'nil' within a function with a __nonnull return type. Note that we don't warn about nil returns from Objective-C methods, because it's common for Objective-C methods to mimic the nil-swallowing behavior of the receiver by checking ostensibly non-null parameters and returning nil from otherwise non-null methods in that case. It also diagnoses (via a separate flag) conversions from nullable to nonnull pointers. It's a separate flag because this warning can be noisy. llvm-svn: 240153
* Introduce type nullability specifiers for C/C++.Douglas Gregor2015-06-191-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | Introduces the type specifiers __nonnull, __nullable, and __null_unspecified that describe the nullability of the pointer type to which the specifier appertains. Nullability type specifiers improve on the existing nonnull attributes in a few ways: - They apply to types, so one can represent a pointer to a non-null pointer, use them in function pointer types, etc. - As type specifiers, they are syntactically more lightweight than __attribute__s or [[attribute]]s. - They can express both the notion of 'should never be null' and also 'it makes sense for this to be null', and therefore can more easily catch errors of omission where one forgot to annotate the nullability of a particular pointer (this will come in a subsequent patch). Nullability type specifiers are maintained as type sugar, and therefore have no effect on mangling, encoding, overloading, etc. Nonetheless, they will be used for warnings about, e.g., passing 'null' to a method that does not accept it. This is the C/C++ part of rdar://problem/18868820. llvm-svn: 240146
* Tweak availability checking to look through typedef declarations.Ted Kremenek2015-05-141-0/+16
| | | | llvm-svn: 237396
* Fix PR22047: ObjC: Method unavailability attribute doesn't work with ↵Jonathan Roelofs2015-04-281-0/+19
| | | | | | | | overloaded methods http://reviews.llvm.org/D9261 llvm-svn: 236006
* [Sema] Check availability of ObjC super class and protocols of a containerArgyrios Kyrtzidis2015-04-191-0/+31
| | | | | | | | | | | in the context of the container itself. Otherwise we will emit 'unavailable' errors when referencing an unavailable super class even though the subclass is also marked 'unavailable'. rdar://20598702 llvm-svn: 235276
* [Objective-C Sema]. In my last patch change theFariborz Jahanian2015-04-162-36/+36
| | | | | | | attribute name to objc_independent_class. rdar://20255473 llvm-svn: 235135
* [Objective-C Sema] patch to introduce IndependentClassFariborz Jahanian2015-04-161-0/+36
| | | | | | | | | attribute to be placed on Objective-C pointer typedef to make them strong enough so on their "new" method family no attempt is made to override these types. rdar://20255473 llvm-svn: 235128
* [Objective-C Sema]This patch fixes the warning when clang issuesFariborz Jahanian2015-04-151-5/+32
| | | | | | | | | | "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
* Improve the error message for assigning to read-only variables.Richard Trieu2015-04-111-2/+2
| | | | | | | | | | Previously, many error messages would simply be "read-only variable is not assignable" This change provides more information about why the variable is not assignable, as well as note to where the const is located. Differential Revision: http://reviews.llvm.org/D4479 llvm-svn: 234677
* [Objective-C Sema] Fixes a typo which did not allow Fariborz Jahanian2015-04-103-4/+17
| | | | | | | 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-0/+9
| | | | | | | of a CFType bridged to some unknown Objective-C type. rdar://20113785 llvm-svn: 234545
* [Objective-C Sema] Use canonical type of properties when comparing Fariborz Jahanian2015-04-081-0/+15
| | | | | | | redeclaration of property in class extension and to avoid bogus error. rdar://20469452 llvm-svn: 234440
OpenPOWER on IntegriCloud