[AMDGPU][AsmParser][NFC] Get rid of custom default operand handlers.
[llvm-project.git] / clang / test / Analysis / errno-stdlibraryfunctions.c
bloba3b42f4425c352535d8b7a647be4e08bc62afe01
1 // RUN: %clang_analyze_cc1 -verify %s \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=debug.ExprInspection \
4 // RUN: -analyzer-checker=alpha.unix.StdCLibraryFunctions \
5 // RUN: -analyzer-checker=apiModeling.Errno \
6 // RUN: -analyzer-checker=alpha.unix.Errno \
7 // RUN: -analyzer-config alpha.unix.StdCLibraryFunctions:ModelPOSIX=true
9 #include "Inputs/errno_var.h"
11 typedef typeof(sizeof(int)) size_t;
12 typedef __typeof(sizeof(int)) off_t;
13 typedef size_t ssize_t;
14 ssize_t send(int sockfd, const void *buf, size_t len, int flags);
15 off_t lseek(int fildes, off_t offset, int whence);
17 void clang_analyzer_warnIfReached();
18 void clang_analyzer_eval(int);
20 int unsafe_errno_read(int sock, void *data, int data_size) {
21 if (send(sock, data, data_size, 0) != data_size) {
22 if (errno == 1) {
23 // expected-warning@-1{{An undefined value may be read from 'errno'}}
24 return 0;
27 return 1;
30 int errno_lseek(int fildes, off_t offset) {
31 off_t result = lseek(fildes, offset, 0);
32 if (result == (off_t)-1) {
33 // Failure path.
34 // check if the function is modeled
35 clang_analyzer_eval(errno != 0); // expected-warning{{TRUE}}
36 return 2;
38 if (result != offset) {
39 // Not success path (?)
40 // not sure if this is a valid case, allow to check 'errno'
41 if (errno == 1) { // no warning
42 return 1;
44 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
46 if (result == offset) {
47 // The checker does not differentiate for this case.
48 // In general case no relation exists between the arg 2 and the returned
49 // value, only for SEEK_SET.
50 if (errno == 1) { // no warning
51 return 1;
53 clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
55 return 0;