blob: 3a8322075bbb27494c6c5a0db42833e68582664b [file] [log] [blame]
Dominic Chen184c6242017-03-03 18:02:02 +00001// 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
Hubert Tong61c848d2019-06-11 14:21:32 +00002// RUN: %normalize_plist <%t | diff -ub %S/Inputs/expected-plists/model-file.cpp.plist -
Ted Kremenekeeccb302014-08-27 15:14:15 +00003
4typedef 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.
10void 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.
14bool notzero(int i);
15
16// This functions is not modeled and there is no function definition.
17// available
18bool notzero_notmodeled(int i);
19
20int 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