[clang][NFC] simplify the unset check in `ParseLabeledStatement` (#117430)
[llvm-project.git] / clang / test / Analysis / undef-buffers.c
blob993b08e8e5fd7b3b2f52ecbc1d0f6861263d15a7
1 // RUN: %clang_analyze_cc1 -verify %s \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=unix \
4 // RUN: -analyzer-checker=core.uninitialized \
5 // RUN: -analyzer-config unix.DynamicMemoryModeling:Optimistic=true
7 typedef __typeof(sizeof(int)) size_t;
8 void *malloc(size_t);
9 void free(void *);
11 char stackBased1 (void) {
12 char buf[2];
13 buf[0] = 'a';
14 return buf[1]; // expected-warning{{Undefined}}
17 char stackBased2 (void) {
18 char buf[2];
19 buf[1] = 'a';
20 return buf[0]; // expected-warning{{Undefined}}
23 // Exercise the conditional visitor.
24 char stackBased3 (int *x) {
25 char buf[2];
26 int *y;
27 buf[0] = 'a';
28 if (!(y = x)) {
29 return buf[1]; // expected-warning{{Undefined}}
31 return buf[0];
34 char heapBased1 (void) {
35 char *buf = malloc(2);
36 buf[0] = 'a';
37 char result = buf[1]; // expected-warning{{undefined}}
38 free(buf);
39 return result;
42 char heapBased2 (void) {
43 char *buf = malloc(2);
44 buf[1] = 'a';
45 char result = buf[0]; // expected-warning{{undefined}}
46 free(buf);
47 return result;