Commit Graph

71 Commits

Author SHA1 Message Date
Fariborz Jahanian 6bdeb14d5d objc: issue deprecated/unavailable diagnostic when
methods with these attributes are sent to receivers
of 'id' type too. // rdar://10459930

llvm-svn: 145999
2011-12-07 00:30:00 +00:00
Argyrios Kyrtzidis eca1f36a54 [arcmt] Integrate GC __weak into property attributes even when we don't have
the implementation.

llvm-svn: 145224
2011-11-28 02:04:36 +00:00
Argyrios Kyrtzidis 3fc3dcd80f [arcmt] Don't add __weak if there is already a GC __weak and make sure to clear
__weak from a readonly property.

llvm-svn: 145210
2011-11-28 00:23:12 +00:00
Argyrios Kyrtzidis 485eceed38 [arcmt] Take into account that all properties are strong-by-default now and fix the test.
llvm-svn: 144146
2011-11-08 23:09:34 +00:00
Argyrios Kyrtzidis e4a38a73fd [arcmt] Now that readonly properties are strong-by-default, do not add redundant 'strong'.
llvm-svn: 144136
2011-11-08 22:10:58 +00:00
Fariborz Jahanian b1ac0813a6 objc-arc: 'readonly' property of retainable object
type is strong by default too. // rdar://10410903

llvm-svn: 144118
2011-11-08 20:58:53 +00:00
Argyrios Kyrtzidis dbe077a89d [arcmt] Now that properties are strong by default, avoid adding redundant '(strong)'
property attribute.

llvm-svn: 144078
2011-11-08 05:56:11 +00:00
Argyrios Kyrtzidis 2519a0801f [arcmt] When we already removed a __weak, don't try to change it to __unsafe_unretained
later on, or we will end up with a redundant '__unsafe_unretained'.

llvm-svn: 144059
2011-11-08 02:02:38 +00:00
Argyrios Kyrtzidis d569791c44 [arcmt] Fix handling NSMakeCollectable inside an objc method.
llvm-svn: 143980
2011-11-07 18:46:50 +00:00
Argyrios Kyrtzidis 722d21c646 [arcmt] In GC, handle (assign) @properties.
-Move __strong/__weak added to a property type to the property attribute,
e.g.  "@property (assign) __weak Foo *prop;" --> "@property (weak) Foo *prop;"

-Remove (assign) in a property so that it becomes strong-by-default in ARC.

llvm-svn: 143979
2011-11-07 18:46:46 +00:00
Argyrios Kyrtzidis e80d4f228c [arcmt] In GC, change '__weak' -> '__unsafe_unretained' when applied
to objects of classes that don't support ARC weak

llvm-svn: 143976
2011-11-07 18:40:29 +00:00
Argyrios Kyrtzidis f233dac67c [arcmt] In GC, error for __strong/__weak on non-objc pointers.
llvm-svn: 143887
2011-11-06 18:58:23 +00:00
Argyrios Kyrtzidis 0c233fa23e [arcmt] In GC, clear redundant __strong's.
llvm-svn: 143886
2011-11-06 18:58:17 +00:00
Argyrios Kyrtzidis 6b2d47d829 [arcmt] In GC, error out when there is a call that returns a pointer to
GC managed non-objc object memory.

llvm-svn: 143747
2011-11-04 23:43:03 +00:00
Argyrios Kyrtzidis d2b9112354 [arcmt] For GC, cleanup and turn -finalize to -dealloc.
llvm-svn: 143701
2011-11-04 15:58:22 +00:00
Argyrios Kyrtzidis d8cdfbc905 [arcmt] In GC, error for use of CFMakeCollectable because it will leak the
object that it receives in ARC.

llvm-svn: 143700
2011-11-04 15:58:17 +00:00
Argyrios Kyrtzidis 3eaa22af57 In C++ keep unavailable function calls in the AST, like in C/ObjC.
This allows the migrator to visit and fix them.

llvm-svn: 143699
2011-11-04 15:58:13 +00:00
Argyrios Kyrtzidis d208ef95aa [arcmt] In GC, transform NSMakeCollectable to CFBridgingRelease.
llvm-svn: 143698
2011-11-04 15:58:08 +00:00
Ted Kremenek 337c5b880c Further refine the diagnostic categories for ARC diagnostics. Addresses <rdar://problem/10245086>.
llvm-svn: 142571
2011-10-20 05:07:47 +00:00
Argyrios Kyrtzidis 05c65fbdb6 [arcmt] Rewrite attributes in extensions as well. rdar://9992142
llvm-svn: 142407
2011-10-18 19:49:19 +00:00
Argyrios Kyrtzidis ffe8b1c7be [arcmt] In ARC default for properties is 'strong' so just remove a 'retain' if possible,
instead of changing it to 'strong'. rdar://9984862.

llvm-svn: 142304
2011-10-17 23:14:16 +00:00
John McCall 4124c4924d Teach the ARC compiler to not require __bridge casts when
passing/receiving CF objects at +0 to/from Objective-C methods
or audited C functions.

llvm-svn: 142219
2011-10-17 18:40:02 +00:00
Argyrios Kyrtzidis f8585fbe57 Try fixing windows bots.
llvm-svn: 141462
2011-10-08 00:54:49 +00:00
Argyrios Kyrtzidis 741fab1358 [arcmt] Ignore linking errors when doing ARC migration, rdar://10247606
llvm-svn: 141434
2011-10-07 22:58:08 +00:00
John McCall 9b0a7cea0f Make -fobjc-nonfragile-abi the -cc1 default, since it's the
increasingly prevailing case to the point that new features
like ARC don't even support the fragile ABI anymore.

This required a little bit of reshuffling with exceptions
because a check was assuming that ObjCNonFragileABI was
only being set in ObjC mode, and that's actually a bit
obnoxious to do.

Most, though, it involved a perl script to translate a ton
of test cases.

Mostly no functionality change for driver users, although
there are corner cases with disabling language-specific
exceptions that we should handle more correctly now.

llvm-svn: 140957
2011-10-02 01:16:38 +00:00
Argyrios Kyrtzidis 41899f3bac [arcmt] Use __bridge_retained when passing an objc object to a CF parameter
annotated with cf_consumed attribute.

llvm-svn: 139709
2011-09-14 18:17:09 +00:00
Argyrios Kyrtzidis 37ad0091c3 [arcmt] Try fixing the windows buildbot.
llvm-svn: 139262
2011-09-07 21:50:18 +00:00
Argyrios Kyrtzidis 9d4fac0f9f [arcmt] Remove xfail on test for windows, Takumi reported that it passes mingw and msvc.
llvm-svn: 139223
2011-09-07 03:43:41 +00:00
Argyrios Kyrtzidis 48d7798de1 [arcmt] Clear out temporary dirs in the tests or we may get failures because of leftovers.
llvm-svn: 138971
2011-09-01 21:53:39 +00:00
Argyrios Kyrtzidis cbbc0141f6 [arcmt] Fix test/ARCMT/remove-statements.m regression due to
Objective-C method buffering(rdar://10056942)

Turned out the same issue existed for C++ inline methods.

llvm-svn: 138960
2011-09-01 20:53:18 +00:00
Fariborz Jahanian bd0642fede objective-c - This patch buffers method implementations
and does the Sema on their body after the entire 
class/category @implementation is seen. This change allows messaging 
of forward private methods, as well as, access to 
synthesized ivars of properties with foward synthesize
declarations; among others. In effect, this patch removes
several restrictions placed on objective-c due to in-place
semantics processing of methods.
This is part of // rdar://8843851.

llvm-svn: 138865
2011-08-31 17:37:55 +00:00
Argyrios Kyrtzidis bd0a6019a2 [arcmt] Xfail the test for windows.
llvm-svn: 138696
2011-08-27 03:38:05 +00:00
Argyrios Kyrtzidis 1045430525 [arcmt] Add a test case for r138671 and improve the loop.
llvm-svn: 138674
2011-08-26 23:20:23 +00:00
Argyrios Kyrtzidis 93db2277e6 [arcmt] When checking whether properties needs to be strong or not, take into account
that assigning result of -retain means it should be strong. rdar://9931757.

llvm-svn: 137252
2011-08-10 21:46:48 +00:00
Fariborz Jahanian e1506cbfda objective-c: reverse patch for // rdar://9818354
llvm-svn: 136658
2011-08-01 22:39:49 +00:00
Argyrios Kyrtzidis fdafb7f7e6 [arcmt] Revert r135382, there's a different approach in r135764. rdar://9821111.
llvm-svn: 136209
2011-07-27 05:28:22 +00:00
Argyrios Kyrtzidis 9390747349 [arcmt] More automatic transformations and safety improvements; rdar://9615812 :
- Replace calling -zone with 'nil'. -zone is obsolete in ARC.
- Allow removing retain/release on a static global var.
- Fix assertion hit when scanning for name references outside a NSAutoreleasePool scope.
- Automatically add bridged casts for results of objc method calls and when calling CFRetain, for example:

NSString *s;
CFStringRef ref = [s string];   -> CFStringRef ref = (__bridge CFStringRef)([s string]);
ref = s.string;                 -> ref = (__bridge CFStringRef)(s.string);
ref = [NSString new];           -> ref = (__bridge_retained CFStringRef)([NSString new]);
ref = [s newString];            -> ref = (__bridge_retained CFStringRef)([s newString]);
ref = [[NSString alloc] init];  -> ref = (__bridge_retained CFStringRef)([[NSString alloc] init]);
ref = [[s string] retain];      -> ref = (__bridge_retained CFStringRef)([s string]);
ref = CFRetain(s);              -> ref = (__bridge_retained CFTypeRef)(s);
ref = [s retain];               -> ref = (__bridge_retained CFStringRef)(s);

- Emit migrator error when trying to cast to CF type the result of autorelease/release:
  for

CFStringRef f3() {
  return (CFStringRef)[[[NSString alloc] init] autorelease];
}

emits:

t.m:12:10: error: [rewriter] it is not safe to cast to 'CFStringRef' the result of 'autorelease' message; a __bridge cast may result in a pointer to a destroyed object and a __bridge_retained may leak the object
  return (CFStringRef)[[[NSString alloc] init] autorelease];
         ^            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
t.m:12:3: note: [rewriter] remove the cast and change return type of function to 'NSString *' to have the object automatically autoreleased
  return (CFStringRef)[[[NSString alloc] init] autorelease];
  ^

- Before changing attributes to weak/unsafe_unretained, check if the backing ivar
  is set to a +1 object, in which case use 'strong' instead.

llvm-svn: 136208
2011-07-27 05:28:18 +00:00
Fariborz Jahanian dff8de77a6 objective-c: Any use of @synthesize or @dynamic lexically after a method (or C function) implementation
will be rejected with a compilation error in ARC mode, and a compiler warning otherwise.
This may cause breakage in non-arc (and arc) tests which don't expect warning/error. Feel free
to fix the tests, or reverse the patch, if I am unavailable. // rdar://9818354 - WIP

llvm-svn: 135740
2011-07-22 01:06:53 +00:00
Argyrios Kyrtzidis d571363e45 [arcmt] Add some additional driver flags to optionally emit or save the pre-migration ARC errors.
-arcmt-migrate-emit-errors : Emits the pre-migration ARC errors but it doesn't affect anything else
-arcmt-migrate-report-output : Writes out the pre-migration ARC errors to the provided plist file

rdar://9791454

llvm-svn: 135491
2011-07-19 17:20:03 +00:00
Argyrios Kyrtzidis 91c62bfc03 [arcmt] When a NSData's 'bytes' family of methods are used on a local var,
add __attribute__((objc_precise_lifetime)) to make sure that the object
(and its data) will not get released before the var goes out-of-scope.

rdar://9206226

llvm-svn: 135382
2011-07-18 07:44:50 +00:00
Argyrios Kyrtzidis 73a0d32df5 [arcmt] NSInvocation's [get/set]ReturnValue and [get/set]Argument are only safe
with __unsafe_unretained parameters. Emit error for strong/weak ones. rdar://9206226

llvm-svn: 135381
2011-07-18 07:44:45 +00:00
Argyrios Kyrtzidis a6fe4bfdf5 [arcmt] It's not safe to remove the -release on "[[someivar delegate] release];" since it's very likely
that, after migration, the object that was passed to 'setDelegate:' will not be properly retained, e.g:

-whatever {
  id x = [[MyDoHicky alloc] init];
  [someivar setDelegate: x]; // x won't get retained in ARC.
}
-dealloc {
  [[someivar delegate] release]; // give migration error here.
}

rdar://8858009

llvm-svn: 135327
2011-07-15 23:48:56 +00:00
Argyrios Kyrtzidis f59daff52e [arcmt] Rewrite to "foo = nil;" not "foo = 0;", as suggested by Jordy.
llvm-svn: 135309
2011-07-15 22:04:00 +00:00
Argyrios Kyrtzidis 6a8a14d217 [arcmt] For:
id x = ...
@try {
 ...
} @finally {
 [x release];
}

Migrator will drop the release. It's better to change it to "x = 0" in a @finally to avoid leak when exception is thrown.

rdar://9398256

llvm-svn: 135301
2011-07-15 21:11:23 +00:00
Argyrios Kyrtzidis f2a27f40d6 [arcmt] Don't remove retains/releases on a global variable, flag them with errors. rdar://9402555.
llvm-svn: 135213
2011-07-14 23:32:04 +00:00
Argyrios Kyrtzidis 08903e4c16 [arcmt] Allow -retain of an __unsafe_unretained receiver if the result gets used.
Keep the error if the result is unused. rdar://9552694.

llvm-svn: 135209
2011-07-14 22:46:12 +00:00
Argyrios Kyrtzidis 84b528f3b1 [arcmt] Emit an error for unused -autorelease messages.
An unused autorelease is badness. If we remove it the receiver
will likely die immediately while previously it was kept alive
by the autorelease pool. This is bad practice in general, so leave it
and emit an error to force the user to restructure his code.

rdar://9599884

llvm-svn: 135193
2011-07-14 21:26:49 +00:00
Argyrios Kyrtzidis e2e40b4dc7 [arcmt] Make sure migrating to ARC works even if '-fobjc-arc' is included in command-line flags. rdar://9567824
llvm-svn: 135115
2011-07-14 00:17:54 +00:00
Argyrios Kyrtzidis de223c3a7b [arcmt] Add weak/unsafe_unretained for "@property (readonly)" when we are @synthesizing it.
llvm-svn: 135067
2011-07-13 19:47:57 +00:00
Argyrios Kyrtzidis c8b3619773 [arcmt] For properties rewrite 'assign' -> 'weak or unsafe_unretained', 'retain' -> 'strong', and add
'weak or unsafe_unretained' when 'assign' is missing. rdar://9496219&9602589.

llvm-svn: 135065
2011-07-13 19:22:00 +00:00