xref: /llvm-project/clang/test/Analysis/short-circuiting-eval.cpp (revision 73c72f2c6505d5bc8b47bb0420f6cba5b24270fe)
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core.DivideZero -verify %s
2 
3 int div0LogicalOpInTernary(bool b1) {
4   int y = (b1 || b1) ? 0 : 1;
5   return 1 / y; // expected-warning {{Division by zero}}
6 }
7 
8 int div0LogicalAndArith(bool b1, int x) {
9   int y = (b1 || (x < 3)) ? 0 : 1;
10   return 1 / y; // expected-warning {{Division by zero}}
11 }
12 
13 int div0NestedLogicalOp(bool b1) {
14   int y = (b1 && b1 || b1 && b1) ? 0 : 1;
15   return 1 / y; // expected-warning {{Division by zero}}
16 }
17 
18 int div0TernaryInTernary(bool b) {
19   int y = ((b || b) ? false : true) ? 0 : 1;
20   return 1 / y; // expected-warning {{Division by zero}}
21 }
22 
23 int div0LogicalOpParensInTernary(bool b1) {
24   int y = ((((b1)) || ((b1)))) ? 0 : 1;
25   return 1 / y; // expected-warning {{Division by zero}}
26 }
27 
28 int div0LogicalOpInsideStExpr(bool b1) {
29   int y = ({1; (b1 || b1);}) ? 0 : 1;
30   // expected-warning@-1 {{expression result unused}}
31   return 1 / y; // expected-warning {{Division by zero}}
32 }
33 
34 int div0StExprInsideLogicalOp(bool b1) {
35   int y = (({1; b1;}) || ({1; b1;})) ? 0 : 1;
36   // expected-warning@-1 {{expression result unused}}
37   // expected-warning@-2 {{expression result unused}}
38   return 1 / y; // expected-warning {{Division by zero}}
39 }
40