Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / Analysis / unary-sym-expr.c
blob92e11b295bee7c227c242d81288f927b797dc7c1
1 // RUN: %clang_analyze_cc1 %s \
2 // RUN: -analyzer-checker=core,debug.ExprInspection \
3 // RUN: -analyzer-config eagerly-assume=false \
4 // RUN: -verify
6 void clang_analyzer_eval(int);
7 void clang_analyzer_dump(int);
9 int test(int x, int y) {
11 clang_analyzer_dump(-x); // expected-warning{{-reg_$0<int x>}}
12 clang_analyzer_dump(~x); // expected-warning{{~reg_$0<int x>}}
13 int z = x + y;
14 clang_analyzer_dump(-z); // expected-warning{{-((reg_$0<int x>) + (reg_$1<int y>))}}
15 clang_analyzer_dump(-(x + y)); // expected-warning{{-((reg_$0<int x>) + (reg_$1<int y>))}}
16 clang_analyzer_dump(-x + y); // expected-warning{{(-reg_$0<int x>) + (reg_$1<int y>)}}
18 if (-x == 0) {
19 clang_analyzer_eval(-x == 0); // expected-warning{{TRUE}}
20 clang_analyzer_eval(-x > 0); // expected-warning{{FALSE}}
21 clang_analyzer_eval(-x < 0); // expected-warning{{FALSE}}
23 if (~y == 0) {
24 clang_analyzer_eval(~y == 0); // expected-warning{{TRUE}}
25 clang_analyzer_eval(~y > 0); // expected-warning{{FALSE}}
26 clang_analyzer_eval(~y < 0); // expected-warning{{FALSE}}
28 (void)(x);
29 return 42;
32 void test_svalbuilder_simplification_add(int x, int y) {
33 if (x + y != 3)
34 return;
35 clang_analyzer_eval(-(x + y) == -3); // expected-warning{{TRUE}}
36 clang_analyzer_eval(-(y + x) == -3); // expected-warning{{TRUE}}
39 void test_svalbuilder_simplification_mul(int x, int y) {
40 if (x * y != 3)
41 return;
42 clang_analyzer_eval(-(x * y) == -3); // expected-warning{{TRUE}}
43 clang_analyzer_eval(-(y * x) == -3); // expected-warning{{TRUE}}
46 void test_svalbuilder_simplification_and(int x, int y) {
47 if ((x & y) != 3)
48 return;
49 clang_analyzer_eval(-(x & y) == -3); // expected-warning{{TRUE}}
50 clang_analyzer_eval(-(y & x) == -3); // expected-warning{{TRUE}}
53 void test_svalbuilder_simplification_or(int x, int y) {
54 if ((x | y) != 3)
55 return;
56 clang_analyzer_eval(-(x | y) == -3); // expected-warning{{TRUE}}
57 clang_analyzer_eval(-(y | x) == -3); // expected-warning{{TRUE}}
60 void test_svalbuilder_simplification_xor(int x, int y) {
61 if ((x ^ y) != 3)
62 return;
63 clang_analyzer_eval(-(x ^ y) == -3); // expected-warning{{TRUE}}
64 clang_analyzer_eval(-(y ^ x) == -3); // expected-warning{{TRUE}}
67 int test_fp(int flag) {
68 int value;
69 if (flag == 0)
70 value = 1;
71 if (-flag == 0)
72 return value; // no-warning
73 return 42;