Commit Graph

19 Commits

Author SHA1 Message Date
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
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
Chandler Carruth 6d28d7f2a3 Rename SourceManager::getInstantiationRange to getExpansionRange.
llvm-svn: 135915
2011-07-25 16:56:02 +00:00
Chris Lattner 0e62c1cc0b remove unneeded llvm:: namespace qualifiers on some core types now that LLVM.h imports
them into the clang namespace.

llvm-svn: 135852
2011-07-23 10:55:15 +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 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
Chandler Carruth e2c09ebcaa Convert terminology in the Lexer from 'instantiate' and variants to
'expand'. Also update the public API it provides to the new term, and
propagate that update to the various clients.

No functionality changed.

llvm-svn: 135138
2011-07-14 08:20:40 +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
Argyrios Kyrtzidis 61c58f7f43 Move SourceManager::isAt[Start/End]OfMacroInstantiation functions to the Lexer, since they depend on it now.
llvm-svn: 134644
2011-07-07 21:54:45 +00:00
John McCall 4db5c3c83a In ARC, reclaim all return values of retainable type, not just those
where we have an immediate need of a retained value.

As an exception, don't do this when the call is made as the immediate
operand of a __bridge retain.  This is more in the way of a workaround
than an actual guarantee, so it's acceptable to be brittle here.

rdar://problem/9504800

llvm-svn: 134605
2011-07-07 06:58:02 +00:00
Argyrios Kyrtzidis 41fb2d95a3 Make the Preprocessor more memory efficient and improve macro instantiation diagnostics.
When a macro instantiation occurs, reserve a SLocEntry chunk with length the
full length of the macro definition source. Set the spelling location of this chunk
to point to the start of the macro definition and any tokens that are lexed directly
from the macro definition will get a location from this chunk with the appropriate offset.

For any tokens that come from argument expansion, '##' paste operator, etc. have their
instantiation location point at the appropriate place in the instantiated macro definition
(the argument identifier and the '##' token respectively).
This improves macro instantiation diagnostics:

Before:

t.c:5:9: error: invalid operands to binary expression ('struct S' and 'int')
int y = M(/);
        ^~~~
t.c:5:11: note: instantiated from:
int y = M(/);
          ^

After:

t.c:5:9: error: invalid operands to binary expression ('struct S' and 'int')
int y = M(/);
        ^~~~
t.c:3:20: note: instantiated from:
\#define M(op) (foo op 3);
                ~~~ ^  ~
t.c:5:11: note: instantiated from:
int y = M(/);
          ^

The memory savings for a candidate boost library that abuses the preprocessor are:

- 32% less SLocEntries (37M -> 25M)
- 30% reduction in PCH file size (900M -> 635M)
- 50% reduction in memory usage for the SLocEntry table (1.6G -> 800M)

llvm-svn: 134587
2011-07-07 03:40:34 +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 e5acb84e63 [arcmt] Merge 'removeEmptyStatements' and 'removeDeallocMethod' passes to cut down on one compilation
pass and increase migration speed.

llvm-svn: 133540
2011-06-21 20:20:42 +00:00
Argyrios Kyrtzidis e5b475c688 [arcmt] Break apart Transforms.cpp.
llvm-svn: 133539
2011-06-21 20:20:39 +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
John McCall d463132f27 Objective-C fast enumeration loop variables are not retained in ARC, but
they should still be officially __strong for the purposes of errors, 
block capture, etc.  Make a new bit on variables, isARCPseudoStrong(),
and set this for 'self' and these enumeration-loop variables.  Change
the code that was looking for the old patterns to look for this bit,
and change IR generation to find this bit and treat the resulting         
variable as __unsafe_unretained for the purposes of init/destroy in
the two places it can come up.

llvm-svn: 133243
2011-06-17 06:42:21 +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