| 1 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix,debug.ExprInspection -verify %s |
| 2 |
|
| 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 |
|
| 10 |
int sprintf(char *str, const char *format, ...); |
| 11 |
int snprintf(char *str, size_t size, const char *format, ...); |
| 12 |
|
| 13 |
void clang_analyzer_warnIfReached(); |
| 14 |
|
| 15 |
struct S { |
| 16 |
static S s1, s2; |
| 17 |
|
| 18 |
// A weird overload within the class that accepts a structure reference |
| 19 |
// instead of a pointer. |
| 20 |
void memcpy(void *, const S &, size_t); |
| 21 |
void test_in_class_weird_memcpy() { |
| 22 |
memcpy(this, s2, 1); // no-crash |
| 23 |
} |
| 24 |
}; |
| 25 |
|
| 26 |
// A similarly weird overload outside of the class. |
| 27 |
void *memcpy(void *, const S &, size_t); |
| 28 |
|
| 29 |
void test_out_of_class_weird_memcpy() { |
| 30 |
memcpy(&S::s1, S::s2, 1); // no-crash |
| 31 |
} |
| 32 |
|
| 33 |
template<typename... Args> |
| 34 |
void log(const char* fmt, const Args&... args) { |
| 35 |
char buf[100] = {}; |
| 36 |
auto f = snprintf; |
| 37 |
auto g = sprintf; |
| 38 |
int n = 0; |
| 39 |
n += f(buf, 99, fmt, args...); // no-crash: The CalleeDecl is a VarDecl, but it's okay. |
| 40 |
n += g(buf, fmt, args...); // no-crash: Same. |
| 41 |
(void)n; |
| 42 |
clang_analyzer_warnIfReached(); // expected-warning {{REACHABLE}} |
| 43 |
} |
| 44 |
|
| 45 |
void test_gh_74269_no_crash() { |
| 46 |
log("%d", 1); |
| 47 |
} |