[cfe-dev] RetainCountChecker | Assertion Failure | check-clang-analysis

Malhar Thakkar via cfe-dev cfe-dev at lists.llvm.org
Sat Jul 1 00:12:00 PDT 2017


Dear all,

I am currently trying to suppress diagnostics emitted if the function under
consideration has a certain annotate attribute ("check_attribute_annotate"
in this case).

Hence, for that, I added the following piece of code to
RetainCountChecker.cpp but it is resulting in some assertion failures while
performing make -j4 check-clang-analysis.



diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
index 89b1291..9f367be 100644
--- a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
+++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
@@ -1894,6 +1894,20 @@ static bool isSynthesizedAccessor(const
StackFrameContext *SFC) {
   return SFC->getAnalysisDeclContext()->isBodyAutosynthesized();
 }

+bool
+isAnnotatedToSkipDiagnostics(const ExplodedNode *EN) {
+  const FunctionDecl *FD = cast<FunctionDecl>(&EN->getCodeDecl());
+  const IdentifierInfo *II = FD->getIdentifier();
+
+  if (II) {
+    for (const auto *Ann : FD->specific_attrs<AnnotateAttr>()){
+      if (Ann->getAnnotation() == "check_attribute_annotate")
+        return true;
+    }
+  }
+  return false;
+}
+
 std::shared_ptr<PathDiagnosticPiece>
 CFRefReportVisitor::VisitNode(const ExplodedNode *N, const ExplodedNode
*PrevN,
                               BugReporterContext &BRC, BugReport &BR) {
@@ -3345,11 +3359,13 @@ void
RetainCountChecker::processNonLeakError(ProgramStateRef St,
   }

   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)){
+    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));
+  }
 }


//===----------------------------------------------------------------------===//

More specifically, the code highlighted in red above is causing the two
assertion failures mentioned below.

The following test-cases are the unexpected failures:

   - Analysis/inlining/RetainCountExamples.m
   - Analysis/properties.m

*Note:* The above diff is a subset of the code that I have changed. I added
the check *if (!isAnnotatedToSkipDiagnostics(N))* before every invocation
to *emitReport* to suppress raising warnings for functions having the
annotate attribute *check_attribute_annotate*. It seemed to work for
manually made test-cases but clearly there is something wrong with my
methodology.


Could anyone please tell me the reason behind these assertion failures?


Thank you.


Regards,
Malhar Thakkar
ᐧ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170701/073c7807/attachment.html>


More information about the cfe-dev mailing list