1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.cstring,alpha.unix.cstring,debug.ExprInspection -analyzer-store=region -verify %s 2 3 #include "Inputs/system-header-simulator-cxx.h" 4 #include "Inputs/system-header-simulator-for-malloc.h" 5 6 void clang_analyzer_eval(int); 7 8 int *testStdCopyInvalidatesBuffer(std::vector<int> v) { 9 int n = v.size(); 10 int *buf = (int *)malloc(n * sizeof(int)); 11 12 buf[0] = 66; 13 14 // Call to copy should invalidate buf. 15 std::copy(v.begin(), v.end(), buf); 16 17 int i = buf[0]; 18 19 clang_analyzer_eval(i == 66); // expected-warning {{UNKNOWN}} 20 21 return buf; 22 } 23 24 int *testStdCopyBackwardInvalidatesBuffer(std::vector<int> v) { 25 int n = v.size(); 26 int *buf = (int *)malloc(n * sizeof(int)); 27 28 buf[0] = 66; 29 30 // Call to copy_backward should invalidate buf. 31 std::copy_backward(v.begin(), v.end(), buf + n); 32 33 int i = buf[0]; 34 35 clang_analyzer_eval(i == 66); // expected-warning {{UNKNOWN}} 36 37 return buf; 38 } 39