blob: 4257220f9bd65a7bde2868ed359a5245e461ce1c [file] [log] [blame]
Ted Kremenekd87d7b22009-01-22 20:27:48 +00001// RUN: clang -analyze -checker-simple -analyzer-store-basic -verify %s &&
2// RUN: clang -analyze -checker-cfref -analyzer-store-basic -verify %s &&
3// RUN: clang -analyze -checker-cfref -analyzer-store-region -verify %s
Zhongxing Xubcec9d52008-10-17 05:19:52 +00004
Zhongxing Xu84b043e2008-10-24 08:51:58 +00005struct s {
6 int data;
7 int data_array[10];
8};
Zhongxing Xubcec9d52008-10-17 05:19:52 +00009
Zhongxing Xu305ea6c2008-10-27 09:19:25 +000010typedef struct {
11 int data;
12} STYPE;
13
Zhongxing Xu29c87a22008-11-02 13:17:44 +000014void g1(struct s* p);
15
Zhongxing Xucb9ca8d2008-11-25 01:45:11 +000016// Array to pointer conversion. Array in the struct field.
Zhongxing Xubcec9d52008-10-17 05:19:52 +000017void f(void) {
18 int a[10];
19 int (*p)[10];
20 p = &a;
21 (*p)[3] = 1;
22
23 struct s d;
24 struct s *q;
25 q = &d;
Zhongxing Xu84b043e2008-10-24 08:51:58 +000026 q->data = 3;
27 d.data_array[9] = 17;
Zhongxing Xubcec9d52008-10-17 05:19:52 +000028}
Zhongxing Xubbef7052008-10-25 14:11:23 +000029
Zhongxing Xucb9ca8d2008-11-25 01:45:11 +000030// StringLiteral in lvalue context and pointer to array type.
31// p: ElementRegion, q: StringRegion
Zhongxing Xubbef7052008-10-25 14:11:23 +000032void f2() {
33 char *p = "/usr/local";
34 char (*q)[4];
35 q = &"abc";
36}
Zhongxing Xu305ea6c2008-10-27 09:19:25 +000037
Zhongxing Xucb9ca8d2008-11-25 01:45:11 +000038// Typedef'ed struct definition.
Zhongxing Xu305ea6c2008-10-27 09:19:25 +000039void f3() {
40 STYPE s;
41}
Zhongxing Xuaeef0612008-10-31 10:23:14 +000042
Zhongxing Xucb9ca8d2008-11-25 01:45:11 +000043// Initialize array with InitExprList.
Zhongxing Xuaeef0612008-10-31 10:23:14 +000044void f4() {
45 int a[] = { 1, 2, 3};
46 int b[3] = { 1, 2 };
47}
Zhongxing Xu29c87a22008-11-02 13:17:44 +000048
Zhongxing Xucb9ca8d2008-11-25 01:45:11 +000049// Struct variable in lvalue context.
Zhongxing Xu85adc922009-01-13 01:49:57 +000050// Assign UnknownVal to the whole struct.
Zhongxing Xu29c87a22008-11-02 13:17:44 +000051void f5() {
52 struct s data;
53 g1(&data);
54}
Zhongxing Xu05ce9aa2008-11-13 07:59:15 +000055
Zhongxing Xucb9ca8d2008-11-25 01:45:11 +000056// AllocaRegion test.
Zhongxing Xu05ce9aa2008-11-13 07:59:15 +000057void f6() {
58 char *p;
59 p = __builtin_alloca(10);
60 p[1] = 'a';
61}
Zhongxing Xu54f2e182008-11-13 08:44:52 +000062
63struct s2;
64
65void g2(struct s2 *p);
66
Zhongxing Xucb9ca8d2008-11-25 01:45:11 +000067// Incomplete struct pointer used as function argument.
Zhongxing Xu54f2e182008-11-13 08:44:52 +000068void f7() {
69 struct s2 *p = __builtin_alloca(10);
70 g2(p);
71}
Zhongxing Xu59501122008-11-13 09:20:05 +000072
Zhongxing Xucb9ca8d2008-11-25 01:45:11 +000073// sizeof() is unsigned while -1 is signed in array index.
Zhongxing Xu59501122008-11-13 09:20:05 +000074void f8() {
75 int a[10];
Zhongxing Xu150824e2008-11-24 23:45:56 +000076 a[sizeof(a)/sizeof(int) - 1] = 1; // no-warning
Zhongxing Xu59501122008-11-13 09:20:05 +000077}
Zhongxing Xuaeb9cc92008-11-18 13:30:46 +000078
Zhongxing Xucb9ca8d2008-11-25 01:45:11 +000079// Initialization of struct array elements.
Zhongxing Xuaeb9cc92008-11-18 13:30:46 +000080void f9() {
81 struct s a[10];
82}
Zhongxing Xuc8f73c52008-11-30 05:51:19 +000083
84// Initializing array with string literal.
85void f10() {
86 char a1[4] = "abc";
Zhongxing Xuc8f73c52008-11-30 05:51:19 +000087 char a3[6] = "abc";
88}