1 // RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.core,alpha.unix,alpha.security.ArrayBound -analyzer-store=region -verify %s
2
3 //===----------------------------------------------------------------------===//
4 // This file tests cases where we should not flag out-of-bounds warnings.
5 //===----------------------------------------------------------------------===//
6
f()7 void f() {
8 long x = 0;
9 char *y = (char*) &x;
10 char c = y[0] + y[1] + y[2]; // no-warning
11 short *z = (short*) &x;
12 short s = z[0] + z[1]; // no-warning
13 }
14
g()15 void g() {
16 int a[2];
17 char *b = (char*)a;
18 b[3] = 'c'; // no-warning
19 }
20
21 typedef typeof(sizeof(int)) size_t;
22 void *malloc(size_t);
23 void free(void *);
24
field()25 void field() {
26 struct vec { size_t len; int data[0]; };
27 // FIXME: Not warn for this.
28 struct vec *a = malloc(sizeof(struct vec) + 10); // expected-warning {{Cast a region whose size is not a multiple of the destination type size}}
29 a->len = 10;
30 a->data[1] = 5; // no-warning
31 free(a);
32 }
33