Skip to content

Commit 0b79eb0

Browse files
haoNoQGeorge Karpenkov
authored and
George Karpenkov
committed
[analyzer] Promote StdCLibraryFunctionsChecker to the apiModeling category.
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
1 parent 66940e4 commit 0b79eb0

File tree

5 files changed

+18
-20
lines changed

5 files changed

+18
-20
lines changed

include/clang/StaticAnalyzer/Checkers/Checkers.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def TrustNonnullChecker : Checker<"TrustNonnull">,
215215
HelpText<"Trust that returns from framework methods annotated with _Nonnull "
216216
"are not null">;
217217

218-
}
218+
} // end "apiModeling"
219219

220220
//===----------------------------------------------------------------------===//
221221
// Evaluate "builtin" functions.

test/Analysis/conversion.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_analyze_cc1 -Wno-conversion -Wno-tautological-constant-compare -analyzer-checker=core,alpha.core.Conversion -verify %s
1+
// RUN: %clang_analyze_cc1 -Wno-conversion -Wno-tautological-constant-compare -analyzer-checker=core,apiModeling,alpha.core.Conversion -verify %s
22

33
unsigned char U8;
44
signed char S8;
@@ -144,15 +144,14 @@ char dontwarn6(long long x) {
144144
}
145145

146146

147-
// false positives..
147+
// C library functions, handled via apiModeling.StdCLibraryFunctions
148148

149149
int isascii(int c);
150-
void falsePositive1() {
150+
void libraryFunction1() {
151151
char kb2[5];
152152
int X = 1000;
153153
if (isascii(X)) {
154-
// FIXME: should not warn here:
155-
kb2[0] = X; // expected-warning {{Loss of precision}}
154+
kb2[0] = X; // no-warning
156155
}
157156
}
158157

@@ -161,7 +160,7 @@ typedef struct FILE {} FILE; int getc(FILE *stream);
161160
# define EOF (-1)
162161
char reply_string[8192];
163162
FILE *cin;
164-
extern int dostuff(void);
163+
extern int dostuff (void);
165164
int libraryFunction2() {
166165
int c, n;
167166
int dig;
@@ -181,8 +180,7 @@ int libraryFunction2() {
181180
if (c == EOF)
182181
return(4);
183182
if (cp < &reply_string[sizeof(reply_string) - 1])
184-
// FIXME: should not warn here:
185-
*cp++ = c; // expected-warning {{Loss of precision}}
183+
*cp++ = c; // no-warning
186184
}
187185
}
188186
}

test/Analysis/std-c-library-functions-inlined.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// RUN: %clang_analyze_cc1 -analyzer-checker=unix.StdCLibraryFunctions -verify %s
2-
// RUN: %clang_analyze_cc1 -triple i686-unknown-linux -analyzer-checker=unix.StdCLibraryFunctions -verify %s
3-
// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=unix.StdCLibraryFunctions -verify %s
4-
// RUN: %clang_analyze_cc1 -triple armv7-a15-linux -analyzer-checker=unix.StdCLibraryFunctions -verify %s
5-
// RUN: %clang_analyze_cc1 -triple thumbv7-a15-linux -analyzer-checker=unix.StdCLibraryFunctions -verify %s
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=apiModeling.StdCLibraryFunctions -verify %s
2+
// RUN: %clang_analyze_cc1 -triple i686-unknown-linux -analyzer-checker=apiModeling.StdCLibraryFunctions -verify %s
3+
// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=apiModeling.StdCLibraryFunctions -verify %s
4+
// RUN: %clang_analyze_cc1 -triple armv7-a15-linux -analyzer-checker=apiModeling.StdCLibraryFunctions -verify %s
5+
// RUN: %clang_analyze_cc1 -triple thumbv7-a15-linux -analyzer-checker=apiModeling.StdCLibraryFunctions -verify %s
66

77
// This test tests crashes that occur when standard functions are available
88
// for inlining.

test/Analysis/std-c-library-functions.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// RUN: %clang_analyze_cc1 -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
2-
// RUN: %clang_analyze_cc1 -triple i686-unknown-linux -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
3-
// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
4-
// RUN: %clang_analyze_cc1 -triple armv7-a15-linux -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
5-
// RUN: %clang_analyze_cc1 -triple thumbv7-a15-linux -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
1+
// RUN: %clang_analyze_cc1 -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
2+
// RUN: %clang_analyze_cc1 -triple i686-unknown-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
3+
// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
4+
// RUN: %clang_analyze_cc1 -triple armv7-a15-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
5+
// RUN: %clang_analyze_cc1 -triple thumbv7-a15-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify -analyzer-config eagerly-assume=false %s
66

77
void clang_analyzer_eval(int);
88

test/Analysis/std-c-library-functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=unix.StdCLibraryFunctions,debug.ExprInspection -verify %s
1+
// RUN: %clang_analyze_cc1 -triple x86_64-unknown-linux -analyzer-checker=apiModeling.StdCLibraryFunctions,debug.ExprInspection -verify %s
22

33
// Test that we don't model functions with broken prototypes.
44
// Because they probably work differently as well.

0 commit comments

Comments
 (0)