]> granicus.if.org Git - clang/commitdiff
ObjectibeC migrator. Annotate cf_consumed arguments,
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 21 Aug 2013 19:37:47 +0000 (19:37 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 21 Aug 2013 19:37:47 +0000 (19:37 +0000)
as reported by static analyer API with CF_CONSUMED.

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

lib/ARCMigrate/ObjCMT.cpp
test/ARCMT/objcmt-arc-cf-annotations.m.result

index 6ad861531f2866b91bf8a8d937767d38c230fc12..2d9afb03f88975a4168ab6fdc9c04755d3dd524c 100644 (file)
@@ -884,14 +884,24 @@ bool ObjCMigrateASTConsumer::migrateAddFunctionAnnotation(
   unsigned i = 0;
   for (FunctionDecl::param_const_iterator pi = FuncDecl->param_begin(),
        pe = FuncDecl->param_end(); pi != pe; ++pi, ++i) {
+    const ParmVarDecl *pd = *pi;
     ArgEffect AE = AEArgs[i];
     if (AE == DecRef /*CFConsumed annotated*/ ||
         AE == IncRef) {
+      if (AE == DecRef && !pd->getAttr<CFConsumedAttr>() &&
+          Ctx.Idents.get("CF_CONSUMED").hasMacroDefinition()) {
+        edit::Commit commit(*Editor);
+        commit.insertBefore(pd->getLocation(), "CF_CONSUMED ");
+        Editor->commit(commit);
+        HasAtLeastOnePointer = true;
+      }
+      // When AE == IncRef, there is no attribute to annotate with.
+      // It is assumed that compiler will extract the info. from function
+      // API name.
       HasAtLeastOnePointer = true;
       continue;
     }
 
-    const ParmVarDecl *pd = *pi;
     QualType AT = pd->getType();
     bool IsPointer;
     if (!AuditedType(AT, IsPointer))
index 4adf834e91d862826d50af692bed69e3a7f41f5f..fbaa1ad44f4d88c3c04f1f1f4e3d08f3020453ac 100644 (file)
@@ -82,7 +82,7 @@ extern CFTypeRef CFRetain(CFTypeRef cf);
 
 CF_IMPLICIT_BRIDGING_ENABLED
 
-extern void CFRelease(CFTypeRef cf);
+extern void CFRelease(CFTypeRef CF_CONSUMED cf);
 
 CF_IMPLICIT_BRIDGING_DISABLED
 
@@ -229,13 +229,13 @@ typedef void (*IOServiceMatchingCallback)(  void * refcon,  io_iterator_t iterat
 
 CF_IMPLICIT_BRIDGING_ENABLED
 
-io_service_t IOServiceGetMatchingService(  mach_port_t masterPort,  CFDictionaryRef matching );
-kern_return_t IOServiceGetMatchingServices(  mach_port_t masterPort,  CFDictionaryRef matching,  io_iterator_t * existing );
-kern_return_t IOServiceAddNotification(  mach_port_t masterPort,  const io_name_t notificationType,  CFDictionaryRef matching,  mach_port_t wakePort,  uintptr_t reference,  io_iterator_t * notification ) __attribute__((deprecated));
+io_service_t IOServiceGetMatchingService(  mach_port_t masterPort,  CFDictionaryRef CF_CONSUMED matching );
+kern_return_t IOServiceGetMatchingServices(  mach_port_t masterPort,  CFDictionaryRef CF_CONSUMED matching,  io_iterator_t * existing );
+kern_return_t IOServiceAddNotification(  mach_port_t masterPort,  const io_name_t notificationType,  CFDictionaryRef CF_CONSUMED matching,  mach_port_t wakePort,  uintptr_t reference,  io_iterator_t * notification ) __attribute__((deprecated));
 
 CF_IMPLICIT_BRIDGING_DISABLED
  // expected-note {{'IOServiceAddNotification' declared here}}
-kern_return_t IOServiceAddMatchingNotification(  IONotificationPortRef notifyPort,  const io_name_t notificationType,  CFDictionaryRef matching,         IOServiceMatchingCallback callback,         void * refCon,  io_iterator_t * notification );
+kern_return_t IOServiceAddMatchingNotification(  IONotificationPortRef notifyPort,  const io_name_t notificationType,  CFDictionaryRef CF_CONSUMED matching,         IOServiceMatchingCallback callback,         void * refCon,  io_iterator_t * notification );
 
 CF_IMPLICIT_BRIDGING_ENABLED
 
@@ -332,7 +332,7 @@ extern CGGradientRef CGGradientRetain(CGGradientRef gradient);
 
 CF_IMPLICIT_BRIDGING_ENABLED
 
-extern void CGGradientRelease(CGGradientRef gradient);
+extern void CGGradientRelease(CGGradientRef CF_CONSUMED gradient);
 
 CF_IMPLICIT_BRIDGING_DISABLED