72 lines · c
1// RUN: %clang_analyze_cc1 -verify %s \2// RUN: -analyzer-config eagerly-assume=false \3// RUN: -analyzer-checker=core,debug.ExprInspection4 5#include "Inputs/errno_var.h"6#include "Inputs/some_system_globals.h"7#include "Inputs/some_user_globals.h"8 9extern void abort() __attribute__((__noreturn__));10#define assert(expr) ((expr) ? (void)(0) : abort())11 12void invalidate_globals(void);13void clang_analyzer_eval(int x);14 15/// Test the special system 'errno'16void test_errno_constraint() {17 assert(errno > 2);18 clang_analyzer_eval(errno > 2); // expected-warning {{TRUE}}19 invalidate_globals();20 clang_analyzer_eval(errno > 2); // expected-warning {{UNKNOWN}}21}22void test_errno_assign(int x) {23 errno = x;24 clang_analyzer_eval(errno == x); // expected-warning {{TRUE}}25 invalidate_globals();26 clang_analyzer_eval(errno == x); // expected-warning {{UNKNOWN}}27}28 29/// Test user global variables30void 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}}33 invalidate_globals();34 clang_analyzer_eval(my_const_user_global > 2); // expected-warning {{TRUE}}35}36void test_my_const_user_global_assign(int); // One cannot assign value to a const lvalue.37 38void 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}}41 invalidate_globals();42 clang_analyzer_eval(my_mutable_user_global > 2); // expected-warning {{UNKNOWN}}43}44void 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}}47 invalidate_globals();48 clang_analyzer_eval(my_mutable_user_global == x); // expected-warning {{UNKNOWN}}49}50 51/// Test system global variables52void 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}}55 invalidate_globals();56 clang_analyzer_eval(my_const_system_global > 2); // expected-warning {{TRUE}}57}58void test_my_const_system_global_assign(int);// One cannot assign value to a const lvalue.59 60void 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}}63 invalidate_globals();64 clang_analyzer_eval(my_mutable_system_global > 2); // expected-warning {{UNKNOWN}}65}66void 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}}69 invalidate_globals();70 clang_analyzer_eval(my_mutable_system_global == x); // expected-warning {{UNKNOWN}}71}72