blob: a2103376e348abdd99f159a4c00776333ddc743e [file] [log] [blame]
Dominic Chen184c6242017-03-03 18:02:02 +00001// RUN: %clang_analyze_cc1 -triple x86_64-unknown-freebsd %s
Jordan Rose6b33c6f2014-03-26 17:05:46 +00002
3#include "Inputs/system-header-simulator.h"
4
5#define M_ZERO 0x0100
6#define NULL ((void *)0)
7
8void *malloc(size_t, void *, int);
9
10struct test {
11};
12
13void foo(struct test *);
14
15void test_zeroed() {
16 struct test **list, *t;
17 int i;
18
19 list = malloc(sizeof(*list) * 10, NULL, M_ZERO);
20 if (list == NULL)
21 return;
22
23 for (i = 0; i < 10; i++) {
24 t = list[i];
25 foo(t);
26 }
27 free(list); // no-warning
28}
29
30void test_nonzero() {
31 struct test **list, *t;
32 int i;
33
34 list = malloc(sizeof(*list) * 10, NULL, 0);
35 if (list == NULL)
36 return;
37
38 for (i = 0; i < 10; i++) {
39 t = list[i]; // expected-warning{{undefined}}
40 foo(t);
41 }
42 free(list);
43}
44
45void test_indeterminate(int flags) {
46 struct test **list, *t;
47 int i;
48
49 list = malloc(sizeof(*list) * 10, NULL, flags);
50 if (list == NULL)
51 return;
52
53 for (i = 0; i < 10; i++) {
54 t = list[i]; // expected-warning{{undefined}}
55 foo(t);
56 }
57 free(list);
58}