| 1 |
// RUN: %clang_analyze_cc1 -analyzer-checker=core.DivideZero -verify %s |
| 2 |
|
| 3 |
int fooPR10616 (int qX ) { |
| 4 |
int a, c, d; |
| 5 |
|
| 6 |
d = (qX-1); |
| 7 |
while ( d != 0 ) { |
| 8 |
d = c - (c/d) * d; |
| 9 |
} |
| 10 |
|
| 11 |
return (a % (qX-1)); // expected-warning {{Division by zero}} |
| 12 |
|
| 13 |
} |
| 14 |
|
| 15 |
namespace GH148875 { |
| 16 |
struct A { |
| 17 |
int x; |
| 18 |
A(int v) : x(v) {} |
| 19 |
}; |
| 20 |
|
| 21 |
struct B { |
| 22 |
int x; |
| 23 |
B() : x(0) {} |
| 24 |
}; |
| 25 |
|
| 26 |
struct C { |
| 27 |
int x, y; |
| 28 |
C(int a, int b) : x(a), y(b) {} |
| 29 |
}; |
| 30 |
|
| 31 |
struct D { |
| 32 |
int x; |
| 33 |
}; |
| 34 |
|
| 35 |
struct E { |
| 36 |
D d; |
| 37 |
E(int a) : d{a} {} |
| 38 |
}; |
| 39 |
|
| 40 |
struct F { |
| 41 |
int x; |
| 42 |
}; |
| 43 |
|
| 44 |
int t1() { |
| 45 |
A a{42}; |
| 46 |
return 1 / (a.x - 42); // expected-warning {{Division by zero}} |
| 47 |
} |
| 48 |
|
| 49 |
int t2() { |
| 50 |
B b{}; |
| 51 |
return 1 / b.x; // expected-warning {{Division by zero}} |
| 52 |
} |
| 53 |
|
| 54 |
int t3() { |
| 55 |
C c1{1, -1}; |
| 56 |
return 1 / (c1.x + c1.y); // expected-warning {{Division by zero}} |
| 57 |
} |
| 58 |
|
| 59 |
int t4() { |
| 60 |
C c2{0, 0}; |
| 61 |
return 1 / (c2.x + c2.y); // expected-warning {{Division by zero}} |
| 62 |
} |
| 63 |
|
| 64 |
int t5() { |
| 65 |
E e{32}; |
| 66 |
return 1 / (e.d.x - 32); // expected-warning {{Division by zero}} |
| 67 |
} |
| 68 |
|
| 69 |
int t6() { |
| 70 |
F f{32}; |
| 71 |
return 1 / (f.x - 32); // expected-warning {{Division by zero}} |
| 72 |
} |
| 73 |
} |