malhar1995 created this revision.

As part of my Google Summer of Code project, I am working on adding support for 
Integer Set Library (ISL) annotations to the current RetainCountChecker.
Hence, to begin with, Dr. Devin Coughlin gave me a task to suppress reference 
counting diagnostics for all ISL functions by preceding them with some annotate 
attribute.
The attached diff aims to do that by not emitting reports if any function on 
the call stack has 'rc_ownership_trusted_implementation' annotate attribute.

Note about ISL:
ISL has annotations __isl_give and __isl_take which are analogous to 
cf_returns_retained and cf_consumed but in case of ISL, annotations precede 
datatypes of function parameters.

Let me know your thoughts on the same.


Repository:
  rL LLVM

https://reviews.llvm.org/D34937

Files:
  lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp

Index: lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -1894,6 +1894,22 @@
   return SFC->getAnalysisDeclContext()->isBodyAutosynthesized();
 }
 
+bool
+isAnnotatedToSkipDiagnostics(const LocationContext *LCtx) {
+  while (LCtx) {
+    if (const StackFrameContext *SFC = dyn_cast<StackFrameContext>(LCtx)) {
+      const Decl *D = SFC->getDecl();
+      for (const auto *Ann : D->specific_attrs<AnnotateAttr>()){
+        if (Ann->getAnnotation() == "rc_ownership_trusted_implementation") {
+          return true;
+        }
+      }
+    }
+    LCtx = LCtx->getParent();
+  }
+  return false;
+}
+
 std::shared_ptr<PathDiagnosticPiece>
 CFRefReportVisitor::VisitNode(const ExplodedNode *N, const ExplodedNode *PrevN,
                               BugReporterContext &BRC, BugReport &BR) {
@@ -3345,11 +3361,13 @@
   }
 
   assert(BT);
-  auto report = std::unique_ptr<BugReport>(
-      new CFRefReport(*BT, C.getASTContext().getLangOpts(), C.isObjCGCEnabled(),
-                      SummaryLog, N, Sym));
-  report->addRange(ErrorRange);
-  C.emitReport(std::move(report));
+  if (!isAnnotatedToSkipDiagnostics(N->getLocationContext())){
+    auto report = std::unique_ptr<BugReport>(
+        new CFRefReport(*BT, C.getASTContext().getLangOpts(), C.isObjCGCEnabled(),
+                        SummaryLog, N, Sym));
+    report->addRange(ErrorRange);
+    C.emitReport(std::move(report));
+  }
 }
 
 //===----------------------------------------------------------------------===//
@@ -3579,9 +3597,10 @@
         if (N) {
           const LangOptions &LOpts = C.getASTContext().getLangOpts();
           bool GCEnabled = C.isObjCGCEnabled();
-          C.emitReport(std::unique_ptr<BugReport>(new CFRefLeakReport(
-              *getLeakAtReturnBug(LOpts, GCEnabled), LOpts, GCEnabled,
-              SummaryLog, N, Sym, C, IncludeAllocationLine)));
+          if (!isAnnotatedToSkipDiagnostics(N->getLocationContext()))
+            C.emitReport(std::unique_ptr<BugReport>(new CFRefLeakReport(
+                *getLeakAtReturnBug(LOpts, GCEnabled), LOpts, GCEnabled,
+                SummaryLog, N, Sym, C, IncludeAllocationLine)));
         }
       }
     }
@@ -3606,9 +3625,10 @@
           if (!returnNotOwnedForOwned)
             returnNotOwnedForOwned.reset(new ReturnedNotOwnedForOwned(this));
 
-          C.emitReport(std::unique_ptr<BugReport>(new CFRefReport(
-              *returnNotOwnedForOwned, C.getASTContext().getLangOpts(),
-              C.isObjCGCEnabled(), SummaryLog, N, Sym)));
+          if (!isAnnotatedToSkipDiagnostics(N->getLocationContext()))
+            C.emitReport(std::unique_ptr<BugReport>(new CFRefReport(
+                *returnNotOwnedForOwned, C.getASTContext().getLangOpts(),
+                C.isObjCGCEnabled(), SummaryLog, N, Sym)));
         }
       }
     }
@@ -3811,9 +3831,10 @@
       overAutorelease.reset(new OverAutorelease(this));
 
     const LangOptions &LOpts = Ctx.getASTContext().getLangOpts();
-    Ctx.emitReport(std::unique_ptr<BugReport>(
-        new CFRefReport(*overAutorelease, LOpts, /* GCEnabled = */ false,
-                        SummaryLog, N, Sym, os.str())));
+    if (!isAnnotatedToSkipDiagnostics(N->getLocationContext()))
+      Ctx.emitReport(std::unique_ptr<BugReport>(
+          new CFRefReport(*overAutorelease, LOpts, /* GCEnabled = */ false,
+                          SummaryLog, N, Sym, os.str())));
   }
 
   return nullptr;
@@ -3865,9 +3886,10 @@
                           : getLeakAtReturnBug(LOpts, GCEnabled);
       assert(BT && "BugType not initialized.");
 
-      Ctx.emitReport(std::unique_ptr<BugReport>(
-          new CFRefLeakReport(*BT, LOpts, GCEnabled, SummaryLog, N, *I, Ctx,
-                              IncludeAllocationLine)));
+      if (!isAnnotatedToSkipDiagnostics(N->getLocationContext()))
+        Ctx.emitReport(std::unique_ptr<BugReport>(
+            new CFRefLeakReport(*BT, LOpts, GCEnabled, SummaryLog, N, *I, Ctx,
+                                IncludeAllocationLine)));
     }
   }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to