blob: 821f48610fc0f6885cad4752633720492cd7f9bc [file] [log] [blame]
Ted Kremenek033a07e2011-08-03 23:14:55 +00001// RUN: %clang_cc1 -analyze -analyzer-checker=core,experimental.core,experimental.unix,experimental.security.ArrayBound -analyzer-store=region -verify %s
Ted Kremenek2f089912009-07-10 21:48:10 +00002
3//===----------------------------------------------------------------------===//
4// This file tests cases where we should not flag out-of-bounds warnings.
5//===----------------------------------------------------------------------===//
Ted Kremenek0b9ad892009-05-04 14:31:19 +00006
Ted Kremenek20bd7462009-05-04 07:04:36 +00007void f() {
8 long x = 0;
9 char *y = (char*) &x;
10 char c = y[0] + y[1] + y[2]; // no-warning
Zhongxing Xu9618b852010-04-01 08:20:27 +000011 short *z = (short*) &x;
12 short s = z[0] + z[1]; // no-warning
Ted Kremenek20bd7462009-05-04 07:04:36 +000013}
Jordy Rose4d912b22010-06-25 23:23:04 +000014
15void g() {
16 int a[2];
17 char *b = (char*)a;
18 b[3] = 'c'; // no-warning
19}
Jordy Rose32f26562010-07-04 00:00:41 +000020
21typedef typeof(sizeof(int)) size_t;
22void *malloc(size_t);
23void free(void *);
24
25void field() {
26 struct vec { size_t len; int data[0]; };
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +000027 // 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}}
Jordy Rose32f26562010-07-04 00:00:41 +000029 a->len = 10;
30 a->data[1] = 5; // no-warning
Argyrios Kyrtzidis312dbec2011-02-28 01:26:35 +000031 free(a);
Jordy Rose32f26562010-07-04 00:00:41 +000032}