xref: /minix3/external/bsd/llvm/dist/clang/test/Analysis/outofbound-notwork.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -Wno-array-bounds -analyze -analyzer-checker=core,alpha.security.ArrayBound -analyzer-store=region -verify %s
2*f4a2713aSLionel Sambuc // XFAIL: *
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc // Once we better handle modeling of sizes of VLAs, we can pull this back
5*f4a2713aSLionel Sambuc // into outofbound.c.
6*f4a2713aSLionel Sambuc 
sizeof_vla(int a)7*f4a2713aSLionel Sambuc void sizeof_vla(int a) {
8*f4a2713aSLionel Sambuc   if (a == 5) {
9*f4a2713aSLionel Sambuc     char x[a];
10*f4a2713aSLionel Sambuc     int y[sizeof(x)];
11*f4a2713aSLionel Sambuc     y[4] = 4; // no-warning
12*f4a2713aSLionel Sambuc     y[5] = 5; // expected-warning{{out-of-bound}}
13*f4a2713aSLionel Sambuc   }
14*f4a2713aSLionel Sambuc }
15*f4a2713aSLionel Sambuc 
sizeof_vla_2(int a)16*f4a2713aSLionel Sambuc void sizeof_vla_2(int a) {
17*f4a2713aSLionel Sambuc   if (a == 5) {
18*f4a2713aSLionel Sambuc     char x[a];
19*f4a2713aSLionel Sambuc     int y[sizeof(x) / sizeof(char)];
20*f4a2713aSLionel Sambuc     y[4] = 4; // no-warning
21*f4a2713aSLionel Sambuc     y[5] = 5; // expected-warning{{out-of-bound}}
22*f4a2713aSLionel Sambuc   }
23*f4a2713aSLionel Sambuc }
24*f4a2713aSLionel Sambuc 
sizeof_vla_3(int a)25*f4a2713aSLionel Sambuc void sizeof_vla_3(int a) {
26*f4a2713aSLionel Sambuc   if (a == 5) {
27*f4a2713aSLionel Sambuc     char x[a];
28*f4a2713aSLionel Sambuc     int y[sizeof(*&*&*&x)];
29*f4a2713aSLionel Sambuc     y[4] = 4; // no-warning
30*f4a2713aSLionel Sambuc     y[5] = 5; // expected-warning{{out-of-bound}}
31*f4a2713aSLionel Sambuc   }
32*f4a2713aSLionel Sambuc }
33