From f23ee512df3d5d1be01b8a041c9475a3252bf80e Mon Sep 17 00:00:00 2001 From: Artem Dergachev Date: Tue, 2 Oct 2018 20:50:40 +0000 Subject: [PATCH] [analyzer] Promote StdCLibraryFunctionsChecker to the apiModeling category. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Because all our languages are C-based, there's no reason to enable this checker only on UNIX targets. Patch by Donát Nagy! Differential Revision: https://reviews.llvm.org/D52722 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@343632 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/StaticAnalyzer/Checkers/Checkers.td | 10 +++++----- test/Analysis/conversion.c | 14 ++++++-------- test/Analysis/std-c-library-functions-inlined.c | 10 +++++----- test/Analysis/std-c-library-functions.c | 10 +++++----- test/Analysis/std-c-library-functions.cpp | 2 +- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/include/clang/StaticAnalyzer/Checkers/Checkers.td b/include/clang/StaticAnalyzer/Checkers/Checkers.td index 435bf6023a..0b50aca495 100644 --- a/include/clang/StaticAnalyzer/Checkers/Checkers.td +++ b/include/clang/StaticAnalyzer/Checkers/Checkers.td @@ -220,11 +220,15 @@ def NullableReturnedFromNonnullChecker : Checker<"NullableReturnedFromNonnull">, let ParentPackage = APIModeling in { +def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">, + HelpText<"Improve modeling of the C standard library functions">, + DescFile<"StdLibraryFunctionsChecker.cpp">; + def TrustNonnullChecker : Checker<"TrustNonnull">, HelpText<"Trust that returns from framework methods annotated with _Nonnull are not null">, DescFile<"TrustNonnullChecker.cpp">; -} +} // end "apiModeling" //===----------------------------------------------------------------------===// // Evaluate "builtin" functions. @@ -494,10 +498,6 @@ def VforkChecker : Checker<"Vfork">, HelpText<"Check for proper usage of vfork">, DescFile<"VforkChecker.cpp">; -def StdCLibraryFunctionsChecker : Checker<"StdCLibraryFunctions">, - HelpText<"Improve modeling of the C standard library functions">, - DescFile<"StdLibraryFunctionsChecker.cpp">; - } // end "unix" let ParentPackage = UnixAlpha in { diff --git a/test/Analysis/conversion.c b/test/Analysis/conversion.c index 7adb336eb2..03cc78e0c1 100644 --- a/test/Analysis/conversion.c +++ b/test/Analysis/conversion.c @@ -1,4 +1,4 @@ -// RUN: %clang_analyze_cc1 -Wno-conversion -Wno-tautological-constant-compare -analyzer-checker=core,alpha.core.Conversion -verify %s +// RUN: %clang_analyze_cc1 -Wno-conversion -Wno-tautological-constant-compare -analyzer-checker=core,apiModeling,alpha.core.Conversion -verify %s unsigned char U8; signed char S8; @@ -138,15 +138,14 @@ void dontwarn5() { } -// false positives.. +// C library functions, handled via apiModeling.StdCLibraryFunctions int isascii(int c); -void falsePositive1() { +void libraryFunction1() { 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 } } @@ -156,7 +155,7 @@ typedef struct FILE {} FILE; int getc(FILE *stream); char reply_string[8192]; FILE *cin; extern int dostuff (void); -int falsePositive2() { +int libraryFunction2() { int c, n; int dig; char *cp = reply_string; @@ -175,8 +174,7 @@ int falsePositive2() { 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 } } } diff --git a/test/Analysis/std-c-library-functions-inlined.c b/test/Analysis/std-c-library-functions-inlined.c index 5277a6efbe..e22df14085 100644 --- a/test/Analysis/std-c-library-functions-inlined.c +++ b/test/Analysis/std-c-library-functions-inlined.c @@ -1,8 +1,8 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=unix.StdCLibraryFunctions -verify %s -// RUN: %clang_analyze_cc1 -triple i686-unknown-linux -analyzer-checker=unix.StdCLibraryFunctions -verify %s -// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=unix.StdCLibraryFunctions -verify %s -// RUN: %clang_analyze_cc1 -triple armv7-a15-linux -analyzer-checker=unix.StdCLibraryFunctions -verify %s -// RUN: %clang_analyze_cc1 -triple thumbv7-a15-linux -analyzer-checker=unix.StdCLibraryFunctions -verify %s +// RUN: %clang_analyze_cc1 -analyzer-checker=apiModeling.StdCLibraryFunctions -verify %s +// RUN: %clang_analyze_cc1 -triple i686-unknown-linux -analyzer-checker=apiModeling.StdCLibraryFunctions -verify %s +// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=apiModeling.StdCLibraryFunctions -verify %s +// RUN: %clang_analyze_cc1 -triple armv7-a15-linux -analyzer-checker=apiModeling.StdCLibraryFunctions -verify %s +// RUN: %clang_analyze_cc1 -triple thumbv7-a15-linux -analyzer-checker=apiModeling.StdCLibraryFunctions -verify %s // This test tests crashes that occur when standard functions are available // for inlining. diff --git a/test/Analysis/std-c-library-functions.c b/test/Analysis/std-c-library-functions.c index 0ccf1a0833..9fb8833175 100644 --- a/test/Analysis/std-c-library-functions.c +++ b/test/Analysis/std-c-library-functions.c @@ -1,8 +1,8 @@ -// RUN: %clang_analyze_cc1 -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s -// RUN: %clang_analyze_cc1 -triple i686-unknown-linux -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s -// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s -// RUN: %clang_analyze_cc1 -triple armv7-a15-linux -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s -// RUN: %clang_analyze_cc1 -triple thumbv7-a15-linux -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s +// RUN: %clang_analyze_cc1 -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s +// RUN: %clang_analyze_cc1 -triple i686-unknown-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s +// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s +// RUN: %clang_analyze_cc1 -triple armv7-a15-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s +// RUN: %clang_analyze_cc1 -triple thumbv7-a15-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s void clang_analyzer_eval(int); diff --git a/test/Analysis/std-c-library-functions.cpp b/test/Analysis/std-c-library-functions.cpp index 00b341af5f..87f84fa881 100644 --- a/test/Analysis/std-c-library-functions.cpp +++ b/test/Analysis/std-c-library-functions.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify %s +// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify %s // Test that we don't model functions with broken prototypes. // Because they probably work differently as well. -- 2.50.1