summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaExprObjC.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Add an assert to further check the invariant that a null pointerChandler Carruth2016-11-041-0/+4
| | | | | | | | | | | corresponds to another argument being valid. This makes it clear that the code is correct despite the PVS-Studio report that a pointer might be dereferenced prior to being checked for whether it is null. It likely is also enough for static analyzers to not flag the code. llvm-svn: 285982
* Fix typos in comments.George Burgess IV2016-09-011-3/+3
| | | | llvm-svn: 280333
* ObjC Class Property: diagnostics when accessing a class property using instance.Manman Ren2016-06-281-7/+24
| | | | | | | | | | | | | When a class property is accessed with an object instance, before this commit, we try to apply a typo correction of the same property: property 'c' not found on object of type 'A *'; did you mean 'c'? With this commit, we correctly emit a diagnostics: property 'c' is a class property; did you mean to access it with class 'A'? rdar://26866973 llvm-svn: 274076
* Re-commit "[Temporary] Add an ExprWithCleanups for each C++ ↵Tim Shen2016-06-211-2/+2
| | | | | | | | | | MaterializeTemporaryExpr." Since D21243 fixes relative clang-tidy tests. This reverts commit a71d9fbd41e99def9159af2b01ef6509394eaeed. llvm-svn: 273312
* Revert "[Temporary] Add an ExprWithCleanups for each C++ ↵Tim Shen2016-06-091-2/+2
| | | | | | | | | MaterializeTemporaryExpr." This reverts r272296, since there are clang-tidy failures that appear to be caused by this change. llvm-svn: 272310
* [Temporary] Add an ExprWithCleanups for each C++ MaterializeTemporaryExpr.Tim Shen2016-06-091-2/+2
| | | | | | | | | | | 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
* [ObjC kindof] Use type bound to filter out the candidate methods.Manman Ren2016-04-071-3/+2
| | | | | | rdar://21306753 llvm-svn: 265712
* NFC: simplify code in BuildInstanceMessage.Manman Ren2016-04-071-36/+52
| | | | | | | | | | | | | | | | Instead of searching the global pool multiple times: in LookupFactoryMethodInGlobalPool, LookupInstanceMethodInGlobalPool, CollectMultipleMethodsInGlobalPool, and AreMultipleMethodsInGlobalPool, we now collect the method candidates in CollectMultipleMethodsInGlobalPool only, and other functions will use the collected method set. This commit adds parameter "Methods" to AreMultipleMethodsInGlobalPool, and SelectBestMethod. It also changes the implementation of CollectMultipleMethodsInGlobalPool to collect the desired kind first, if none is found, to collect the other kind. This avoids the need to call both LookupFactoryMethodInGlobalPool and LookupInstanceMethodInGlobalPool. llvm-svn: 265711
* [Sema] More changes to fix Objective-C fallout from r249995.Bob Wilson2016-02-131-28/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a follow-up to PR26085. That was fixed in r257710 but the testcase there was incomplete. There is a related issue where the overload resolution for Objective-C incorrectly picks a method that is not valid without a bridge cast. The call to Sema::CheckSingleAssignmentConstraints that was added to SemaOverload.cpp's IsStandardConversion() function does not catch that case and reports that the method is Compatible even when it is not. The root cause here is that various Objective-C-related functions in Sema do not consistently return a value to indicate whether there was an error. This was fine in the past because they would report diagnostics when needed, but r257710 changed them to suppress reporting diagnostics when checking during overload resolution. This patch adds a new ACR_error result to the ARCConversionResult enum and updates Sema::CheckObjCARCConversion to return that value when there is an error. Most of the calls to that function do not check the return value, so adding this new result does not affect them. The one exception is in SemaCast.cpp where it specifically checks for ACR_unbridged, so that is also OK. The call in Sema::CheckSingleAssignmentConstraints can then check for an ACR_okay result and identify assignments as Incompatible. To preserve the existing behavior, it only changes the return value to Incompatible when the new Diagnose argument (from r257710) is false. Similarly, the CheckObjCBridgeRelatedConversions and ConversionToObjCStringLiteralCheck need to identify when an assignment is Incompatible. Those functions already return appropriate values but they need some fixes related to the new Diagnose argument. llvm-svn: 260787
* Fix remaining Clang-tidy readability-redundant-control-flow warnings; other ↵Eugene Zelenko2016-02-121-10/+4
| | | | | | | | minor fixes. Differential revision: http://reviews.llvm.org/D17218 llvm-svn: 260757
* Class Property: class property and instance property can have the same name.Manman Ren2016-01-281-4/+7
| | | | | | | | | | | | | | | | | | | Add "enum ObjCPropertyQueryKind" to a few APIs that used to only take the name of the property: ObjCPropertyDecl::findPropertyDecl, ObjCContainerDecl::FindPropertyDeclaration, ObjCInterfaceDecl::FindPropertyVisibleInPrimaryClass, ObjCImplDecl::FindPropertyImplDecl, and Sema::ActOnPropertyImplDecl. ObjCPropertyQueryKind currently has 3 values: OBJC_PR_query_unknown, OBJC_PR_query_instance, OBJC_PR_query_class This extra parameter specifies that we are looking for an instance property with the given name, or a class property with the given name, or any property with the given name (if both exist, the instance property will be returned). rdar://23891898 llvm-svn: 259070
* OpaquePtr: Use nullptr construction for ParsedType OpaquePtr typedefDavid Blaikie2016-01-151-1/+1
| | | | llvm-svn: 257958
* [Sema] Suppress diags in overload resolution.George Burgess IV2016-01-131-59/+75
| | | | | | | | | | We were emitting diagnostics from our shiny new C-only overload resolution mode. This patch attempts to silence all such diagnostics. This fixes PR26085. Differential Revision: http://reviews.llvm.org/D16159 llvm-svn: 257710
* Properly track that a character literal is UTF-8, and pretty print the ↵Aaron Ballman2016-01-071-0/+2
| | | | | | prefix properly. llvm-svn: 257097
* [TrailingObjects] Convert classes in ExprObjC.hJames Y Knight2015-12-311-3/+3
| | | | llvm-svn: 256659
* [Sema] ArrayRef-ize BuildObjCDictionaryLiteral. NFCCraig Topper2015-12-241-15/+14
| | | | llvm-svn: 256398
* [Sema] ArrayRef-ize ParseObjCStringLiteral and ↵Craig Topper2015-12-241-8/+5
| | | | | | CodeCompleteObjCProtocolReferences. NFC llvm-svn: 256397
* Split RequireCompleteType into a function that actually requires that the typeRichard Smith2015-12-181-0/+2
| | | | | | | | | | | | | | | | | | | is complete (with an error produced if not) and a function that merely queries whether the type is complete. Either way we'll trigger instantiation if necessary, but only the former will diagnose and recover from missing module imports. The intent of this change is to prevent a class of bugs where code would call RequireCompleteType(..., 0) and then ignore the result. With modules, we must check the return value and use it to determine whether the definition of the type is visible. This also fixes a debug info quality issue: calls to isCompleteType do not trigger the emission of debug information for a type in limited-debug-info mode. This allows us to avoid emitting debug information for type definitions in more cases where we believe it is safe to do so. llvm-svn: 256049
* Use Sema::getLocForEndOfToken instead of Preprocessor::getLocForEndOfToken. NFCCraig Topper2015-11-151-6/+6
| | | | llvm-svn: 253155
* Stop back-patching 'readonly' Objective-C properties with 'readwrite' ones.Douglas Gregor2015-11-031-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | A 'readonly' Objective-C property declared in the primary class can effectively be shadowed by a 'readwrite' property declared within an extension of that class, so long as the types and attributes of the two property declarations are compatible. Previously, this functionality was implemented by back-patching the original 'readonly' property to make it 'readwrite', destroying source information and causing some hideously redundant, incorrect code. Simplify the implementation to express how this should actually be modeled: as a separate property declaration in the extension that shadows (via the name lookup rules) the declaration in the primary class. While here, correct some broken Fix-Its, eliminate a pile of redundant code, clean up the ARC migrator's handling of properties declared in extensions, and fix debug info's naming of methods that come from categories. A wonderous side effect of doing this write is that it eliminates the "AddedObjCPropertyInClassExtension" method from the AST mutation listener, which in turn eliminates the last place where we rewrite entire declarations in a chained PCH file or a module file. This change (which fixes rdar://problem/18475765) will allow us to eliminate the rewritten-decls logic from the serialization library, and fixes a crash (rdar://problem/23247794) illustrated by the test/PCH/chain-categories.m example. llvm-svn: 251874
* Refine r251469 to give better (and more localizable) diagnosticsJohn McCall2015-10-281-1/+1
| | | | | | for all the reasons that ARC makes things implicitly unavailable. llvm-svn: 251496
* Be slightly more permissive when checking for type-erased blocks.Bob Wilson2015-10-021-1/+2
| | | | | | This is a patch from Doug that was inadvertently omitted from r241543. llvm-svn: 249116
* Silence a "not all control paths return a value" warning from MSVC. Should ↵Aaron Ballman2015-07-241-1/+2
| | | | | | also silence a -Wreturn-type warning. NFC intended. llvm-svn: 243109
* Cleanup ObjCInterfaceDecl lookup for ObjC literalsAlex Denisov2015-07-241-99/+98
| | | | llvm-svn: 243092
* 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
OpenPOWER on IntegriCloud