| 1 |
// RUN: %clang_analyze_cc1 -verify %s \ |
| 2 |
// RUN: -analyzer-checker=core \ |
| 3 |
// RUN: -analyzer-checker=apiModeling.Errno \ |
| 4 |
// RUN: -analyzer-checker=debug.ErrnoTest \ |
| 5 |
// RUN: -analyzer-checker=unix.Errno \ |
| 6 |
// RUN: -analyzer-config unix.Errno:AllowErrnoReadOutsideConditionExpressions=false \ |
| 7 |
// RUN: -DERRNO_VAR |
| 8 |
|
| 9 |
// RUN: %clang_analyze_cc1 -verify %s \ |
| 10 |
// RUN: -analyzer-checker=core \ |
| 11 |
// RUN: -analyzer-checker=apiModeling.Errno \ |
| 12 |
// RUN: -analyzer-checker=debug.ErrnoTest \ |
| 13 |
// RUN: -analyzer-checker=unix.Errno \ |
| 14 |
// RUN: -analyzer-config unix.Errno:AllowErrnoReadOutsideConditionExpressions=false \ |
| 15 |
// RUN: -DERRNO_FUNC |
| 16 |
|
| 17 |
#include "Inputs/system-header-simulator.h" |
| 18 |
#ifdef ERRNO_VAR |
| 19 |
#include "Inputs/errno_var.h" |
| 20 |
#endif |
| 21 |
#ifdef ERRNO_FUNC |
| 22 |
#include "Inputs/errno_func.h" |
| 23 |
#endif |
| 24 |
|
| 25 |
int ErrnoTesterChecker_setErrnoIfError(); |
| 26 |
|
| 27 |
void test_cond() { |
| 28 |
ErrnoTesterChecker_setErrnoIfError(); |
| 29 |
int A = errno ? 1 : 2; |
| 30 |
// expected-warning@-1{{An undefined value may be read from 'errno'}} |
| 31 |
} |
| 32 |
|
| 33 |
void test_errno_store_into_variable() { |
| 34 |
ErrnoTesterChecker_setErrnoIfError(); |
| 35 |
int a = errno; |
| 36 |
// expected-warning@-1{{An undefined value may be read from 'errno'}} |
| 37 |
} |
| 38 |
|
| 39 |
void test_errno_store_into_variable_in_expr() { |
| 40 |
ErrnoTesterChecker_setErrnoIfError(); |
| 41 |
int a = 4 + errno; |
| 42 |
// expected-warning@-1{{An undefined value may be read from 'errno'}} |
| 43 |
} |
| 44 |
|
| 45 |
int test_errno_return() { |
| 46 |
ErrnoTesterChecker_setErrnoIfError(); |
| 47 |
return errno; |
| 48 |
// expected-warning@-1{{An undefined value may be read from 'errno'}} |
| 49 |
} |
| 50 |
|
| 51 |
int test_errno_return_expr() { |
| 52 |
ErrnoTesterChecker_setErrnoIfError(); |
| 53 |
return errno > 10; |
| 54 |
// expected-warning@-1{{An undefined value may be read from 'errno'}} |
| 55 |
} |