xref: /llvm-project/clang/test/Analysis/solver-sym-simplification-concreteint.c (revision 1ea584377e7897f7df5302ed9cd378d17be14fbf)
1 // RUN: %clang_analyze_cc1 %s \
2 // RUN:   -analyzer-checker=core \
3 // RUN:   -analyzer-checker=debug.ExprInspection \
4 // RUN:   -analyzer-config eagerly-assume=false \
5 // RUN:   -verify
6 
7 void clang_analyzer_warnIfReached(void);
8 void clang_analyzer_eval(_Bool);
9 
test_simplification_to_concrete_int_infeasible(int b,int c)10 void test_simplification_to_concrete_int_infeasible(int b, int c) {
11   if (c + b != 0)     // c + b == 0
12     return;
13   if (b != 1)         // b == 1  --> c + 1 == 0
14     return;
15   if (c != 1)         // c == 1  --> 1 + 1 == 0 contradiction
16     return;
17   clang_analyzer_warnIfReached(); // no-warning
18 
19   // Keep the symbols and the constraints! alive.
20   (void)(b * c);
21   return;
22 }
23 
test_simplification_to_concrete_int_feasible(int b,int c)24 void test_simplification_to_concrete_int_feasible(int b, int c) {
25   if (c + b != 0)
26     return;
27                       // c + b == 0
28   if (b != 1)
29     return;
30                       // b == 1   -->  c + 1 == 0
31   if (c != -1)
32     return;
33                       // c == -1  --> -1 + 1 == 0 OK
34   clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}}
35   clang_analyzer_eval(c == -1);   // expected-warning{{TRUE}}
36 
37   // Keep the symbols and the constraints! alive.
38   (void)(b * c);
39   return;
40 }
41