xref: /llvm-project/clang/test/Analysis/print-ranges.cpp (revision bc08c3cb7f8e797fee14e96eedd3dc358608ada3)
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config eagerly-assume=false -verify %s
2 // UNSUPPORTED z3
3 
4 template <typename T>
5 void clang_analyzer_value(T x);
6 void clang_analyzer_value();
7 template <typename T1, typename T2>
8 void clang_analyzer_value(T1 x, T2 y);
9 
test1(char x)10 void test1(char x) {
11   clang_analyzer_value(x); // expected-warning{{8s:{ [-128, 127] }}}
12   if (x > 42)
13     clang_analyzer_value(x); // expected-warning{{8s:{ [43, 127] }}}
14   if (x == 42)
15     clang_analyzer_value(x); // expected-warning{{8s:42}}
16 }
17 
test2(short x)18 void test2(short x) {
19   clang_analyzer_value(x); // expected-warning{{16s:{ [-32768, 32767] }}}
20   if (x < 4200)
21     clang_analyzer_value(x); // expected-warning{{16s:{ [-32768, 4199] }}}
22   if (x == 4200)
23     clang_analyzer_value(x); // expected-warning{{16s:4200}}
24 }
25 
test3(unsigned long long x)26 void test3(unsigned long long x) {
27   clang_analyzer_value(x); // expected-warning{{64u:{ [0, 18446744073709551615] }}}
28   if (x != 42000000)
29     clang_analyzer_value(x); // expected-warning{{64u:{ [0, 41999999], [42000001, 18446744073709551615] }}}
30   if (x == 18446744073709551615ull)
31     clang_analyzer_value(x); // expected-warning{{64u:18446744073709551615}}
32 }
33 
34 struct S {};
test4(S s)35 void test4(S s) {
36   clang_analyzer_value(s); // expected-warning{{n/a}}
37 }
38 
test5()39 void test5() {
40   clang_analyzer_value(); // expected-warning{{Missing argument}}
41 }
42 
test6(int x,int y)43 void test6(int x, int y) {
44   if (x == 42 && y == 24)
45     // Ignore 'y'.
46     clang_analyzer_value(x, y); // expected-warning{{32s:42}}
47 }
48