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.

llvm-svn: 188922

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

index 6ad8615..2d9afb0 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 4adf834..fbaa1ad 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