[RISCV] Add shrinkwrap test cases showing gaps in current impl
[llvm-project.git] / clang / test / Analysis / unix-fns-o_creat.c
blob76df3851cfc9cbbc2ad8bc92357246f4a7796d83
1 // RUN: %clang_analyze_cc1 -verify -analyzer-checker=core,unix.API -analyzer-output=text %s
3 // Verify that the UnixAPIChecker finds the missing mode value regardless
4 // of the particular values of these macros, particularly O_CREAT.
5 #define O_RDONLY 0x2000
6 #define O_WRONLY 0x8000
7 #define O_CREAT 0x0002
9 extern int open(const char *path, int flags, ...);
11 void missing_mode_1(const char *path) {
12 (void)open(path, O_CREAT); // expected-warning{{Call to 'open' requires a 3rd argument when the 'O_CREAT' flag is set}} \
13 expected-note{{Call to 'open' requires a 3rd argument when the 'O_CREAT' flag is set}}
16 extern int some_flag;
18 void missing_mode_2(const char *path) {
19 int mode = O_WRONLY;
20 if (some_flag) { // expected-note {{Assuming 'some_flag' is not equal to 0}} \
21 expected-note {{Taking true branch}}
22 mode |= O_CREAT;
24 (void)open(path, mode); // expected-warning{{Call to 'open' requires a 3rd argument when the 'O_CREAT' flag is set}} \
25 expected-note{{Call to 'open' requires a 3rd argument when the 'O_CREAT' flag is set}}
28 void no_creat(const char* path) {
29 int mode = O_RDONLY;
30 (void)open(path, mode); // ok
33 void mode_is_there(const char *path) {
34 int mode = O_WRONLY;
35 if (some_flag) {
36 mode |= O_CREAT;
38 (void)open(path, mode, 0770); // ok