[PATCH] D52423: Make ConversionChecker load StdCLibraryFunctionsChecker

DonĂ¡t Nagy via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 24 07:59:07 PDT 2018


donat.nagy created this revision.
donat.nagy added a reviewer: dergachev.a.
Herald added a subscriber: cfe-commits.

ConversionChecker produces false positives when it encounters the
idiomatic usage of certain well-known functions (e.g. getc() and the
character classification functions like isalpha()). To eliminate these
false positives, the analyzer needs some information about semantics of
these functions. This functionality have been implemented already in
StdCLibraryFunctionsChecker, so we simply load that automatically when
ConversionChecker is loaded.


Repository:
  rC Clang

https://reviews.llvm.org/D52423

Files:
  lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
  lib/StaticAnalyzer/Checkers/InterCheckerAPI.h
  test/Analysis/conversion.c


Index: test/Analysis/conversion.c
===================================================================
--- test/Analysis/conversion.c
+++ test/Analysis/conversion.c
@@ -138,15 +138,14 @@
 }
 
 
-// false positives..
+// old false positives..
 
 int isascii(int c);
 void falsePositive1() {
   char kb2[5];
   int X = 1000;
   if (isascii(X)) {
-    // FIXME: should not warn here:
-    kb2[0] = X; // expected-warning {{Loss of precision}}
+    kb2[0] = X; // no-warning
   }
 }
 
@@ -175,8 +174,7 @@
       if (c == EOF)
         return(4);
       if (cp < &reply_string[sizeof(reply_string) - 1])
-        // FIXME: should not warn here:
-        *cp++ = c; // expected-warning {{Loss of precision}}
+        *cp++ = c; // no-warning
     }
   }
 }
Index: lib/StaticAnalyzer/Checkers/InterCheckerAPI.h
===================================================================
--- lib/StaticAnalyzer/Checkers/InterCheckerAPI.h
+++ lib/StaticAnalyzer/Checkers/InterCheckerAPI.h
@@ -23,5 +23,8 @@
 /// Register the part of MallocChecker connected to InnerPointerChecker.
 void registerInnerPointerCheckerAux(CheckerManager &Mgr);
 
+/// Register evaluation of some basic C standard library functions.
+void registerStdCLibraryFunctionsChecker(CheckerManager &mgr);
+
 }}
 #endif /* INTERCHECKERAPI_H_ */
Index: lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
===================================================================
--- lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
+++ lib/StaticAnalyzer/Checkers/ConversionChecker.cpp
@@ -23,6 +23,7 @@
 //
 //===----------------------------------------------------------------------===//
 #include "ClangSACheckers.h"
+#include "InterCheckerAPI.h"
 #include "clang/AST/ParentMap.h"
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
@@ -159,5 +160,6 @@
 }
 
 void ento::registerConversionChecker(CheckerManager &mgr) {
+  registerStdCLibraryFunctionsChecker(mgr);
   mgr.registerChecker<ConversionChecker>();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52423.166691.patch
Type: text/x-patch
Size: 2014 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180924/4d6332de/attachment.bin>


More information about the cfe-commits mailing list