Commit Graph

135 Commits

Author SHA1 Message Date
Argyrios Kyrtzidis 501d90bf9f [objcmt] Fix a mishandled conversion to objc directory literal.
rdar://13181413

llvm-svn: 178942
2013-04-06 01:13:17 +00:00
Argyrios Kyrtzidis d07fabf034 [arcmt] Make sure the function has an associated parameter for the argument
before checking for its attributes.

rdar://13192395

llvm-svn: 175184
2013-02-14 17:29:16 +00:00
Argyrios Kyrtzidis 88c0d3b1ae [arcmt] Make sure the objc migrators work fine when used with a PCH.
rdar://13140508

llvm-svn: 174386
2013-02-05 16:37:00 +00:00
Douglas Gregor 0ad84b46e3 Undo my re-wording of the "ARC forbids Objective-C objects in ..."
error. Jordan is right.

llvm-svn: 173713
2013-01-28 20:13:44 +00:00
Douglas Gregor e6c3fa0b27 Forbid the use of objects in unions in Objective-C++ ARC. Fixes
<rdar://problem/13098104>.

llvm-svn: 173708
2013-01-28 19:08:09 +00:00
Argyrios Kyrtzidis 6b4f341ecd [objcmt] Rewrite a NSDictionary dictionaryWithObjects:forKeys: to a dictionary literal
if we can see the elements of the arrays.

for example:

 NSDictionary *dict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"1", @"2", nil] forKeys:[NSArray arrayWithObjects:@"A", @"B", nil]];

-->

 NSDictionary *dict = @{ @"A" : @"1", @"B" : @"2" };

rdar://12428166

llvm-svn: 172679
2013-01-16 23:54:48 +00:00
Argyrios Kyrtzidis 08281fa337 [arcmt] Follow-up for r171484; make sure when adding brackets enclosing case statements,
that the case does not "contain" a declaration that is referenced "outside" of it,
otherwise we will emit un-compilable code.

llvm-svn: 171828
2013-01-08 00:58:25 +00:00
Argyrios Kyrtzidis d12c332905 [arcmt] Allow removing an -autorelease of a variable initialized in the previous statement.
rdar://11074996

llvm-svn: 171485
2013-01-04 18:30:11 +00:00
Argyrios Kyrtzidis 03fbe3ef81 [arcmt] Adds brackets in case statements that "contain" initialization of retaining
variable, thus emitting the "switch case is in protected scope" error.

rdar://12952016

llvm-svn: 171484
2013-01-04 18:30:08 +00:00
Argyrios Kyrtzidis b7b89b5ebc [arcmt] Don't error if an autoreleased variable is returned after the -autorelease.
rdar://12952025

llvm-svn: 171482
2013-01-04 18:29:59 +00:00
Argyrios Kyrtzidis 6ba7afb8e1 [arcmt] Rewrite uses of Block_copy/Block_release macros.
c = Block_copy(b);
  Block_release(c);
 ---->
  c = [b copy];
  <removed>

rdar://9408211

llvm-svn: 171454
2013-01-03 03:17:17 +00:00
Andy Gibbs 0fea04509a Change VerifyDiagnosticConsumer so that it *must* contain at least one "expected-*" directive. As a result, for test-cases that are not expected to generate any diagnostics, an additional directive "expected-no-diagnostics" has been implemented which can then be included in such test-cases. This new directive may not be used in conjunction with any other "expected-*" directive.
This change was initially proposed as a solution to the problem highlighted by check-in r164677, i.e. that -verify will not cause a test-case failure where the compile command does not actually reference the file.

Patch reviewed by David Blaikie.

llvm-svn: 166281
2012-10-19 12:49:32 +00:00
Fariborz Jahanian 35227ea365 objective-C arc: remove -Warc-abi in its entirety.
// rdar://10554025

llvm-svn: 163917
2012-09-14 17:48:35 +00:00
Jordan Rose b00073db80 Update VerifyDiagnosticConsumer to only get directives during parsing.
The old behavior was to re-scan any files (like modules) where we may have
directives but won't actually be parsing during the -verify invocation.
Now, we keep the old behavior in Debug builds as a sanity check (though
modules are a known entity), and expect all legitimate directives to come
from comments seen by the preprocessor.

This also affects the ARC migration tool, which captures diagnostics in
order to filter some out. This change adds an explicit cleanup to
CaptureDiagnosticsConsumer in order to let its sub-consumer handle the
real end of diagnostics.

This was originally split into four patches, but the tests do not run
cleanly without all four, so I've combined them into one commit.

Patches by Andy Gibbs, with slight modifications from me.

llvm-svn: 161650
2012-08-10 01:06:16 +00:00
Fariborz Jahanian b7f03c191c objective-c arc: ARC IRGen correctly assumes result
type of generated call to super dealloc is 'void'
and asserts if user's dealloc is not of 'void type.
This rule must be enforced in clang front-end (with a 
fixit) if this is not the case, instead of asserting in CodeGen.
// rdar://11987838

llvm-svn: 160993
2012-07-30 20:52:48 +00:00
Fariborz Jahanian 84c97cafd0 revert r160839 for now.
llvm-svn: 160895
2012-07-27 21:34:23 +00:00
Fariborz Jahanian 226459efff objc-arc: When objects with known CF semantics are assigned to
retainable types in arc, only suggest CFBridgingRelease/
CFBridgingRetain and not the confusing __bridge casts.
// rdar://11923822

llvm-svn: 160839
2012-07-26 23:17:04 +00:00
Nico Weber 9035951409 Let Expr::HasSideEffects() return false for NULL, bool literals, this, and nullptr.
Fixes PR13413, -Wunused-private-field now warns on unused fields initialized to NULL.

llvm-svn: 160541
2012-07-20 03:39:05 +00:00
Argyrios Kyrtzidis 89b928eb6a [objcmt] Check for classes that accept 'objectForKey:' (or the other selectors
that the migrator handles) but return their instances as 'id', resulting
in the compiler resolving 'objectForKey:' as the method from NSDictionary.

When checking if we can convert to subscripting syntax, check whether
the receiver is a result of a class method from a hardcoded list of
such classes. In such a case return the specific class as the interface
of the receiver.

llvm-svn: 159788
2012-07-06 00:07:09 +00:00
Argyrios Kyrtzidis 13b92929dc [objcmt] Allow migrating to subscripting syntax for other classes
(apart from NSDictionary/NSArray) that implement objectForKey:/objectAtIndex/etc.
and the subscripting methods as well.

Part of rdar://11734969

llvm-svn: 159783
2012-07-05 21:49:51 +00:00
Fariborz Jahanian 450bb6e8ff objective-c: Refactor parse/sema portion of
objective-c's fast enumeration statement,
for more work to come.

llvm-svn: 159689
2012-07-03 22:00:52 +00:00
Argyrios Kyrtzidis 927a437ac7 [objcmt] Have the modern objc migration warning change from:
[NSNumber numberWithDouble:cppb];
warning: converting to boxing syntax requires a cast

to something like:

[NSNumber numberWithDouble:cppb];
warning: converting to boxing syntax requires casting 'bool' to 'double'

This is way better to fully understand the warning.
rdar://11705106

llvm-svn: 158783
2012-06-20 01:28:32 +00:00
Argyrios Kyrtzidis 692bf8cb64 [arcmt] When migrating to ARC disable -Werror so as to only block migration
for "hard" ARC errors, not warnings.

rdar://11691437

llvm-svn: 158781
2012-06-20 01:10:40 +00:00
Argyrios Kyrtzidis a3fcbeb908 [objcmt] When checking whether the subscripting methods are declared use
ObjCInterfaceDec::lookupInstanceMethod to make sure we check categories as well
and update related tests.

rdar://11695288

llvm-svn: 158697
2012-06-19 02:22:02 +00:00
Argyrios Kyrtzidis b03cc793a9 [arcmt] At an unbridged cast error, if we're returning a load-of-ivar from a +0 method,
automatically insert a __bridge cast.

radar://11560638

llvm-svn: 158127
2012-06-07 00:44:06 +00:00
Argyrios Kyrtzidis 63aebfb4ae [objcmt] When in ARC mode, also convert "[[.. alloc] init]" messages to literals,
since the change from +1 to +0 will be handled fine by ARC.

rdar://11606358

llvm-svn: 158114
2012-06-06 22:23:12 +00:00
Fariborz Jahanian 3da28f80e3 objective-c: merge deprecated/unavailable attributes to
the overriding deprecated/unavailable method.
// rdar://11475360

llvm-svn: 158022
2012-06-05 21:14:46 +00:00
Argyrios Kyrtzidis 6310fdd982 [objcmt] Don't migrate to subscripting syntax if the required methods have not
been declared on NSArray/NSDictionary.

rdar://11581975

llvm-svn: 157951
2012-06-04 21:23:26 +00:00
Argyrios Kyrtzidis 273c7c40b2 [arcmt] Use CFBridgingRetain/CFBridgingRelease instead of __bridge_retained/__bridge_transfer
when migrating.

rdar://11569198

llvm-svn: 157785
2012-06-01 00:10:47 +00:00
Argyrios Kyrtzidis bb2be0dca3 [objcmt] Add test case for r157395.
llvm-svn: 157404
2012-05-24 17:49:22 +00:00
Argyrios Kyrtzidis 0b21d82437 [arcmt] Remove an unused -autorelease, without failing with error, for this
idiom that is used commonly in setters:

   [backingValue autorelease];
   backingValue = [newValue retain]; // in general a +1 assign

rdar://9914061

llvm-svn: 157347
2012-05-23 21:50:04 +00:00
Argyrios Kyrtzidis 94442980c0 [objcmt] Don't add redundant parentheses when migrating subscripting of an ivar.
rdar://11501256

llvm-svn: 157227
2012-05-22 00:47:53 +00:00
Argyrios Kyrtzidis 937bcb2de6 [arcmt] Revert r156999 "Remove the "it is not safe to remove an unused 'autorelease' message" ARC
migration error".

Per feedback from John this is useful to have in general.

llvm-svn: 157198
2012-05-21 17:48:31 +00:00
Argyrios Kyrtzidis 3d6439517c [arcmt] Remove the "it is not safe to remove an unused 'autorelease' message" ARC
migration error.

This is more trouble that it is worth; autoreleasing a value without holding on it
is a valid use-case, we should not "punish" correct code for the minority of
broken/fragile programs that depend on the behavior of  -autorelease.

rdar://9914061

llvm-svn: 156999
2012-05-17 18:16:05 +00:00
Argyrios Kyrtzidis 8154147942 [objcmt] Accept char arrays for rewriting to @() syntax.
Part of rdar://11438360

llvm-svn: 156880
2012-05-16 00:21:21 +00:00
Argyrios Kyrtzidis 7bd957c12a [objcmt] Rewrite messages to NSString's stringWithUTF8String:/stringWithCString:
to use the @() boxing syntax.

It will also rewrite uses of stringWithCString:encoding: where the encoding that is
used is NSASCIIStringEncoding or NSUTF8StringEncoding.

rdar://11438360

llvm-svn: 156868
2012-05-15 22:22:10 +00:00
Argyrios Kyrtzidis 491e4aed31 [objcmt] Rewrite [NSNumber numberWith*] messages to the new @() boxing syntax.
There are some caveats:
-If an implicit cast (e.g. int -> float for numberWithFloat:) was required, the message
 will not get rewritten
-If the message was with numberWithInteger:/numberWithUnsignedInteger:, which are very
 commonly used, be more liberal and allow the boxing syntax if the underlying type has
 same signedness and will not lose precision.

Part of rdar://11438360

llvm-svn: 156844
2012-05-15 19:17:49 +00:00
Argyrios Kyrtzidis 0bbe94f737 [objcmt] When rewriting to subscripting syntax, make sure we put
the receiver in parentheses when necessary.

Part of rdar://11438360

llvm-svn: 156789
2012-05-14 23:33:49 +00:00
Argyrios Kyrtzidis c1dfed6572 [objcmt] When rewriting to array/dictionary literals, add an explicit
cast to 'id' for any argument that requires it.

Part of rdar://11438360.

llvm-svn: 156782
2012-05-14 22:01:53 +00:00
Argyrios Kyrtzidis a9151a5170 [arcmt] When fixing the "unassigned init call" ARC error, make sure
to do a nil check for the result of the call.

rdar://10950973

llvm-svn: 153793
2012-03-31 01:34:06 +00:00
Argyrios Kyrtzidis 28e0a7f6c1 [arcmt] Fix a bug where a property in a class extension, that did not exist
in the interface, got its attribute rewritten twice, resulting in
'weakweak' or 'strongstrong'.

rdar://11047179

llvm-svn: 153621
2012-03-29 01:10:31 +00:00
Ted Kremenek 4a64230ee7 Don't include FixIts with a null replacement range. Fixes <rdar://problem/11040133>.
llvm-svn: 153122
2012-03-20 20:49:45 +00:00
Argyrios Kyrtzidis 5652716a7a [objcmt] Add a triple to test/ARCMT/objcmt-subscripting-literals.m
llvm-svn: 152151
2012-03-06 22:03:39 +00:00
Ted Kremenek f7639e1b4a Add new code migrator support for migrating existing Objective-C code to use
the new Objective-C NSArray/NSDictionary/NSNumber literal syntax.

This introduces a new library, libEdit, which provides a new way to support
migration of code that improves on the original ARC migrator.  We now believe
that most of its functionality can be refactored into the existing libraries,
and thus this new library may shortly disappear.

llvm-svn: 152141
2012-03-06 20:06:33 +00:00
Argyrios Kyrtzidis afdc66f4fa [arcmt]
-Make sure we don't change to '__weak' a __block variable used as output.
-Make sure we don't apply __weak twice.

Fixes rdar://10520757&10521362

llvm-svn: 152020
2012-03-05 08:46:24 +00:00
Argyrios Kyrtzidis 01c047e003 [arcmt] GC migrator: don't try to remove redundant __strong, it does
more harm than good.

Fixes rdar://10522805&10521433

llvm-svn: 151424
2012-02-25 01:57:42 +00:00
Ted Kremenek 6eb25628c5 Revert r145999. This turned out to be a bad idea. Unfortunately, 'id' is used so profusely
in many APIs and large codebases that this made the deprecated warning trigger happy to
the point of not being useful.

llvm-svn: 150223
2012-02-10 02:45:47 +00:00
Fariborz Jahanian 30febeb224 Look for declaration of CFBridgingRetain/CFBridgingRetain before
changing the diagnostic. Also use correct spelling for both.

llvm-svn: 149554
2012-02-01 22:56:20 +00:00
Fariborz Jahanian bcdc282d85 objc-arc: In various diagnostics mention
CFBridgingRetain/CFBridgingRelease calls instead
of __bridge_retained/__bridge_transfer casts as preferred
way of moving cf objects to arc land. // rdar://10207950

llvm-svn: 149449
2012-01-31 23:42:37 +00:00
Fariborz Jahanian a1c1b152f0 arc migrator: twik previous patch to exclude user provided
explicit type cast. // rdar://10521744

llvm-svn: 149437
2012-01-31 22:09:44 +00:00