Commit Graph

298 Commits

Author SHA1 Message Date
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
Argyrios Kyrtzidis a200973ead [arcmt] Also avoid 'weak' for forward references to objc classes.
llvm-svn: 135003
2011-07-12 22:16:25 +00:00
Argyrios Kyrtzidis ce9b739999 [arcmt] Before applying '__weak' check whether the objc class is annotated with objc_arc_weak_reference_unavailable
or is in a list of classes not supporting 'weak'.

rdar://9489367.

llvm-svn: 135002
2011-07-12 22:05:17 +00:00
Douglas Gregor 7e6bfb4a0d In ARC mode, consider Objective-C lifetime types (object pointers and
block pointers) that don't have any qualification to be POD types. We
were previously considering them to be non-POD types, because this was
convenient in C++ for is_pod-like traits. However, we now end up
inferring lifetime in such cases (template arguments infer __strong),
so it is not necessary.

Moreover, we want rvalues of object type (which have their lifetime
stripped) to be PODs to allow, e.g., va_arg(arglist, id) to function
properly. Fixes <rdar://problem/9758798>.

llvm-svn: 134993
2011-07-12 17:28:52 +00:00
NAKAMURA Takumi c7ec4539ed Tweak two tests with MSYS-bash tolerant.
llvm-svn: 134899
2011-07-11 16:21:34 +00:00
Argyrios Kyrtzidis d8d3c1b8f3 [arcmt] Remove test/ARCMT/with-working-dir.m which fails at windows hosts and is not that useful
in the first place. http://llvm.org/PR10312.

llvm-svn: 134845
2011-07-09 20:01:02 +00:00
Argyrios Kyrtzidis 7fbd97f641 [arcmt] Introduce new '-ccc-arcmt-migrate <path>' ARC migration driver option.
This is a new mode of migration, where we avoid modifying the original files but
we emit temporary files instead.

<path> will be used to keep migration process metadata. Currently the temporary files
that are produced are put in the system's temp directory but we can put them
in the <path> if is necessary.

Also introduce new ARC migration functions in libclang whose only purpose,
currently, is to accept <path> and provide pairs of original file/transformed file
to map from the originals to the files after transformations are applied.

Finally introduce the c-arcmt-test utility that exercises the new libclang functions,
update arcmt-test, and add tests for the whole process.

rdar://9735086.

llvm-svn: 134844
2011-07-09 20:00:58 +00:00
John McCall 24fc0decfe Change the driver's logic about Objective-C runtimes: abstract out a
structure to hold inferred information, then propagate each invididual
bit down to -cc1.  Separate the bits of "supports weak" and "has a native
ARC runtime";  make the latter a CodeGenOption.

The tool chain is still driving this decision, because it's the place that
has the required deployment target information on Darwin, but at least it's
better-factored now.

llvm-svn: 134453
2011-07-06 00:26:06 +00:00
Argyrios Kyrtzidis 7192a3b841 [ARC] When casting from a pointer to an objective-c object with known ownership, if the
cast type has no ownership specified, implicitly "transfer" the ownership of the cast'ed type
to the cast type:

id x;
(NSString**)&x; // Casting as (__strong NSString**).

llvm-svn: 134275
2011-07-01 22:22:59 +00:00
Argyrios Kyrtzidis 5a9e5c4df6 [arcmt] Add test for rdar://9601437.
llvm-svn: 133807
2011-06-24 18:41:23 +00:00
Argyrios Kyrtzidis cff00d9c12 Rename objc_lifetime -> objc_ownership, and modify diagnostics to talk about 'ownership', not 'lifetime'.
rdar://9477613.

llvm-svn: 133779
2011-06-24 00:08:59 +00:00
Argyrios Kyrtzidis 0b2bd862ff [arcmt] Fully migrate ObjC++ classes, rdar://9660007.
llvm-svn: 133763
2011-06-23 21:21:33 +00:00
Argyrios Kyrtzidis 795550691e [arcmt] Remove rewriteAllocCopyWithZone transformation; not needed anymore.
llvm-svn: 133762
2011-06-23 21:21:28 +00:00
Argyrios Kyrtzidis 59b5f356ad [arcmt] Make -Warc-unsafe-retained-assign an error when migrating. rdar://8939557
llvm-svn: 133627
2011-06-22 18:03:59 +00:00
Argyrios Kyrtzidis 0a9d652331 [arcmt] Always add '__bridge' cast when 'self' is cast to a C pointer. rdar://9644061
llvm-svn: 133480
2011-06-20 23:39:20 +00:00
Argyrios Kyrtzidis 90b6a2a6a7 [arcmt] Fix the ARC migrator. -arcmt-modify requires running before the initialization of SourceManager
because it is going to modify the input file.

llvm-svn: 133323
2011-06-18 00:53:41 +00:00
Argyrios Kyrtzidis ec7c965c2e [arcmt] Fix test for MSVC build.
llvm-svn: 133183
2011-06-16 20:19:55 +00:00
Argyrios Kyrtzidis 2798ded9de [arcmt] Fix the test when running in Lion.
llvm-svn: 133167
2011-06-16 17:28:31 +00:00
John McCall b29f52727c Give arcmt-test an explicit triple for this test.
llvm-svn: 133165
2011-06-16 17:13:30 +00:00
Argyrios Kyrtzidis bdf3ca9186 [arcmt] Fix tests in non-darwin.
llvm-svn: 133140
2011-06-16 02:41:46 +00:00
Argyrios Kyrtzidis 6e4ef20baf [arcmt] Make arcmt-test accept cc1 options to make it more portable and hopefully fix MSVC failures.
llvm-svn: 133119
2011-06-16 00:53:46 +00:00
John McCall d70fb9812a The ARC Migration Tool. All the credit goes to Argyrios and Fariborz
for this.

llvm-svn: 133104
2011-06-15 23:25:17 +00:00