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