summaryrefslogtreecommitdiffstats
path: root/clang/lib/ARCMigrate
Commit message (Collapse)AuthorAgeFilesLines
...
* [arcmt] More automatic transformations and safety improvements; rdar://9615812 :Argyrios Kyrtzidis2011-07-277-23/+201
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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
* Rename getInstantiationLineNumber to getExpansionLineNumber in bothChandler Carruth2011-07-251-1/+1
| | | | | | SourceManager and FullSourceLoc. llvm-svn: 135969
* Rename getInstantiationColumnNumber to getExpansionColumnNumber in bothChandler Carruth2011-07-251-1/+1
| | | | | | SourceManager and FullSourceLoc. llvm-svn: 135965
* Rename SourceManager::getInstantiationRange to getExpansionRange.Chandler Carruth2011-07-252-2/+2
| | | | llvm-svn: 135915
* Mechanically rename SourceManager::getInstantiationLoc andChandler Carruth2011-07-253-13/+13
| | | | | | | | FullSourceLoc::getInstantiationLoc to ...::getExpansionLoc. This is part of the API and documentation update from 'instantiation' as the term for macros to 'expansion'. llvm-svn: 135914
* Move ArrayRef to LLVM.h and eliminate now-redundant qualifiers, patch by Jon ↵Chris Lattner2011-07-234-15/+15
| | | | | | Mulder! llvm-svn: 135855
* remove unneeded llvm:: namespace qualifiers on some core types now that ↵Chris Lattner2011-07-2316-96/+79
| | | | | | | | LLVM.h imports them into the clang namespace. llvm-svn: 135852
* now that we have a centralized place to do so, add some using declarations forChris Lattner2011-07-201-10/+10
| | | | | | | some common llvm types: stringref and smallvector. This cleans up the codebase quite a bit. llvm-svn: 135576
* Update CMake build.Benjamin Kramer2011-07-191-0/+1
| | | | llvm-svn: 135492
* [arcmt] Add some additional driver flags to optionally emit or save the ↵Argyrios Kyrtzidis2011-07-194-10/+261
| | | | | | | | | | | 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
* [arcmt] When a NSData's 'bytes' family of methods are used on a local var,Argyrios Kyrtzidis2011-07-181-0/+34
| | | | | | | | | 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
* [arcmt] NSInvocation's [get/set]ReturnValue and [get/set]Argument are only safeArgyrios Kyrtzidis2011-07-187-3/+100
| | | | | | with __unsafe_unretained parameters. Emit error for strong/weak ones. rdar://9206226 llvm-svn: 135381
* [arcmt] It's not safe to remove the -release on "[[someivar delegate] ↵Argyrios Kyrtzidis2011-07-151-9/+31
| | | | | | | | | | | | | | | | | | 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
* [arcmt] Rewrite to "foo = nil;" not "foo = 0;", as suggested by Jordy.Argyrios Kyrtzidis2011-07-151-2/+8
| | | | llvm-svn: 135309
* [arcmt] For:Argyrios Kyrtzidis2011-07-151-8/+31
| | | | | | | | | | | | | | | 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
* Switch comments about 'macro instantiation' to 'macro expansion' inChandler Carruth2011-07-151-2/+2
| | | | | | ARCMigrate. llvm-svn: 135223
* [arcmt] Don't remove retains/releases on a global variable, flag them with ↵Argyrios Kyrtzidis2011-07-144-11/+22
| | | | | | errors. rdar://9402555. llvm-svn: 135213
* [arcmt] Allow -retain of an __unsafe_unretained receiver if the result gets ↵Argyrios Kyrtzidis2011-07-141-1/+2
| | | | | | | | used. Keep the error if the result is unused. rdar://9552694. llvm-svn: 135209
* [arcmt] Emit an error for unused -autorelease messages.Argyrios Kyrtzidis2011-07-141-2/+14
| | | | | | | | | | | 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
* Convert terminology in the Lexer from 'instantiate' and variants toChandler Carruth2011-07-142-3/+3
| | | | | | | | | '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
* [arcmt] Make sure migrating to ARC works even if '-fobjc-arc' is included in ↵Argyrios Kyrtzidis2011-07-141-1/+9
| | | | | | command-line flags. rdar://9567824 llvm-svn: 135115
* [arcmt] Add weak/unsafe_unretained for "@property (readonly)" when we are ↵Argyrios Kyrtzidis2011-07-131-1/+1
| | | | | | @synthesizing it. llvm-svn: 135067
* [arcmt] For properties rewrite 'assign' -> 'weak or unsafe_unretained', ↵Argyrios Kyrtzidis2011-07-133-135/+239
| | | | | | | | 'retain' -> 'strong', and add 'weak or unsafe_unretained' when 'assign' is missing. rdar://9496219&9602589. llvm-svn: 135065
* [arcmt] Also avoid 'weak' for forward references to objc classes.Argyrios Kyrtzidis2011-07-121-0/+2
| | | | llvm-svn: 135003
* [arcmt] Before applying '__weak' check whether the objc class is annotated ↵Argyrios Kyrtzidis2011-07-124-4/+62
| | | | | | | | | | with objc_arc_weak_reference_unavailable or is in a list of classes not supporting 'weak'. rdar://9489367. llvm-svn: 135002
* [arcmt] Remove redundant has_error() check.Argyrios Kyrtzidis2011-07-101-2/+2
| | | | llvm-svn: 134876
* [arcmt] Try fixing test/ARCMT/migrate.m for windows hosts.Argyrios Kyrtzidis2011-07-101-1/+2
| | | | llvm-svn: 134875
* [arcmt] Introduce new '-ccc-arcmt-migrate <path>' ARC migration driver option.Argyrios Kyrtzidis2011-07-093-19/+87
| | | | | | | | | | | | | | | | | | | | 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
* Move SourceManager::isAt[Start/End]OfMacroInstantiation functions to the ↵Argyrios Kyrtzidis2011-07-072-3/+3
| | | | | | Lexer, since they depend on it now. llvm-svn: 134644
* In ARC, reclaim all return values of retainable type, not just thoseJohn McCall2011-07-073-9/+11
| | | | | | | | | | | | 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
* Make the Preprocessor more memory efficient and improve macro instantiation ↵Argyrios Kyrtzidis2011-07-072-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Change the driver's logic about Objective-C runtimes: abstract out aJohn McCall2011-07-063-5/+5
| | | | | | | | | | | | 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
* Rename objc_lifetime -> objc_ownership, and modify diagnostics to talk about ↵Argyrios Kyrtzidis2011-06-241-4/+4
| | | | | | | | 'ownership', not 'lifetime'. rdar://9477613. llvm-svn: 133779
* Unbreak the CMake build.Alexis Hunt2011-06-231-1/+0
| | | | llvm-svn: 133769
* [arcmt] Fully migrate ObjC++ classes, rdar://9660007.Argyrios Kyrtzidis2011-06-234-28/+8
| | | | llvm-svn: 133763
* [arcmt] Remove rewriteAllocCopyWithZone transformation; not needed anymore.Argyrios Kyrtzidis2011-06-233-225/+0
| | | | llvm-svn: 133762
* [arcmt] Make -Warc-unsafe-retained-assign an error when migrating. ↵Argyrios Kyrtzidis2011-06-221-0/+2
| | | | | | rdar://8939557 llvm-svn: 133627
* Unbreak the CMake buildAlexis Hunt2011-06-211-1/+1
| | | | llvm-svn: 133557
* [arcmt] Merge 'removeEmptyStatements' and 'removeDeallocMethod' passes to ↵Argyrios Kyrtzidis2011-06-216-216/+215
| | | | | | | | cut down on one compilation pass and increase migration speed. llvm-svn: 133540
* [arcmt] Break apart Transforms.cpp.Argyrios Kyrtzidis2011-06-2114-1941/+2180
| | | | llvm-svn: 133539
* [arcmt] Always add '__bridge' cast when 'self' is cast to a C pointer. ↵Argyrios Kyrtzidis2011-06-201-33/+29
| | | | | | rdar://9644061 llvm-svn: 133480
* [arcmt] Find out whether there is an ARC runtime directly from the triple, ↵Argyrios Kyrtzidis2011-06-201-50/+66
| | | | | | avoid hacky delegation to the driver for that. llvm-svn: 133464
* [arcmt] Fix the ARC migrator. -arcmt-modify requires running before the ↵Argyrios Kyrtzidis2011-06-183-12/+17
| | | | | | | | initialization of SourceManager because it is going to modify the input file. llvm-svn: 133323
* [arcmt] Const'ify.Argyrios Kyrtzidis2011-06-182-6/+6
| | | | llvm-svn: 133322
* [arcmt] Remove '-arcmt-modify-in-memory', it turned out less useful than we ↵Argyrios Kyrtzidis2011-06-172-50/+0
| | | | | | hoped it would be. llvm-svn: 133315
* Objective-C fast enumeration loop variables are not retained in ARC, butJohn McCall2011-06-171-4/+1
| | | | | | | | | | | | 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
* Raise the ARCMT functionality in Clang into proper FrontendActions.Chandler Carruth2011-06-162-0/+59
| | | | | | | | | | | | | | | | | | | | | These are somewhat special in that they wrap any other FrontendAction, running various ARC transformations or checks prior to the standard action's run. To implement them easily, this extends FrontendAction to have a WrapperFrontendAction utility class which forwards all calls by default to an inner action setup at construction time. This is then subclassed to override the specific behavior needed by the different ARCMT tools. Finally, FrontendTool is taught how to create these wrapper actions from the existing flags and options structures. The result is that clangFrontend no longer depends on clangARCMigrate. This is very important, as clangARCMigrate *heavily* depends on clangFrontend. Fundamentally ARCMigrate is at the same layer as a library like Rewrite, sitting firmly on top of the Frontend, but tied together with the FrontendTool when building the clang binary itself. llvm-svn: 133161
* [arcmt] Fix tests in non-darwin.Argyrios Kyrtzidis2011-06-161-0/+5
| | | | llvm-svn: 133140
* The ARC Migration Tool. All the credit goes to Argyrios and FariborzJohn McCall2011-06-157-0/+3745
for this. llvm-svn: 133104
OpenPOWER on IntegriCloud