]> granicus.if.org Git - clang/commitdiff
[arcmt] When fixing the "unassigned init call" ARC error, make sure
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 31 Mar 2012 01:34:06 +0000 (01:34 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Sat, 31 Mar 2012 01:34:06 +0000 (01:34 +0000)
to do a nil check for the result of the call.

rdar://10950973

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@153793 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ARCMigrate/TransUnusedInitDelegate.cpp
test/ARCMT/init.m
test/ARCMT/init.m.result

index e2aa6ff93cf3e9ae77ebf406730678c0133ed6de..60ed32aef4ce6d0574c03a4635a4bac2f919432e 100644 (file)
@@ -54,7 +54,11 @@ public:
       Transaction Trans(Pass.TA);
       Pass.TA.clearDiagnostic(diag::err_arc_unused_init_message,
                               ME->getExprLoc());
-      Pass.TA.insert(ME->getExprLoc(), "self = ");
+      SourceRange ExprRange = ME->getSourceRange();
+      Pass.TA.insert(ExprRange.getBegin(), "if (!(self = ");
+      std::string retStr = ")) return ";
+      retStr += getNilString(Pass.Ctx);
+      Pass.TA.insertAfterToken(ExprRange.getEnd(), retStr);
     }
     return true;
   }
index 36e5148476e00706e38c2e7542690c22161eeab1..9dbb1f82b8280f7b5debf9c941474508ad9db268 100644 (file)
@@ -3,6 +3,8 @@
 // RUN: diff %t %s.result
 // DISABLE: mingw32
 
+#define nil (void *)0
+
 @interface NSObject
 -init;
 @end
index 9f568d83ed341ddd4ce169dad14051acb0b89f50..d7f730083aabe8120724d6df1a7dfeb3cc6d781f 100644 (file)
@@ -3,6 +3,8 @@
 // RUN: diff %t %s.result
 // DISABLE: mingw32
 
+#define nil (void *)0
+
 @interface NSObject
 -init;
 @end
@@ -16,7 +18,7 @@
 
 @implementation A
 -(id) init {
-  self = [self init];
+  if (!(self = [self init])) return nil;
   id a;
   [a init];
   a = [[A alloc] init];
@@ -25,7 +27,7 @@
 }
 
 -(id) init2 {
-  self = [super init];
+  if (!(self = [super init])) return nil;
   return self;
 }