Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Analysis / malloc-three-arg.c
blobae6b7e921287a501c8914f1f014740494045dce9
1 // RUN: %clang_analyze_cc1 -triple x86_64-unknown-freebsd %s
3 #include "Inputs/system-header-simulator.h"
5 #define M_ZERO 0x0100
6 #define NULL ((void *)0)
8 void *malloc(size_t, void *, int);
9 void free(void *);
11 struct test {
14 void foo(struct test *);
16 void test_zeroed(void) {
17 struct test **list, *t;
18 int i;
20 list = malloc(sizeof(*list) * 10, NULL, M_ZERO);
21 if (list == NULL)
22 return;
24 for (i = 0; i < 10; i++) {
25 t = list[i];
26 foo(t);
28 free(list); // no-warning
31 void test_nonzero(void) {
32 struct test **list, *t;
33 int i;
35 list = malloc(sizeof(*list) * 10, NULL, 0);
36 if (list == NULL)
37 return;
39 for (i = 0; i < 10; i++) {
40 t = list[i]; // expected-warning{{undefined}}
41 foo(t);
43 free(list);
46 void test_indeterminate(int flags) {
47 struct test **list, *t;
48 int i;
50 list = malloc(sizeof(*list) * 10, NULL, flags);
51 if (list == NULL)
52 return;
54 for (i = 0; i < 10; i++) {
55 t = list[i]; // expected-warning{{undefined}}
56 foo(t);
58 free(list);