Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / Analysis / unix-api.c
blob64ff3c0fccf426799cb8e4fc37aea39f376600b9
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,unix.API -verify %s
3 #ifndef O_RDONLY
4 #define O_RDONLY 0
5 #endif
7 #ifndef NULL
8 #define NULL ((void*) 0)
9 #endif
11 int open(const char *, int, ...);
12 int openat(int, const char *, int, ...);
13 int close(int fildes);
15 void open_1(const char *path) {
16 int fd;
17 fd = open(path, O_RDONLY); // no-warning
18 if (fd > -1)
19 close(fd);
22 void open_2(const char *path) {
23 int fd;
24 int mode = 0x0;
25 fd = open(path, O_RDONLY, mode, NULL); // expected-warning{{Call to 'open' with more than 3 arguments}}
26 if (fd > -1)
27 close(fd);
30 void openat_2(int base_fd, const char *path) {
31 int fd;
32 int mode = 0x0;
33 fd = openat(base_fd, path, O_RDONLY, mode, NULL); // expected-warning{{Call to 'openat' with more than 4 arguments}}
34 if (fd > -1)
35 close(fd);
38 void open_3(const char *path) {
39 int fd;
40 fd = open(path, O_RDONLY, NULL); // expected-warning{{The 3rd argument to 'open' is not an integer}}
41 if (fd > -1)
42 close(fd);
45 void openat_3(int base_fd, const char *path) {
46 int fd;
47 fd = openat(base_fd, path, O_RDONLY, NULL); // expected-warning{{The 4th argument to 'openat' is not an integer}}
48 if (fd > -1)
49 close(fd);
53 void open_4(const char *path) {
54 int fd;
55 fd = open(path, O_RDONLY, ""); // expected-warning{{The 3rd argument to 'open' is not an integer}}
56 if (fd > -1)
57 close(fd);
60 void open_5(const char *path) {
61 int fd;
62 struct {
63 int val;
64 } st = {0};
65 fd = open(path, O_RDONLY, st); // expected-warning{{The 3rd argument to 'open' is not an integer}}
66 if (fd > -1)
67 close(fd);
70 void open_6(const char *path) {
71 int fd;
72 struct {
73 int val;
74 } st = {0};
75 fd = open(path, O_RDONLY, st.val); // no-warning
76 if (fd > -1)
77 close(fd);
80 void open_7(const char *path) {
81 int fd;
82 fd = open(path, O_RDONLY, &open); // expected-warning{{The 3rd argument to 'open' is not an integer}}
83 if (fd > -1)
84 close(fd);
87 void open_8(const char *path) {
88 int fd;
89 fd = open(path, O_RDONLY, 0.0f); // expected-warning{{The 3rd argument to 'open' is not an integer}}
90 if (fd > -1)
91 close(fd);