summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaObjC
Commit message (Collapse)AuthorAgeFilesLines
* Add a FIXME and corresponding test coverage for some suspicious behaviorRichard Smith2020-01-101-0/+1
| | | | forming composite ObjC pointer types in comparisons.
* [objc_direct] Tigthen checks for direct methodsPierre Habouzit2019-12-201-0/+53
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Because the name of a direct method must be agreed upon by the caller and the implementation, certain bad practices that one can get away with when using dynamism are fatal with direct methods. To avoid really weird and unscruttable linker error, tighten the front-end error reporting. Rule 1: Direct methods can only have at most one declaration in an @interface container. Any redeclaration is strictly forbidden. Today some amount of redeclaration is tolerated between the main interface and categories for dynamic methods, but we can't have that. Rule 2: Direct method implementations can only be declared in a matching @interface container: when implemented in the primary @implementation then the declaration must be in the primary @interface or an extension, and when implemented in a category, the declaration must be in the @interface for the same category. Also fix another issue with ObjCMethod::getCanonicalDecl(): when an implementation lives in the primary @interface, then its canonical declaration can be in any extension, even when it's not an accessor. Add Sema tests to cover the new errors, and CG tests to beef up testing around function names for categories and extensions. Radar-Id: <rdar://problem/58054563> Differential Revision: https://reviews.llvm.org/D71694
* Set a source location for Objective-C accessor stubsAdrian Prantl2019-12-051-0/+23
| | | | | | | | | | | | 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
* [Sema] Fix a -Wobjc-signed-char-bool false-positiveErik Pilkington2019-11-181-0/+56
| | | | | | | Unsigned bit-field flags can only have boolean values, so handle that case in Expr::isKnownToHaveBooleanValue. rdar://56256999
* Implement __attribute__((objc_direct)), __attribute__((objc_direct_members))Pierre Habouzit2019-11-182-0/+274
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | __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 two typos in one test name, three days before its 10th birthday! (NFC)Adrian Prantl2019-11-081-0/+0
|
* Redeclare Objective-C property accessors inside the ObjCImplDecl in which ↵Adrian Prantl2019-11-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Revert r374202"[ObjC generics] Fix not inheriting type bounds in ↵Hans Wennborg2019-10-221-14/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | categories/extensions." This introduced new errors, see below. Reverting until that can be investigated properly. #import <AVFoundation/AVFoundation.h> void f(int width, int height) { FourCharCode best_fourcc = kCMPixelFormat_422YpCbCr8_yuvs; NSDictionary* videoSettingsDictionary = @{ (id)kCVPixelBufferPixelFormatTypeKey : @(best_fourcc), }; } $ clang++ -c /tmp/a.mm /tmp/a.mm:6:5: error: cannot initialize a parameter of type 'KeyType<NSCopying> _Nonnull const' (aka 'const id') with an rvalue of type 'id' (id)kCVPixelBufferPixelFormatTypeKey : @(best_fourcc), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. > When a category/extension doesn't repeat a type bound, corresponding > type parameter is substituted with `id` when used as a type argument. As > a result, in the added test case it was causing errors like > > > type argument 'T' (aka 'id') does not satisfy the bound ('id<NSCopying>') of type parameter 'T' > > We are already checking that type parameters should be consistent > everywhere (see `checkTypeParamListConsistency`) and update > `ObjCTypeParamDecl` to have correct underlying type. And when we use the > type parameter as a method return type or a method parameter type, it is > substituted to the bounded type. But when we use the type parameter as a > type argument, we check `ObjCTypeParamType` that ignores the updated > underlying type and remains `id`. > > Fix by desugaring `ObjCTypeParamType` to the underlying type, the same > way we are doing with `TypedefType`. > > rdar://problem/54329242 > > Reviewers: erik.pilkington, ahatanak > > Reviewed By: erik.pilkington > > Subscribers: jkorous, dexonsmith, ributzka, cfe-commits > > Differential Revision: https://reviews.llvm.org/D66696
* [ObjC] Diagnose implicit type coercion from ObjC 'Class' to objectJames Y Knight2019-10-171-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | pointer types. For example, in Objective-C mode, the initialization of 'x' in: ``` @implementation MyType + (void)someClassMethod { MyType *x = self; } @end ``` is correctly diagnosed with an incompatible-pointer-types warning, but in Objective-C++ mode, it is not diagnosed at all -- even though incompatible pointer conversions generally become an error in C++. This patch fixes that oversight, allowing implicit conversions involving Class only to/from unqualified-id, and between qualified and unqualified Class, where the protocols are compatible. Note that this does change some behaviors in Objective-C, as well, as shown by the modified tests. Of particular note is that assignment from from 'Class<MyProtocol>' to 'id<MyProtocol>' now warns. (Despite appearances, those are not compatible types. 'Class<MyProtocol>' is not expected to have instance methods defined by 'MyProtocol', while 'id<MyProtocol>' is.) Differential Revision: https://reviews.llvm.org/D67983 llvm-svn: 375125
* [ObjC] Add some additional test cases around pointer conversions.James Y Knight2019-10-173-29/+61
| | | | | | | | | | | | | This is especially important for Objective-C++, which is entirely missing this testing at the moment. This annotates with "FIXME" the cases which I change in the next patch -- I primarily wanted to document the current state of things so that the effect of the code change is made clear. Differential Revision: https://reviews.llvm.org/D67982 llvm-svn: 375124
* [ObjC generics] Fix not inheriting type bounds in categories/extensions.Volodymyr Sapsai2019-10-091-0/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a category/extension doesn't repeat a type bound, corresponding type parameter is substituted with `id` when used as a type argument. As a result, in the added test case it was causing errors like > type argument 'T' (aka 'id') does not satisfy the bound ('id<NSCopying>') of type parameter 'T' We are already checking that type parameters should be consistent everywhere (see `checkTypeParamListConsistency`) and update `ObjCTypeParamDecl` to have correct underlying type. And when we use the type parameter as a method return type or a method parameter type, it is substituted to the bounded type. But when we use the type parameter as a type argument, we check `ObjCTypeParamType` that ignores the updated underlying type and remains `id`. Fix by desugaring `ObjCTypeParamType` to the underlying type, the same way we are doing with `TypedefType`. rdar://problem/54329242 Reviewers: erik.pilkington, ahatanak Reviewed By: erik.pilkington Subscribers: jkorous, dexonsmith, ributzka, cfe-commits Differential Revision: https://reviews.llvm.org/D66696 llvm-svn: 374202
* [Sema] Emit diagnostics for uncorrected delayed typos at the end of TUIlya Biryukov2019-10-091-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Instead of asserting all typos are corrected in the sema destructor. The sema destructor is not run in the common case of running the compiler with the -disable-free cc1 flag (which is the default in the driver). Having this assertion led to crashes in libclang and clangd, which are not reproducible when running the compiler. Asserting at the end of the TU could be an option, but finding all missing typo correction cases is hard and having worse diagnostics instead of a failing assertion is a better trade-off. For more discussion on this, see: https://lists.llvm.org/pipermail/cfe-dev/2019-July/062872.html Reviewers: sammccall, rsmith Reviewed By: rsmith Subscribers: usaxena95, dgoldman, jkorous, vsapsai, rnk, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64799 llvm-svn: 374152
* [Sema] Split of versions of -Wimplicit-{float,int}-conversion for ↵Erik Pilkington2019-09-171-0/+49
| | | | | | | | | | | | | Objective-C BOOL Also, add a diagnostic group, -Wobjc-signed-char-bool, to control all these related diagnostics. rdar://51954400 Differential revision: https://reviews.llvm.org/D67559 llvm-svn: 372183
* [Sema][ObjC] Mark C union fields that have non-trivial ObjC ownershipAkira Hatanaka2019-09-072-1/+26
| | | | | | | | | | | | | | | | | qualifications as unavailable if the union is declared in a system header r365985 stopped marking those fields as unavailable, which caused the union's NonTrivialToPrimitive* bits to be set to true. This patch restores the behavior prior to r365985, except that users can explicitly specify the ownership qualification of the field to instruct the compiler not to mark it as unavailable. rdar://problem/53420753 Differential Revision: https://reviews.llvm.org/D65256 llvm-svn: 371276
* [Sema] Diagnose default-initialization, destruction, and copying ofAkira Hatanaka2019-09-072-5/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | non-trivial C union types This recommits r365985, which was reverted because it broke a few projects using unions containing non-trivial ObjC pointer fields in system headers. We now have a patch to fix the problem (see https://reviews.llvm.org/D65256). Original commit message: This patch diagnoses uses of non-trivial C unions and structs/unions containing non-trivial C unions in the following contexts, which require default-initialization, destruction, or copying of the union objects, instead of disallowing fields of non-trivial types in C unions, which is what we currently do: - function parameters. - function returns. - assignments. - compound literals. - block captures except capturing of `__block` variables by non-escaping blocks. - local and global variable definitions. - lvalue-to-rvalue conversions of volatile types. See the discussion in https://reviews.llvm.org/D62988 for more background. rdar://problem/50679094 Differential Revision: https://reviews.llvm.org/D63753 llvm-svn: 371275
* [ObjC] Fix type checking for qualified id block parameters.Volodymyr Sapsai2019-08-281-0/+11
| | | | | | | | | | | | | | | | | | When checking if block types are compatible, we are checking for compatibility their return types and parameters' types. As these types have different variance, we need to check them in different order. rdar://problem/52788423 Reviewers: erik.pilkington, arphaman Reviewed By: arphaman Subscribers: jkorous, dexonsmith, ributzka, cfe-commits Differential Revision: https://reviews.llvm.org/D66831 llvm-svn: 370130
* [Sema][ObjC] Fix a -Wformat false positive with localizedStringForKeyErik Pilkington2019-08-141-1/+41
| | | | | | | | | | | | Only honour format_arg attributes on -[NSBundle localizedStringForKey] when its argument has a format specifier in it, otherwise its likely to just be a key to fetch localized strings. Fixes rdar://23622446 Differential revision: https://reviews.llvm.org/D27165 llvm-svn: 368878
* Add SVE opaque built-in typesRichard Sandiford2019-08-091-0/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch adds the SVE built-in types defined by the Procedure Call Standard for the Arm Architecture: https://developer.arm.com/docs/100986/0000 It handles the types in all relevant places that deal with built-in types. At the moment, some of these places bail out with an error, including: (1) trying to generate LLVM IR for the types (2) trying to generate debug info for the types (3) trying to mangle the types using the Microsoft C++ ABI (4) trying to @encode the types in Objective C (1) and (2) are fixed by follow-on patches but (unlike this patch) they deal mostly with target-specific LLVM details, so seemed like a logically separate change. There is currently no spec for (3) and (4), so reporting an error seems like the correct behaviour for now. The intention is that the types will become sizeless types: http://lists.llvm.org/pipermail/cfe-dev/2019-June/062523.html The main purpose of the sizeless type extension is to diagnose impossible or dangerous uses of the types, such as any that would require sizeof to have a meaningful defined value. Until then, the patch sets the alignments of the types to the values specified in the link above. It also sets the sizes of the types to zero, which is chosen to be consistently wrong and shouldn't affect correctly-written code (i.e. code that would compile even with the sizeless type extension). The patch adds the common subset of functionality needed to test the sizeless type extension on the one hand and to provide SVE intrinsic functions on the other. After this patch, the two pieces of work are essentially independent. The patch is based on one by Graham Hunter: https://reviews.llvm.org/D59245 Differential Revision: https://reviews.llvm.org/D62960 llvm-svn: 368413
* Revert "[Sema] Diagnose default-initialization, destruction, and copying of"Akira Hatanaka2019-07-262-83/+5
| | | | | | | | | | | | | | | This reverts commit r365985. Prior to r365985, clang used to mark C union fields that have non-trivial ObjC ownership qualifiers as unavailable if the union was declared in a system header. r365985 stopped doing so, which caused the swift compiler to crash when it tried to import a non-trivial union. I have a patch that fixes the crash (https://reviews.llvm.org/D65256), but I'm temporarily reverting the original patch until we can decide on whether it's taking the right approach. llvm-svn: 367076
* [Sema] Diagnose default-initialization, destruction, and copying ofAkira Hatanaka2019-07-132-5/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | non-trivial C union types This patch diagnoses uses of non-trivial C unions and structs/unions containing non-trivial C unions in the following contexts, which require default-initialization, destruction, or copying of the union objects, instead of disallowing fields of non-trivial types in C unions, which is what we currently do: - function parameters. - function returns. - assignments. - compound literals. - block captures except capturing of `__block` variables by non-escaping blocks. - local and global variable definitions. - lvalue-to-rvalue conversions of volatile types. See the discussion in https://reviews.llvm.org/D62988 for more background. rdar://problem/50679094 Differential Revision: https://reviews.llvm.org/D63753 llvm-svn: 365985
* Revert [Sema] Resolve placeholder types before type deduction to silence ↵Reid Kleckner2019-07-081-14/+2
| | | | | | | | | | | | | | | | | | | | | | spurious `-Warc-repeated-use-of-weak` warnings This reverts r365382 (git commit 8b1becf2e31d9170ee356a19c7b6ea991d3a520f) Appears to regress this semi-reduced fragment of valid code from windows SDK headers: #define InterlockedIncrement64 _InterlockedIncrement64 extern "C" __int64 InterlockedIncrement64(__int64 volatile *Addend); #pragma intrinsic(_InterlockedIncrement64) unsigned __int64 InterlockedIncrement(unsigned __int64 volatile *Addend) { return (unsigned __int64)(InterlockedIncrement64)((volatile __int64 *)Addend); } Found on a buildbot here, but no mail was sent due to it already being red: http://lab.llvm.org:8011/builders/sanitizer-windows/builds/48067 llvm-svn: 365393
* [Sema] Resolve placeholder types before type deduction to silenceAkira Hatanaka2019-07-081-2/+14
| | | | | | | | | | | | | | | | | | spurious `-Warc-repeated-use-of-weak` warnings The spurious -Warc-repeated-use-of-weak warnings are issued when an initializer expression uses a weak ObjC pointer. My first attempt to silence the warnings (r350917) caused clang to reject code that is legal in C++17. The patch is based on the feedback I received from Richard when the patch was reverted. http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20190422/268945.html http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20190422/268943.html Differential Revision: https://reviews.llvm.org/D62645 llvm-svn: 365382
* [ObjC] Improve error message for a malformed objc-type-nameErik Pilkington2019-06-261-1/+1
| | | | | | | | | | | | If the type didn't exist, we used to emit a really bad error: t.m:3:12: error: expected ')' -(nullable NoSuchType)foo3; ^ rdar://50925632 llvm-svn: 364489
* Add the `objc_class_stub` attribute.John McCall2019-05-302-0/+37
| | | | | | | | | | | | | | | | | | | | | | | | | Swift requires certain classes to be not just initialized lazily on first use, but actually allocated lazily using information that is only available at runtime. This is incompatible with ObjC class initialization, or at least not efficiently compatible, because there is no meaningful class symbol that can be put in a class-ref variable at load time. This leaves ObjC code unable to access such classes, which is undesirable. objc_class_stub says that class references should be resolved by calling a new ObjC runtime function with a pointer to a new "class stub" structure. Non-ObjC compilers (like Swift) can simply emit this structure when ObjC interop is required for a class that cannot be statically allocated, then apply this attribute to the `@interface` in the generated ObjC header for the class. This attribute can be thought of as a generalization of the existing `objc_runtime_visible` attribute which permits more efficient class resolution as well as supporting the additon of categories to the class. Subclassing these classes from ObjC is currently not allowed. Patch by Slava Pestov! llvm-svn: 362054
* Remove unicode character from testLeonard Chan2019-05-211-1/+2
| | | | llvm-svn: 361302
* [Sema] Fix for build on some iOS programs.Leonard Chan2019-05-201-0/+16
| | | | | | | | Nullability attributes weren't being stripped for AttributedTypes that were wrapped in a MacroQualifiedType. This fix adds a check for this type and a test. llvm-svn: 361205
* Fix for the greendragon bots.Leonard Chan2019-05-081-1/+1
| | | | | | Adds extra checks for ObjC GC and Ownership. llvm-svn: 360225
* Recommit r359859 "[Attribute/Diagnostics] Print macro if definition is an ↵Leonard Chan2019-05-073-3/+9
| | | | | | | | attribute declaration" Updated with fix for read of uninitialized memory. llvm-svn: 360109
* [Sema][ObjC] Disable -Wunused-parameter for ObjC methodsAkira Hatanaka2019-05-032-3/+7
| | | | | | | | | | The warning isn't very useful when the function is an ObjC method. rdar://problem/41561853 Differential Revision: https://reviews.llvm.org/D61147 llvm-svn: 359864
* Revert "[Attribute/Diagnostics] Print macro if definition is an attribute ↵Leonard Chan2019-05-033-9/+3
| | | | | | | | declaration" This reverts commit fc40cbd9d8c63e65eed3590ba925321afe782e1d. llvm-svn: 359859
* [Attribute/Diagnostics] Print macro if definition is an attribute declarationLeonard Chan2019-05-023-3/+9
| | | | | | | | | | | | | If an address_space attribute is defined in a macro, print the macro instead when diagnosing a warning or error for incompatible pointers with different address_spaces. We allow this for all attributes (not just address_space), and for multiple attributes declared in the same macro. Differential Revision: https://reviews.llvm.org/D51329 llvm-svn: 359826
* [Parser] Avoid correcting delayed typos in array subscript multiple times.Volodymyr Sapsai2019-05-011-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | We correct some typos in `ActOnArraySubscriptExpr` and `ActOnOMPArraySectionExpr`, so when their result is `ExprError`, we can end up correcting delayed typos in the same expressions again. In general it is OK but when `NumTypos` is incorrect, we can hit the assertion > Assertion failed: (Entry != DelayedTypos.end() && "Failed to get the state for a TypoExpr!"), function getTypoExprState, file clang/lib/Sema/SemaLookup.cpp, line 5219. Fix by replacing some subscript `ExprResult` with typo-corrected expressions instead of keeping the original expressions. Thus if original expressions contained `TypoExpr`, we'll use corrected expressions instead of trying to correct them again. rdar://problem/47403222 Reviewers: rsmith, erik.pilkington, majnemer Reviewed By: erik.pilkington Subscribers: jkorous, dexonsmith, cfe-commits Differential Revision: https://reviews.llvm.org/D60848 llvm-svn: 359713
* Revert r350917 "[Sema] If CheckPlaceholderExpr rewrites the initializerRichard Smith2019-04-241-14/+2
| | | | | | | | | | | | | | of an auto" This commit changed the initializer expression passed into initialization (stripping off an enclosing pair of parentheses or braces) and subtly changing the meaning of programs, typically by inserting bogus calls to copy constructors. See the added testcase in test/SemaCXX/cxx1y-init-captures.cpp for an example of the breakage. llvm-svn: 359066
* [Sema][ObjC] Don't warn about an implicitly retained self if theAkira Hatanaka2019-04-171-18/+0
| | | | | | | | | | | | | | | | | retaining block and all of the enclosing blocks are non-escaping. If the block implicitly retaining self doesn't escape, there is no risk of creating retain cycles, so clang shouldn't diagnose it and force users to add self-> to silence the diagnostic. Also, fix a bug where clang was failing to diagnose an implicitly retained self inside a c++ lambda nested inside a block. rdar://problem/25059955 Differential Revision: https://reviews.llvm.org/D60736 llvm-svn: 358624
* Support objc_nonlazy_class attribute on Objective-C implementationsErik Pilkington2019-04-111-1/+5
| | | | | | | | Fixes rdar://49523079 Differential revision: https://reviews.llvm.org/D60544 llvm-svn: 358201
* Add support for attributes on @implementations in Objective-CErik Pilkington2019-04-112-4/+5
| | | | | | | | | We want to make objc_nonlazy_class apply to implementations, but ran into this. There doesn't seem to be any reason that this isn't supported. Differential revision: https://reviews.llvm.org/D60542 llvm-svn: 358200
* Fix a test, NFCErik Pilkington2019-04-101-4/+12
| | | | | | | This test was duplicated, and the last declaration had some syntax errors since the invalid attribute caused the @implementation to be skipped by the parser. llvm-svn: 358136
* [Sema] Fix a use-after-deallocate of a ParsedAttrErik Pilkington2019-04-021-0/+4
| | | | | | | | | | | | | | | moveAttrFromListToList only makes sense when moving an attribute to a list with a pool that's either equivalent, or has a shorter lifetime. Therefore, using it to move a ParsedAttr from a declarator to a declaration specifier doesn't make sense, since the declaration specifier's pool outlives the declarator's. The patch adds a new function, ParsedAttributes::takeOneFrom, which transfers the attribute from one pool to another, fixing the use-after-deallocate. rdar://49175426 Differential revision: https://reviews.llvm.org/D60101 llvm-svn: 357516
* [Sema] Fix a use-after-free of a _Nonnull ParsedAttrErik Pilkington2019-03-141-0/+6
| | | | | | | | | | | | | | We were allocating the implicit attribute in the declarator's attribute pool, but putting into the declaration specifier's ParsedAttributesView. If there are multiple declarators, then we'll use the attribute from the declaration specifier after clearing out the declarators attribute pool. Fix this by allocating the attribute in the declaration specifier's pool. rdar://48529718 Differential revision: https://reviews.llvm.org/D59327 llvm-svn: 356187
* Use {{.*}} in test case to match the type of wide string literals.Akira Hatanaka2019-03-081-1/+1
| | | | | | The type of wide string literals varies depending on the target. llvm-svn: 355700
* Fix test case committed in r355662.Akira Hatanaka2019-03-081-1/+1
| | | | | | | Build bots were failing because wide string literals don't have type 'int *' on some targets. llvm-svn: 355664
* [ObjC] Emit a boxed expression as a compile-time constant if theAkira Hatanaka2019-03-083-7/+32
| | | | | | | | | | | | | | | | | | expression inside the parentheses is a valid UTF-8 string literal. Previously clang emitted an expression like @("abc") as a message send to stringWithUTF8String. This commit makes clang emit the boxed expression as a compile-time constant instead. This commit also has the effect of silencing the nullable-to-nonnull conversion warning clang started emitting after r317727, which originally motivated this commit (see https://oleb.net/2018/@keypath). rdar://problem/42684601 Differential Revision: https://reviews.llvm.org/D58729 llvm-svn: 355662
* [Sema][ObjC] Allow silencing -Wobjc-designated-initializers warnings byAkira Hatanaka2019-03-011-0/+13
| | | | | | | | | | | | | 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
* [ObjC generics] Fix applying `__kindof` to the type parameter.Volodymyr Sapsai2019-02-161-0/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes the warning about incompatible pointer types on assigning to a subclass of type argument an expression of type `__kindof TypeParam`. We already have a mechanism in `ASTContext::canAssignObjCInterfaces` that handles `ObjCObjectType` with `__kindof`. But it wasn't triggered because during type substitution `__kindof TypeParam` was represented as `AttributedType` with attribute `ObjCKindOf` and equivalent type `TypeArg`. For assignment type checking we use canonical types so attributed type was desugared and the attribute was ignored. The fix is in checking transformed `AttributedType` and pushing `__kindof` down into `ObjCObjectType` when necessary. rdar://problem/38514910 Reviewers: ahatanak, erik.pilkington, doug.gregor Reviewed By: doug.gregor Subscribers: jkorous, dexonsmith, manmanren, jordan_rose, doug.gregor, cfe-commits Differential Revision: https://reviews.llvm.org/D57076 llvm-svn: 354189
* [ObjC] Fix non-canonical types preventing type arguments substitution.Volodymyr Sapsai2019-02-151-0/+8
| | | | | | | | | | | | | | | | | `QualType::substObjCTypeArgs` doesn't go past non-canonical types and as the result misses some of the substitutions like `ObjCTypeParamType`. Update `SimpleTransformVisitor` to traverse past the type sugar. Reviewers: ahatanak, erik.pilkington Reviewed By: erik.pilkington Subscribers: jkorous, dexonsmith, cfe-commits Differential Revision: https://reviews.llvm.org/D57270 llvm-svn: 354164
* [Sema] Fix-up a -Wfloat-conversion diagnosticErik Pilkington2019-02-141-0/+7
| | | | | | | | | | | | We were warning on valid ObjC property reference exprs, and passing in the wrong arguments to DiagnoseFloatingImpCast (leading to a badly worded diagnostic). rdar://47644670 Differential revision: https://reviews.llvm.org/D58145 llvm-svn: 354074
* [Sema] Delay checking whether objc_designated_initializer is being applied ↵Erik Pilkington2019-02-131-1/+14
| | | | | | | | | | | | | | | | to an init method This fixes a regression that was caused by r335084, which reversed the order that attributes are applied. objc_method_family can change whether a method is an init method, so the order that these attributes are applied matters. The commit fixes this by delaying the init check until after all attributes have been applied. rdar://47829358 Differential revision: https://reviews.llvm.org/D58152 llvm-svn: 353976
* [Sema][ObjC] Disallow non-trivial C struct fields in unions.Akira Hatanaka2019-02-071-1/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch fixes a bug where clang doesn’t reject union fields of non-trivial C struct types. For example: ``` // This struct is non-trivial under ARC. struct S0 { id x; }; union U0 { struct S0 s0; // clang should reject this. struct S0 s1; // clang should reject this. }; void test(union U0 a) { // Previously, both 'a.s0.x' and 'a.s1.x' were released in this // function. } ``` rdar://problem/46677858 Differential Revision: https://reviews.llvm.org/D55659 llvm-svn: 353459
* [OBJC] Add attribute to mark Objective C class as non-lazyJoe Daniels2019-02-041-0/+34
| | | | | | | | | | | | | A non-lazy class will be initialized eagerly when the Objective-C runtime is loaded. This is required for certain system classes which have instances allocated in non-standard ways, such as the classes for blocks and constant strings. Adding this attribute is essentially equivalent to providing a trivial +load method but avoids the (fairly small) load-time overheads associated with defining and calling such a method. Differential Revision: https://reviews.llvm.org/D56555 llvm-svn: 353116
* [SemaObjC] Don't infer the availabilty of +new from -init if the receiver ↵Erik Pilkington2019-02-041-0/+13
| | | | | | | | | | has Class type rdar://47713266 Differential revision: https://reviews.llvm.org/D57712 llvm-svn: 353115
OpenPOWER on IntegriCloud