no-outofbounds.c revision cdc3a89d5de90b2299c56f4a46c3de590c5184d1
1// RUN: %clang_cc1 -analyze -analyzer-checker=core,alpha.core,alpha.unix,alpha.security.ArrayBound -analyzer-store=region -verify %s 2 3//===----------------------------------------------------------------------===// 4// This file tests cases where we should not flag out-of-bounds warnings. 5//===----------------------------------------------------------------------===// 6 7void f() { 8 long x = 0; 9 char *y = (char*) &x; 10 char c = y[0] + y[1] + y[2]; // no-warning 11 short *z = (short*) &x; 12 short s = z[0] + z[1]; // no-warning 13} 14 15void g() { 16 int a[2]; 17 char *b = (char*)a; 18 b[3] = 'c'; // no-warning 19} 20 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]; }; 27 // 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}} 29 a->len = 10; 30 a->data[1] = 5; // no-warning 31 free(a); 32} 33