| 1 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config faux-bodies=true,model-path=%S/Inputs/Models -analyzer-output=plist-multi-file -verify %s -o %t |
| 2 |
// RUN: %normalize_plist <%t | diff -ub %S/Inputs/expected-plists/model-file.cpp.plist - |
| 3 |
|
| 4 |
typedef int* intptr; |
| 5 |
|
| 6 |
// This function is modeled and the p pointer is dereferenced in the model |
| 7 |
// function and there is no function definition available. The modeled |
| 8 |
// function can use any types that are available in the original translation |
| 9 |
// unit, for example intptr in this case. |
| 10 |
void modeledFunction(intptr p); |
| 11 |
|
| 12 |
// This function is modeled and returns true if the parameter is not zero |
| 13 |
// and there is no function definition available. |
| 14 |
bool notzero(int i); |
| 15 |
|
| 16 |
// This functions is not modeled and there is no function definition. |
| 17 |
// available |
| 18 |
bool notzero_notmodeled(int i); |
| 19 |
|
| 20 |
int main() { |
| 21 |
// There is a nullpointer dereference inside this function. |
| 22 |
modeledFunction(0); |
| 23 |
|
| 24 |
int p = 0; |
| 25 |
if (notzero(p)) { |
| 26 |
// It is known that p != 0 because of the information provided by the |
| 27 |
// model of the notzero function. |
| 28 |
int j = 5 / p; |
| 29 |
} |
| 30 |
|
| 31 |
if (notzero_notmodeled(p)) { |
| 32 |
// There is no information about the value of p, because |
| 33 |
// notzero_notmodeled is not modeled and the function definition |
| 34 |
// is not available. |
| 35 |
int j = 5 / p; // expected-warning {{Division by zero}} |
| 36 |
} |
| 37 |
|
| 38 |
return 0; |
| 39 |
} |
| 40 |
|