summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaObjCProperty.cpp
Commit message (Collapse)AuthorAgeFilesLines
* Also synthesize _cmd and self for propertiesPierre Habouzit2019-12-091-0/+6
| | | | | | Patch by: Pierre Habouzit Differential Revision: https://reviews.llvm.org/D71226
* Set a source location for Objective-C accessor stubsAdrian Prantl2019-12-051-4/+6
| | | | | | | | | | | | even when there is no explicit synthesize statement. This fixes a regression introduced in https://reviews.llvm.org/D68108 that could lead to missing debug locations in cleanup code in synthesized Objective-C++ properties. rdar://57630879 Differential Revision: https://reviews.llvm.org/D71084
* Implement __attribute__((objc_direct)), __attribute__((objc_direct_members))Pierre Habouzit2019-11-181-1/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | __attribute__((objc_direct)) is an attribute on methods declaration, and __attribute__((objc_direct_members)) on implementation, categories or extensions. A `direct` property specifier is added (@property(direct) type name) These attributes / specifiers cause the method to have no associated Objective-C metadata (for the property or the method itself), and the calling convention to be a direct C function call. The symbol for the method has enforced hidden visibility and such direct calls are hence unreachable cross image. An explicit C function must be made if so desired to wrap them. The implicit `self` and `_cmd` arguments are preserved, however to maintain compatibility with the usual `objc_msgSend` semantics, 3 fundamental precautions are taken: 1) for instance methods, `self` is nil-checked. On arm64 backends this typically adds a single instruction (cbz x0, <closest-ret>) to the codegen, for the vast majority of the cases when the return type is a scalar. 2) for class methods, because the class may not be realized/initialized yet, a call to `[self self]` is emitted. When the proper deployment target is used, this is optimized to `objc_opt_self(self)`. However, long term we might want to emit something better that the optimizer can reason about. When inlining kicks in, these calls aren't optimized away as the optimizer has no idea that a single call is really necessary. 3) the calling convention for the `_cmd` argument is changed: the caller leaves the second argument to the call undefined, and the selector is loaded inside the body when it's referenced only. As far as error reporting goes, the compiler refuses: - making any overloads direct, - making an overload of a direct method, - implementations marked as direct when the declaration in the interface isn't (the other way around is allowed, as the direct attribute is inherited from the declaration), - marking methods required for protocol conformance as direct, - messaging an unqualified `id` with a direct method, - forming any @selector() expression with only direct selectors. As warnings: - any inconsistency of direct-related calling convention when @selector() or messaging is used, - forming any @selector() expression with a possibly direct selector. Lastly an `objc_direct_members` attribute is added that can decorate `@implementation` blocks and causes methods only declared there (and in no `@interface`) to be automatically direct. When decorating an `@interface` then all methods and properties declared in this block are marked direct. Radar-ID: rdar://problem/2684889 Differential Revision: https://reviews.llvm.org/D69991 Reviewed-By: John McCall
* Fix variable ‘LookedUpGetterSetter’ set but not used warning. NFCI.Simon Pilgrim2019-11-091-2/+0
|
* Redeclare Objective-C property accessors inside the ObjCImplDecl in which ↵Adrian Prantl2019-11-081-29/+82
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | they are synthesized. This patch is motivated by (and factored out from) https://reviews.llvm.org/D66121 which is a debug info bugfix. Starting with DWARF 5 all Objective-C methods are nested inside their containing type, and that patch implements this for synthesized Objective-C properties. 1. SemaObjCProperty populates a list of synthesized accessors that may need to inserted into an ObjCImplDecl. 2. SemaDeclObjC::ActOnEnd inserts forward-declarations for all accessors for which no override was provided into their ObjCImplDecl. This patch does *not* synthesize AST function *bodies*. Moving that code from the static analyzer into Sema may be a good idea though. 3. Places that expect all methods to have bodies have been updated. I did not update the static analyzer's inliner for synthesized properties to point back to the property declaration (see test/Analysis/Inputs/expected-plists/nullability-notes.m.plist), which I believed to be more bug than a feature. Differential Revision: https://reviews.llvm.org/D68108 rdar://problem/53782400
* [NFCI]Create CommonAttributeInfo Type as base type of *Attr and ParsedAttr.Erich Keane2019-09-131-6/+6
| | | | | | | | | | | | In order to enable future improvements to our attribute diagnostics, this moves info from ParsedAttr into CommonAttributeInfo, then makes this type the base of the *Attr and ParsedAttr types. Quite a bit of refactoring took place, including removing a bunch of redundant Spelling Index propogation. Differential Revision: https://reviews.llvm.org/D67368 llvm-svn: 371875
* clang: Fix typo in commentNico Weber2019-08-211-1/+1
| | | | llvm-svn: 369542
* Fix parameter name comments using clang-tidy. NFC.Rui Ueyama2019-07-161-1/+1
| | | | | | | | | | | | | | | | | | | | | This patch applies clang-tidy's bugprone-argument-comment tool to LLVM, clang and lld source trees. Here is how I created this patch: $ git clone https://github.com/llvm/llvm-project.git $ cd llvm-project $ mkdir build $ cd build $ cmake -GNinja -DCMAKE_BUILD_TYPE=Debug \ -DLLVM_ENABLE_PROJECTS='clang;lld;clang-tools-extra' \ -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DLLVM_ENABLE_LLD=On \ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ ../llvm $ ninja $ parallel clang-tidy -checks='-*,bugprone-argument-comment' \ -config='{CheckOptions: [{key: StrictMode, value: 1}]}' -fix \ ::: ../llvm/lib/**/*.{cpp,h} ../clang/lib/**/*.{cpp,h} ../lld/**/*.{cpp,h} llvm-svn: 366177
* Range-style std::find{,_if} -> llvm::find{,_if}. NFCFangrui Song2019-03-311-5/+4
| | | | llvm-svn: 357359
* [Sema][ObjC] Allow silencing -Wobjc-designated-initializers warnings byAkira Hatanaka2019-03-011-0/+9
| | | | | | | | | | | | | declaring an unavailable method in the subclass's extension that overrides the designated initializer in the base class. r243676 made changes to allow declaring the unavailable method in the subclass interface to silence the warning. This commit additionally allows declaring the unavailable method in the class extension. rdar://problem/42731306 llvm-svn: 355175
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [AST][NFC] Pass the AST context to one of the ctor of DeclRefExpr.Bruno Ricci2018-12-211-8/+8
| | | | | | | | | All of the other constructors already take a reference to the AST context. This avoids calling Decl::getASTContext in most cases. Additionally move the definition of the constructor from Expr.h to Expr.cpp since it is calling DeclRefExpr::computeDependence. NFC. llvm-svn: 349901
* Add -Wobjc-property-assign-on-object-type.John McCall2018-09-051-0/+8
| | | | | | | | | | | | This is a warning about using 'assign' instead of 'unsafe_unretained' in Objective-C property declarations. It's off by default because there isn't consensus in the Objective-C steering group that this is the right thing to do, but we're nonetheless okay with adding it because there's a substantial pool of Objective-C programmers who will appreciate the warning. Patch by Alfred Zien! llvm-svn: 341489
* Model type attributes as regular Attrs.Richard Smith2018-08-201-2/+2
| | | | | | | | | | | | | | Specifically, AttributedType now tracks a regular attr::Kind rather than having its own parallel Kind enumeration, and AttributedTypeLoc now holds an Attr* instead of holding an ad-hoc collection of Attr fields. Differential Revision: https://reviews.llvm.org/D50526 This reinstates r339623, reverted in r339638, with a fix to not fail template instantiation if we instantiate a QualType with no associated type source information and we encounter an AttributedType. llvm-svn: 340215
* Revert r339623 "Model type attributes as regular Attrs."Reid Kleckner2018-08-141-2/+2
| | | | | | | | This breaks compiling atlwin.h in Chromium. I'm sure the code is invalid in some way, but we put a lot of work into accepting it, and I'm sure rejecting it was not an intended consequence of this refactoring. :) llvm-svn: 339638
* Model type attributes as regular Attrs.Richard Smith2018-08-131-2/+2
| | | | | | | | | | Specifically, AttributedType now tracks a regular attr::Kind rather than having its own parallel Kind enumeration, and AttributedTypeLoc now holds an Attr* instead of holding an ad-hoc collection of Attr fields. Differential Revision: https://reviews.llvm.org/D50526 llvm-svn: 339623
* Port getLocEnd -> getEndLocStephen Kelly2018-08-091-2/+2
| | | | | | | | | | Reviewers: teemperor! Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50351 llvm-svn: 339386
* Port getLocStart -> getBeginLocStephen Kelly2018-08-091-5/+5
| | | | | | | | | | Reviewers: teemperor! Subscribers: jholewinski, whisperity, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D50350 llvm-svn: 339385
* Remove trailing spaceFangrui Song2018-07-301-69/+69
| | | | | | sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
* Remove \brief commands from doxygen comments.Adrian Prantl2018-05-091-2/+2
| | | | | | | | | | | | | | | | | | | This is similar to the LLVM change https://reviews.llvm.org/D46290. We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46320 llvm-svn: 331834
* [ObjC] The absence of ownership qualifiers on an ambiguous property leadsAlex Lorenz2018-05-021-4/+14
| | | | | | | | | to synthesis of a valid property even when the selected protocol property has ownership qualifiers rdar://39024725 llvm-svn: 331409
* Remove redundant casts. NFCGeorge Burgess IV2018-03-011-1/+1
| | | | | | | | | | | | | | | | | | | So I wrote a clang-tidy check to lint out redundant `isa`, `cast`, and `dyn_cast`s for fun. This is a portion of what it found for clang; I plan to do similar cleanups in LLVM and other subprojects when I find time. Because of the volume of changes, I explicitly avoided making any change that wasn't highly local and obviously correct to me (e.g. we still have a number of foo(cast<Bar>(baz)) that I didn't touch, since overloading is a thing and the cast<Bar> did actually change the type -- just up the class hierarchy). I also tried to leave the types we were cast<>ing to somewhere nearby, in cases where it wasn't locally obvious what we were dealing with before. llvm-svn: 326416
* [Sema] Add support for flexible array members in Obj-C.Volodymyr Sapsai2017-10-231-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Allow Obj-C ivars with incomplete array type but only as the last ivar. Also add a requirement for ivars that contain a flexible array member to be at the end of class too. It is possible to add in a subclass another ivar at the end but we'll emit a warning in this case. Also we'll emit a warning if a variable sized ivar is declared in class extension or in implementation because subclasses won't know they should avoid adding new ivars. In ARC incomplete array objects are treated as __unsafe_unretained so require them to be marked as such. Prohibit synthesizing ivars with flexible array members because order of synthesized ivars is not obvious and tricky to control. Spelling out ivar explicitly gives control to developers and helps to avoid surprises with unexpected ivar ordering. For C and C++ changed diagnostic to tell explicitly a field is not the last one and point to the next field. It is not as useful as in Obj-C but it is an improvement and it is consistent with Obj-C. For C for unions emit more specific err_flexible_array_union instead of generic err_field_incomplete. rdar://problem/21054495 Reviewers: rjmccall, theraven Reviewed By: rjmccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D38773 llvm-svn: 316381
* [ObjC] Don't warn on readwrite properties with custom setters thatAlex Lorenz2017-10-061-1/+5
| | | | | | | | override readonly properties from protocols rdar://34192541 llvm-svn: 315093
* [ObjC] Check written attributes only when synthesizing ambiguous propertyAlex Lorenz2017-08-221-2/+2
| | | | | | | | | | | | | | | | | This commit fixes a bug introduced in r307903. The attribute ambiguity checker that was introduced in r307903 checked all property attributes, which caused errors for source-compatible properties, like: @property (nonatomic, readonly) NSObject *prop; @property (nonatomic, readwrite) NSObject *prop; because the readwrite property would get implicit 'strong' attribute. The ambiguity checker should be concerned about explicitly specified attributes only. rdar://33748089 llvm-svn: 311443
* [Sema] Silence -Wobjc-missing-property-synthesis for unavailable propertiesAlex Lorenz2017-08-151-1/+1
| | | | | | rdar://30296911 llvm-svn: 310916
* [ObjC] Pick a 'readwrite' property when synthesizing ambiguousAlex Lorenz2017-07-131-27/+160
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | property and check for incompatible attributes This commit changes the way ambiguous property synthesis (i.e. when synthesizing a property that's declared in multiple protocols) is performed. Previously, Clang synthesized the first property that was found. This lead to problems when the property was synthesized in a class that conformed to two protocols that declared that property and a second protocols had a 'readwrite' declaration - the setter was not synthesized so the class didn't really conform to the second protocol and user's code would crash at runtime when they would try to set the property. This commit ensures that a first readwrite property is selected. This is a semantic change that changes users code in this manner: ``` @protocol P @property(readonly) int p; @end @protocol P2 @property(readwrite) id p; @end @interface I <P2> @end @implementation I @syntesize p; // Users previously got a warning here, and Clang synthesized // readonly 'int p' here. Now Clang synthesizes readwrite 'id' p.. @end ``` To ensure that this change is safe, the warning about incompatible types is promoted to an error when this kind of readonly/readwrite ambiguity is detected in the @implementation. This will ensure that previous code that had this subtle bug and ignored the warning now will fail to compile with an error, and users should not get suprises at runtime once they resolve the error. The commit also extends the ambiguity checker, and now it can detect conflicts among the different property attributes. An error diagnostic is used for conflicting attributes, to ensure that the user won't get "suprises" at runtime. ProtocolPropertyMap is removed in favour of a a set + vector because the map's order of iteration is non-deterministic, so it couldn't be used to select the readwrite property. rdar://31579994 Differential Revision: https://reviews.llvm.org/D35268 llvm-svn: 307903
* Add a fixit for -Wobjc-protocol-property-synthesisAlex Lorenz2017-07-031-4/+10
| | | | | | | | rdar://32132756 Differential Revision: https://reviews.llvm.org/D34886 llvm-svn: 307014
* [Sema][ObjC] Avoid the "type of property does not match type of accessor"Alex Lorenz2017-03-301-6/+3
| | | | | | | | warning for methods that resemble the setters of readonly properties rdar://30415679 llvm-svn: 299078
* [index/AST] Add references for ObjC getter=/setter= property attributes and ↵Argyrios Kyrtzidis2017-03-161-10/+18
| | | | | | | | | | | related property getter/setter role fixes This enhances the AST to keep track of locations of the names in those ObjC property attributes, and reports them for indexing. Patch by Nathan Hawes! https://reviews.llvm.org/D30907 llvm-svn: 297972
* Move checks for creation of objects of abstract class type from the variousRichard Smith2016-12-151-2/+4
| | | | | | | | | constructs that can do so into the initialization code. This fixes a number of different cases in which we used to fail to check for abstract types. Thanks to Tim Shen for inspiring the weird code that uncovered this! llvm-svn: 289753
* Mass-rename the handful of error_* diagnostics to err_*.Richard Smith2016-12-021-21/+21
| | | | llvm-svn: 288545
* [ObjC] Remove _Atomic from return type and parameter type ofAkira Hatanaka2016-05-261-8/+16
| | | | | | | | | | | | | | objective-c properties. This fixes an assert in CodeGen that fires when the getter and setter functions for an objective-c property of type _Atomic(_Bool) are synthesized. rdar://problem/26322972 Differential Revision: http://reviews.llvm.org/D20407 llvm-svn: 270808
* ObjectiveC Class Properties: warn if a class property accessor is mistakenly anManman Ren2016-05-181-12/+16
| | | | | | | | | | | | | instance method. When diagnosing unimplemented class property, make sure we emit a warning when we only see an instance method with the right selector. Also warn when we only see a class method for an instance property. rdar://26141719 llvm-svn: 269968
* ObjC class properties: add diagnostics for unimplemented class properties.Manman Ren2016-04-121-42/+62
| | | | | | rdar://24711047 llvm-svn: 266146
* ObjC: add getter/setter for class properties to global pool.Manman Ren2016-03-231-0/+5
| | | | | | rdar://problem/25323072 llvm-svn: 264196
* Fix remaining Clang-tidy readability-redundant-control-flow warnings; other ↵Eugene Zelenko2016-02-121-5/+0
| | | | | | | | minor fixes. Differential revision: http://reviews.llvm.org/D17218 llvm-svn: 260757
* Class Property: warn for synthesize on a class property.Manman Ren2016-01-291-0/+4
| | | | | | rdar://23891898 llvm-svn: 259226
* Class Property: change PropertyMap to include isClassProperty.Manman Ren2016-01-281-17/+28
| | | | | | | | | | | | | | PropertyMap used to map IdentifierInfo (name of the property) to ObjcPropertyDecl *. Now that a class property can have the same name as an instance property, we change PropertyMap to map a pair <IdentifierInfo *, unsigned> to ObjcPropertyDecl *. Also update a few places from iterating over instance_properties to iterating over all properties. rdar://23891898 llvm-svn: 259119
* Class Property: class property and instance property can have the same name.Manman Ren2016-01-281-17/+26
| | | | | | | | | | | | | | | | | | | 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
* Class Property: create accessors (class methods) for class property.Manman Ren2016-01-271-17/+40
| | | | | | | | | Change a few places where we assume property accessors can only be instance methods. rdar://23891898 llvm-svn: 258980
* Class Property: handle class properties.Manman Ren2016-01-271-2/+2
| | | | | | | | At places where we handle instance properties, if necessary. rdar://23891898 llvm-svn: 258979
* Class Property: parse property attribute (class).Manman Ren2016-01-261-0/+5
| | | | | | | | | This is the third patch in a series of patches to support class properties in addition to instance properties in objective-c. rdar://23891898 llvm-svn: 258834
* Use instance_properties instead of properties. NFC.Manman Ren2016-01-261-8/+8
| | | | | | | | | | | All current properties are instance properties. This is the second patch in a series of patches to support class properties in addition to instance properties in objective-c. rdar://23891898 llvm-svn: 258824
* ObjC properties: consider ownership of properties from protocols when ↵Douglas Gregor2015-12-181-0/+7
| | | | | | | | | | synthesizing. When determining whether ownership was explicitly written for a property when it is being synthesized, also consider that the original property might have come from a protocol. Fixes rdar://problem/23931441. llvm-svn: 255943
* Objective-C properties: merge attributes when redeclaring 'readonly' as ↵Douglas Gregor2015-12-101-89/+158
| | | | | | | | | | | | | | 'readwrite' in an extension. r251874 stopped back-patching the AST when an Objective-C 'readonly' property is redeclared in a class extension as 'readwrite'. However, it did not properly handle merging of Objective-C property attributes (e.g., getter name, ownership, atomicity) to the redeclaration, leading to bad metadata. Merge (and check!) those property attributes so we get the right metadata and reasonable ASTs. Fixes rdar://problem/23823989. llvm-svn: 255309
* Objective-C properties: loosen 'atomic' checking for readonly properties.Douglas Gregor2015-12-091-20/+53
| | | | | | | | | | | | | | | r251874 reworked the way we handle properties declared within Objective-C class extensions, which had the effective of tightening up property checking in a number of places. In this particular class of cases, we end up complaining about "atomic" mismatches between an implicitly-atomic, readonly property and a nonatomic, readwrite property, which doesn't make sense because "atomic" is essentially irrelevant to readonly properties. Therefore, suppress this diagnostic when the readonly property is implicitly atomic. Fixes rdar://problem/23803109. llvm-svn: 255174
* Objective-C properties: fix bogus use of "isa<>" on a QualType.Douglas Gregor2015-12-081-6/+5
| | | | | | | | | The code used "isa" to check the type and then "getAs" to look through sugar; we need to look through the sugar when checking, too, otherwise any kind of sugar (nullability qualifiers in the example; or a typedef) will thwart this semantic check. Fixes rdar://problem/23804250. llvm-svn: 255066
* Fix a comment typo from r251874.Nico Weber2015-12-031-1/+1
| | | | llvm-svn: 254579
* Simplify Sema::ProcessPropertyDecl. NFCDouglas Gregor2015-11-031-21/+6
| | | | | | | | Now that the properties created within Objective-C class extensions go into the extension themselves, we don't need any of the extra complexity here. llvm-svn: 251949
OpenPOWER on IntegriCloud