[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang / test / Analysis / svalbuilder-casts.cpp
blob4cee98927a2cecb1c40eb9c634b8c6a07e0a0b96
1 // RUN: %clang_analyze_cc1 %s \
2 // RUN: -analyzer-checker=core \
3 // RUN: -analyzer-checker=debug.ExprInspection \
4 // RUN: -analyzer-config support-symbolic-integer-casts=true \
5 // RUN: -analyzer-config eagerly-assume=false \
6 // RUN: -triple x86_64-unknown-linux-gnu \
7 // RUN: -verify
9 // Test that the SValBuilder is able to look up and use a constraint for an
10 // operand of a SymbolCast, when the operand is constrained to a const value.
12 void clang_analyzer_eval(bool);
14 extern void abort() __attribute__((__noreturn__));
15 #define assert(expr) ((expr) ? (void)(0) : abort())
17 void test(int x) {
18 // Constrain a SymSymExpr to a constant value.
19 assert(x * x == 1);
20 // It is expected to be able to get the constraint for the operand of the
21 // cast.
22 clang_analyzer_eval((char)(x * x) == 1); // expected-warning{{TRUE}}
23 clang_analyzer_eval((long)(x * x) == 1); // expected-warning{{TRUE}}
26 void test1(int x, int y) {
27 // Even if two lower bytes of `x` equal to zero, it doesn't mean that
28 // the entire `x` is zero. We are not able to know the exact value of x.
29 // It can be one of 65536 possible values like
30 // [0, 65536, -65536, 131072, -131072, ...]. To avoid huge range sets we
31 // still assume `x` in the range [INT_MIN, INT_MAX].
32 assert((short)x == 0); // Lower two bytes are set to 0.
34 static_assert((short)65536 == 0, "");
35 static_assert((short)-65536 == 0, "");
36 static_assert((short)131072 == 0, "");
37 static_assert((short)-131072 == 0, "");
38 clang_analyzer_eval(x == 0); // expected-warning{{UNKNOWN}}
40 // These are not truncated to short as zero.
41 static_assert((short)1 != 0, "");
42 clang_analyzer_eval(x == 1); // expected-warning{{FALSE}}
43 static_assert((short)-1 != 0, "");
44 clang_analyzer_eval(x == -1); // expected-warning{{FALSE}}
45 static_assert((short)65537 != 0, "");
46 clang_analyzer_eval(x == 65537); // expected-warning{{FALSE}}
47 static_assert((short)-65537 != 0, "");
48 clang_analyzer_eval(x == -65537); // expected-warning{{FALSE}}
49 static_assert((short)131073 != 0, "");
50 clang_analyzer_eval(x == 131073); // expected-warning{{FALSE}}
51 static_assert((short)-131073 != 0, "");
52 clang_analyzer_eval(x == -131073); // expected-warning{{FALSE}}
54 // Check for implicit cast.
55 short s = y;
56 assert(s == 0);
57 clang_analyzer_eval(y == 0); // expected-warning{{UNKNOWN}}