brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 3a83220 Raw
41 lines · cpp
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 %t2// RUN: %normalize_plist <%t | diff -ub %S/Inputs/expected-plists/model-file.cpp.plist -3 4typedef int* intptr;5 6// This function is modeled and the p pointer is dereferenced in the model7// function and there is no function definition available. The modeled8// function can use any types that are available in the original translation9// 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 zero13// 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// available18bool 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 the27   // 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, because33   // notzero_notmodeled is not modeled and the function definition34   // is not available.35    int j = 5 / p; // expected-warning {{Division by zero}}36  }37 38  return 0;39}40 41