1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,unix,alpha.unix.cstring,debug.ExprInspection -verify %s
3 // Test functions that are called "memcpy" but aren't the memcpy
4 // we're looking for. Unfortunately, this test cannot be put into
5 // a namespace. The out-of-class weird memcpy needs to be recognized
6 // as a normal C function for the test to make sense.
7 typedef __typeof(sizeof(int)) size_t;
8 void *memcpy(void *, const void *, size_t);
9 size_t strlen(const char *s
);
11 int sprintf(char *str
, const char *format
, ...);
12 int snprintf(char *str
, size_t size
, const char *format
, ...);
14 void clang_analyzer_warnIfReached();
19 // A weird overload within the class that accepts a structure reference
20 // instead of a pointer.
21 void memcpy(void *, const S
&, size_t);
22 void test_in_class_weird_memcpy() {
23 memcpy(this, s2
, 1); // no-crash
27 // A similarly weird overload outside of the class.
28 void *memcpy(void *, const S
&, size_t);
30 void test_out_of_class_weird_memcpy() {
31 memcpy(&S::s1
, S::s2
, 1); // no-crash
34 template<typename
... Args
>
35 void log(const char* fmt
, const Args
&... args
) {
40 n
+= f(buf
, 99, fmt
, args
...); // no-crash: The CalleeDecl is a VarDecl, but it's okay.
41 n
+= g(buf
, fmt
, args
...); // no-crash: Same.
43 clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}}
46 void test_gh_74269_no_crash() {
50 struct TestNotNullTerm
{
52 TestNotNullTerm
* const &x
= this;
53 strlen((char *)&x
); // expected-warning{{Argument to string length function is not a null-terminated string}}
57 void test_notcstring_tempobject() {
58 // FIXME: This warning from cstring.NotNullTerminated is a false positive.
59 // Handling of similar cases is not perfect in other cstring checkers.
60 // The fix would be a larger change in CStringChecker and affect multiple checkers.
61 strlen((char[]){'a', 0}); // expected-warning{{Argument to string length function is a C++ temp object of type char[2], which is not a null-terminated string}}