forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A new yaml config file is introduced for the stdlibrary checker, so the user can define argument constraints and function summaries in runtime.
- Loading branch information
Showing
4 changed files
with
305 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# size_t fread(void *restrict ptr, size_t size, size_t nitems, | ||
# FILE *restrict stream); | ||
Summaries: | ||
- Name: "fread" | ||
Signature: | ||
ArgTypes: | ||
- "size_t" | ||
- "size_t" | ||
- "size_t" | ||
- "FILE *restrict" | ||
RetType: "size_t" | ||
EvaluationType: "NoEvalCall" | ||
ArgConstraints: # We give an error if this is violated | ||
- | ||
type: "NotNull" | ||
arg: 0 | ||
|
||
- | ||
type: "NotNull" | ||
arg: 3 | ||
- | ||
type: "BufferSize" | ||
bufferArg: 0 | ||
sizeArg: 1 | ||
countArg: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#list of summaries | ||
- Name: "isalnum" #int isalnum(int) | ||
Signature: | ||
ArgTypes: | ||
- "int" | ||
RetType: "int" | ||
EvaluationType: "EvalCallAsPure" # or NoEvalCall | ||
#case1 | ||
Summary: #This models the function behaviour | ||
- ArgumentCondition: | ||
arg: 0 | ||
type: "WithinRange" | ||
ranges: [['0','9'],['A', 'Z'], ['a', 'z']] | ||
ReturnValueCondition: | ||
type: "OutOfRange" | ||
ranges: [0,0] | ||
Errno: "ErrnoIrrelevant" | ||
AssumptionNote: "Assuming the character is alphanumeric" | ||
- ArgumentCondition: | ||
arg: 0 | ||
type: "WithinRange" | ||
ranges: [128,"UCharRangeMax"] | ||
Errno: "ErrnoIrrelevant" | ||
- ArgumentCondition: | ||
arg: 0 | ||
type: "OutOfRange" | ||
ranges: [['0','9'],['A', 'Z'], ['a', 'z'],[128,"UCharRangeMax"]] | ||
ReturnValueCondition: | ||
type: "WithinRange" | ||
ranges: [0,0] | ||
Errno: "ErrnoIrrelevant" | ||
AssumptionNote: "Assuming the character is non-alphanumeric" | ||
ArgConstraint: # We give an error if this is violated | ||
- ArgumentCondition: | ||
arg: 0 | ||
type: "WithinRange" | ||
ranges: [["EOFv","EOFv"],[0,"UCharRangeMax"]] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Check the basic reporting/warning and the application of constraints. | ||
// RUN: %clang_analyze_cc1 %s \ | ||
// RUN: -analyzer-checker=core \ | ||
// RUN: -analyzer-checker=apiModeling.StdCLibraryFunctions \ | ||
// RUN: -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \ | ||
// RUN: -analyzer-checker=debug.StdCLibraryFunctionsTester \ | ||
// RUN: -analyzer-checker=debug.ExprInspection \ | ||
// RUN: -triple x86_64-unknown-linux-gnu \ | ||
// RUN: -verify=report | ||
|
||
// Check the bugpath related to the reports. | ||
// RUN: %clang_analyze_cc1 %s \ | ||
// RUN: -analyzer-checker=core \ | ||
// RUN: -analyzer-checker=apiModeling.StdCLibraryFunctions \ | ||
// RUN: -analyzer-checker=alpha.unix.StdCLibraryFunctionArgs \ | ||
// RUN: -analyzer-checker=debug.StdCLibraryFunctionsTester \ | ||
// RUN: -analyzer-checker=debug.ExprInspection \ | ||
// RUN: -triple x86_64-unknown-linux-gnu \ | ||
// RUN: -analyzer-output=text \ | ||
// RUN: -verify=bugpath | ||
|
||
void clang_analyzer_eval(int); | ||
|
||
typedef struct FILE FILE; | ||
typedef typeof(sizeof(int)) size_t; | ||
size_t fread(void *restrict, size_t, size_t, FILE *restrict); | ||
void test_notnull_concrete(FILE *fp) { | ||
fread(0, sizeof(int), 10, fp); // \ | ||
// report-warning{{Function argument constraint is not satisfied}} \ | ||
// report-note{{}} \ | ||
// bugpath-warning{{Function argument constraint is not satisfied}} \ | ||
// bugpath-note{{}} \ | ||
// bugpath-note{{Function argument constraint is not satisfied}} | ||
} | ||
void test_notnull_symbolic(FILE *fp, int *buf) { | ||
fread(buf, sizeof(int), 10, fp); | ||
clang_analyzer_eval(buf != 0); // \ | ||
// report-warning{{TRUE}} \ | ||
// bugpath-warning{{TRUE}} \ | ||
// bugpath-note{{TRUE}} \ | ||
// bugpath-note{{'buf' is not equal to null}} | ||
} | ||
void test_notnull_symbolic2(FILE *fp, int *buf) { | ||
if (!buf) // bugpath-note{{Assuming 'buf' is null}} \ | ||
// bugpath-note{{Taking true branch}} | ||
fread(buf, sizeof(int), 10, fp); // \ | ||
// report-warning{{Function argument constraint is not satisfied}} \ | ||
// report-note{{}} \ | ||
// bugpath-warning{{Function argument constraint is not satisfied}} \ | ||
// bugpath-note{{}} \ | ||
// bugpath-note{{Function argument constraint is not satisfied}} | ||
} | ||
typedef __WCHAR_TYPE__ wchar_t; | ||
// This is one test case for the ARR38-C SEI-CERT rule. | ||
void ARR38_C_F(FILE *file) { | ||
enum { BUFFER_SIZE = 1024 }; | ||
wchar_t wbuf[BUFFER_SIZE]; // bugpath-note{{'wbuf' initialized here}} | ||
|
||
const size_t size = sizeof(*wbuf); // bugpath-note{{'size' initialized to}} | ||
const size_t nitems = sizeof(wbuf); // bugpath-note{{'nitems' initialized to}} | ||
|
||
// The 3rd parameter should be the number of elements to read, not | ||
// the size in bytes. | ||
fread(wbuf, size, nitems, file); // \ | ||
// report-warning{{Function argument constraint is not satisfied}} \ | ||
// report-note{{}} \ | ||
// bugpath-warning{{Function argument constraint is not satisfied}} \ | ||
// bugpath-note{{}} \ | ||
// bugpath-note{{Function argument constraint is not satisfied}} | ||
} |