1 // RUN: %clang_analyze_cc1 -verify %s \
2 // RUN: -analyzer-config eagerly-assume=false \
3 // RUN: -analyzer-checker=core,debug.ExprInspection
5 #include "Inputs/errno_var.h"
6 #include "Inputs/some_system_globals.h"
7 #include "Inputs/some_user_globals.h"
9 extern void abort() __attribute__((__noreturn__
));
10 #define assert(expr) ((expr) ? (void)(0) : abort())
12 void invalidate_globals(void);
13 void clang_analyzer_eval(int x
);
15 /// Test the special system 'errno'
16 void test_errno_constraint() {
18 clang_analyzer_eval(errno
> 2); // expected-warning {{TRUE}}
20 clang_analyzer_eval(errno
> 2); // expected-warning {{UNKNOWN}}
22 void test_errno_assign(int x
) {
24 clang_analyzer_eval(errno
== x
); // expected-warning {{TRUE}}
26 clang_analyzer_eval(errno
== x
); // expected-warning {{UNKNOWN}}
29 /// Test user global variables
30 void test_my_const_user_global_constraint() {
31 assert(my_const_user_global
> 2);
32 clang_analyzer_eval(my_const_user_global
> 2); // expected-warning {{TRUE}}
34 clang_analyzer_eval(my_const_user_global
> 2); // expected-warning {{TRUE}}
36 void test_my_const_user_global_assign(int); // One cannot assign value to a const lvalue.
38 void test_my_mutable_user_global_constraint() {
39 assert(my_mutable_user_global
> 2);
40 clang_analyzer_eval(my_mutable_user_global
> 2); // expected-warning {{TRUE}}
42 clang_analyzer_eval(my_mutable_user_global
> 2); // expected-warning {{UNKNOWN}}
44 void test_my_mutable_user_global_assign(int x
) {
45 my_mutable_user_global
= x
;
46 clang_analyzer_eval(my_mutable_user_global
== x
); // expected-warning {{TRUE}}
48 clang_analyzer_eval(my_mutable_user_global
== x
); // expected-warning {{UNKNOWN}}
51 /// Test system global variables
52 void test_my_const_system_global_constraint() {
53 assert(my_const_system_global
> 2);
54 clang_analyzer_eval(my_const_system_global
> 2); // expected-warning {{TRUE}}
56 clang_analyzer_eval(my_const_system_global
> 2); // expected-warning {{TRUE}}
58 void test_my_const_system_global_assign(int);// One cannot assign value to a const lvalue.
60 void test_my_mutable_system_global_constraint() {
61 assert(my_mutable_system_global
> 2);
62 clang_analyzer_eval(my_mutable_system_global
> 2); // expected-warning {{TRUE}}
64 clang_analyzer_eval(my_mutable_system_global
> 2); // expected-warning {{UNKNOWN}}
66 void test_my_mutable_system_global_assign(int x
) {
67 my_mutable_system_global
= x
;
68 clang_analyzer_eval(my_mutable_system_global
== x
); // expected-warning {{TRUE}}
70 clang_analyzer_eval(my_mutable_system_global
== x
); // expected-warning {{UNKNOWN}}