2017-03-04 02:02:02 +08:00
|
|
|
// RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.Malloc,debug.ExprInspection -verify %s
|
2012-09-12 18:45:40 +08:00
|
|
|
// REQUIRES: LP64
|
2012-06-16 09:28:00 +08:00
|
|
|
|
|
|
|
void clang_analyzer_eval(bool);
|
2011-02-19 04:55:19 +08:00
|
|
|
|
|
|
|
int f1(char *dst) {
|
|
|
|
char *p = dst + 4;
|
|
|
|
char *q = dst + 3;
|
|
|
|
return !(q >= p);
|
|
|
|
}
|
2011-02-19 05:24:56 +08:00
|
|
|
|
2011-02-19 09:08:41 +08:00
|
|
|
long f2(char *c) {
|
|
|
|
return long(c) & 1;
|
|
|
|
}
|
|
|
|
|
2011-02-19 09:59:41 +08:00
|
|
|
bool f3() {
|
|
|
|
return !false;
|
|
|
|
}
|
|
|
|
|
2011-02-19 16:03:18 +08:00
|
|
|
void *f4(int* w) {
|
|
|
|
return reinterpret_cast<void*&>(w);
|
|
|
|
}
|
|
|
|
|
2011-02-19 05:24:56 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct A { };
|
|
|
|
struct B {
|
2011-02-19 10:53:41 +08:00
|
|
|
operator A() { return A(); }
|
2011-02-19 05:24:56 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
A f(char *dst) {
|
|
|
|
B b;
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2011-02-19 16:03:18 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct S {
|
|
|
|
void *p;
|
|
|
|
};
|
|
|
|
|
|
|
|
void *f(S* w) {
|
|
|
|
return &reinterpret_cast<void*&>(*w);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2011-03-26 22:30:44 +08:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
struct C {
|
|
|
|
void *p;
|
|
|
|
static void f();
|
|
|
|
};
|
|
|
|
|
|
|
|
void C::f() { }
|
|
|
|
|
|
|
|
}
|
2012-06-16 09:28:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
void vla(int n) {
|
|
|
|
int nums[n];
|
|
|
|
nums[0] = 1;
|
|
|
|
clang_analyzer_eval(nums[0] == 1); // expected-warning{{TRUE}}
|
|
|
|
|
|
|
|
// This used to fail with MallocChecker on, and /only/ in C++ mode.
|
|
|
|
// This struct is POD, though, so it should be fine to put it in a VLA.
|
|
|
|
struct { int x; } structs[n];
|
|
|
|
structs[0].x = 1;
|
|
|
|
clang_analyzer_eval(structs[0].x == 1); // expected-warning{{TRUE}}
|
|
|
|
}
|
|
|
|
|
2012-06-16 09:28:03 +08:00
|
|
|
void useIntArray(int []);
|
|
|
|
void testIntArrayLiteral() {
|
|
|
|
useIntArray((int []){ 1, 2, 3 });
|
|
|
|
}
|
|
|
|
|