blob: 2d77cc92adf9a45c63492c731e7d1518f54cf551 [file] [log] [blame]
Ted Kremenek51885072011-03-24 00:28:47 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core,core.experimental,unix.experimental,security.experimental.ArrayBound -analyzer-store=basic -verify %s
2// RUN: %clang_cc1 -analyze -analyzer-checker=core,core.experimental,unix.experimental,security.experimental.ArrayBound -analyzer-store=region -verify %s
Ted Kremenek2f089912009-07-10 21:48:10 +00003
4//===----------------------------------------------------------------------===//
5// This file tests cases where we should not flag out-of-bounds warnings.
6//===----------------------------------------------------------------------===//
Ted Kremenek0b9ad892009-05-04 14:31:19 +00007
Ted Kremenek20bd7462009-05-04 07:04:36 +00008void f() {
9 long x = 0;
10 char *y = (char*) &x;
11 char c = y[0] + y[1] + y[2]; // no-warning
Zhongxing Xu9618b852010-04-01 08:20:27 +000012 short *z = (short*) &x;
13 short s = z[0] + z[1]; // no-warning
Ted Kremenek20bd7462009-05-04 07:04:36 +000014}
Jordy Rose4d912b22010-06-25 23:23:04 +000015
16void g() {
17 int a[2];
18 char *b = (char*)a;
19 b[3] = 'c'; // no-warning
20}
Jordy Rose32f26562010-07-04 00:00:41 +000021
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]; };
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +000028 // 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}}
Jordy Rose32f26562010-07-04 00:00:41 +000030 a->len = 10;
31 a->data[1] = 5; // no-warning
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +000032 free(a);
Jordy Rose32f26562010-07-04 00:00:41 +000033}