Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Analysis / no-outofbounds.c
blob15155729067e9b5c0b4d5c76274c3b9bc4fb3325
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core,alpha.unix,alpha.security.ArrayBound -verify %s
2 // expected-no-diagnostics
4 //===----------------------------------------------------------------------===//
5 // This file tests cases where we should not flag out-of-bounds warnings.
6 //===----------------------------------------------------------------------===//
8 void f(void) {
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
16 void g(void) {
17 int a[2];
18 char *b = (char*)a;
19 b[3] = 'c'; // no-warning
22 typedef typeof(sizeof(int)) size_t;
23 void *malloc(size_t);
24 void free(void *);
26 void field(void) {
27 struct vec { size_t len; int data[0]; };
28 struct vec *a = malloc(sizeof(struct vec) + 10*sizeof(int));
29 a->len = 10;
30 a->data[1] = 5; // no-warning
31 free(a);