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