1 // Refer issue 55019 for more details.
2 // A supplemental test case of pr22954.c for other functions modeled in
5 // RUN: %clang_analyze_cc1 %s -verify \
6 // RUN: -analyzer-checker=core \
7 // RUN: -analyzer-checker=unix \
8 // RUN: -analyzer-checker=debug.ExprInspection
10 #include "Inputs/system-header-simulator.h"
11 #include "Inputs/system-header-simulator-cxx.h"
21 void clang_analyzer_dump(const void *);
23 // CStringChecker::memsetAux
27 clang_analyzer_dump(x
.ptr
); // expected-warning {{HeapSymRegion}}
28 memset(x
.arr
, 0, sizeof(x
.arr
));
29 clang_analyzer_dump(x
.ptr
); // expected-warning {{HeapSymRegion}}
30 free(x
.ptr
); // no-leak-warning
33 // CStringChecker::evalCopyCommon
37 clang_analyzer_dump(x
.ptr
); // expected-warning {{HeapSymRegion}}
38 memcpy(x
.arr
, "hi", 2);
39 clang_analyzer_dump(x
.ptr
); // expected-warning {{HeapSymRegion}}
40 free(x
.ptr
); // no-leak-warning
43 // CStringChecker::evalStrcpyCommon
47 clang_analyzer_dump(x
.ptr
); // expected-warning {{HeapSymRegion}}
49 clang_analyzer_dump(x
.ptr
); // expected-warning {{HeapSymRegion}}
50 free(x
.ptr
); // no-leak-warning
56 clang_analyzer_dump(x
.ptr
); // expected-warning {{HeapSymRegion}}
57 strncpy(x
.arr
, "hi", sizeof(x
.arr
));
58 clang_analyzer_dump(x
.ptr
); // expected-warning {{HeapSymRegion}}
59 free(x
.ptr
); // no-leak-warning
62 // CStringChecker::evalStrsep
66 clang_analyzer_dump(x
.ptr
); // expected-warning {{HeapSymRegion}}
68 (void)strsep(&p
, "x");
69 clang_analyzer_dump(x
.ptr
); // expected-warning {{HeapSymRegion}}
70 free(x
.ptr
); // no-leak-warning
73 // CStringChecker::evalStdCopyCommon
77 clang_analyzer_dump(x
.ptr
); // expected-warning {{HeapSymRegion}}
80 std::copy(p
, p
+ 1, x
.arr
);
82 // FIXME: As we currently cannot know whether the copy overflows, the checker
83 // invalidates the entire `x` object. When the copy size through iterators
84 // can be correctly modeled, we can then update the verify direction from
85 // SymRegion to HeapSymRegion as this std::copy call never overflows and
86 // hence the pointer `x.ptr` shall not be invalidated.
87 clang_analyzer_dump(x
.ptr
); // expected-warning {{SymRegion}}
88 delete static_cast<char*>(x
.ptr
); // no-leak-warning