2008-11-13 18:42:31 +03:00
|
|
|
// RUN: clang -checker-simple -verify %s
|
2008-11-16 07:47:39 +03:00
|
|
|
// RUN: clang -checker-simple -analyzer-store-region -verify %s
|
2008-10-17 09:19:52 +04:00
|
|
|
|
2008-10-24 12:51:58 +04:00
|
|
|
struct s {
|
|
|
|
int data;
|
|
|
|
int data_array[10];
|
|
|
|
};
|
2008-10-17 09:19:52 +04:00
|
|
|
|
2008-10-27 12:19:25 +03:00
|
|
|
typedef struct {
|
|
|
|
int data;
|
|
|
|
} STYPE;
|
|
|
|
|
2008-11-02 16:17:44 +03:00
|
|
|
void g1(struct s* p);
|
|
|
|
|
2008-11-25 04:45:11 +03:00
|
|
|
// Array to pointer conversion. Array in the struct field.
|
2008-10-17 09:19:52 +04:00
|
|
|
void f(void) {
|
|
|
|
int a[10];
|
|
|
|
int (*p)[10];
|
|
|
|
p = &a;
|
|
|
|
(*p)[3] = 1;
|
|
|
|
|
|
|
|
struct s d;
|
|
|
|
struct s *q;
|
|
|
|
q = &d;
|
2008-10-24 12:51:58 +04:00
|
|
|
q->data = 3;
|
|
|
|
d.data_array[9] = 17;
|
2008-10-17 09:19:52 +04:00
|
|
|
}
|
2008-10-25 18:11:23 +04:00
|
|
|
|
2008-11-25 04:45:11 +03:00
|
|
|
// StringLiteral in lvalue context and pointer to array type.
|
|
|
|
// p: ElementRegion, q: StringRegion
|
2008-10-25 18:11:23 +04:00
|
|
|
void f2() {
|
|
|
|
char *p = "/usr/local";
|
|
|
|
char (*q)[4];
|
|
|
|
q = &"abc";
|
|
|
|
}
|
2008-10-27 12:19:25 +03:00
|
|
|
|
2008-11-25 04:45:11 +03:00
|
|
|
// Typedef'ed struct definition.
|
2008-10-27 12:19:25 +03:00
|
|
|
void f3() {
|
|
|
|
STYPE s;
|
|
|
|
}
|
2008-10-31 13:23:14 +03:00
|
|
|
|
2008-11-25 04:45:11 +03:00
|
|
|
// Initialize array with InitExprList.
|
2008-10-31 13:23:14 +03:00
|
|
|
void f4() {
|
|
|
|
int a[] = { 1, 2, 3};
|
|
|
|
int b[3] = { 1, 2 };
|
|
|
|
}
|
2008-11-02 16:17:44 +03:00
|
|
|
|
2008-11-25 04:45:11 +03:00
|
|
|
// Struct variable in lvalue context.
|
2008-11-02 16:17:44 +03:00
|
|
|
void f5() {
|
|
|
|
struct s data;
|
|
|
|
g1(&data);
|
|
|
|
}
|
2008-11-13 10:59:15 +03:00
|
|
|
|
2008-11-25 04:45:11 +03:00
|
|
|
// AllocaRegion test.
|
2008-11-13 10:59:15 +03:00
|
|
|
void f6() {
|
|
|
|
char *p;
|
|
|
|
p = __builtin_alloca(10);
|
|
|
|
p[1] = 'a';
|
|
|
|
}
|
2008-11-13 11:44:52 +03:00
|
|
|
|
|
|
|
struct s2;
|
|
|
|
|
|
|
|
void g2(struct s2 *p);
|
|
|
|
|
2008-11-25 04:45:11 +03:00
|
|
|
// Incomplete struct pointer used as function argument.
|
2008-11-13 11:44:52 +03:00
|
|
|
void f7() {
|
|
|
|
struct s2 *p = __builtin_alloca(10);
|
|
|
|
g2(p);
|
|
|
|
}
|
2008-11-13 12:20:05 +03:00
|
|
|
|
2008-11-25 04:45:11 +03:00
|
|
|
// sizeof() is unsigned while -1 is signed in array index.
|
2008-11-13 12:20:05 +03:00
|
|
|
void f8() {
|
|
|
|
int a[10];
|
2008-11-25 02:45:56 +03:00
|
|
|
a[sizeof(a)/sizeof(int) - 1] = 1; // no-warning
|
2008-11-13 12:20:05 +03:00
|
|
|
}
|
2008-11-18 16:30:46 +03:00
|
|
|
|
2008-11-25 04:45:11 +03:00
|
|
|
// Initialization of struct array elements.
|
2008-11-18 16:30:46 +03:00
|
|
|
void f9() {
|
|
|
|
struct s a[10];
|
|
|
|
}
|