1*efa7df16SGabor Marton // RUN: %clang_analyze_cc1 -analyzer-checker=core \ 2*efa7df16SGabor Marton // RUN: -analyzer-output=text \ 3*efa7df16SGabor Marton // RUN: -verify %s 4*efa7df16SGabor Marton 5*efa7df16SGabor Marton namespace test_tracking_of_lhs_multiplier { f(int x,int y)6*efa7df16SGabor Marton int f(int x, int y) { 7*efa7df16SGabor Marton bool p0 = x < 0; // expected-note {{Assuming 'x' is >= 0}} \ 8*efa7df16SGabor Marton // expected-note {{'p0' initialized to 0}} 9*efa7df16SGabor Marton int div = p0 * y; // expected-note {{'div' initialized to 0}} 10*efa7df16SGabor Marton return 1 / div; // expected-note {{Division by zero}} \ 11*efa7df16SGabor Marton // expected-warning {{Division by zero}} 12*efa7df16SGabor Marton } 13*efa7df16SGabor Marton } // namespace test_tracking_of_lhs_multiplier 14*efa7df16SGabor Marton 15*efa7df16SGabor Marton namespace test_tracking_of_rhs_multiplier { f(int x,int y)16*efa7df16SGabor Marton int f(int x, int y) { 17*efa7df16SGabor Marton bool p0 = x < 0; // expected-note {{Assuming 'x' is >= 0}} \ 18*efa7df16SGabor Marton // expected-note {{'p0' initialized to 0}} 19*efa7df16SGabor Marton int div = y * p0; // expected-note {{'div' initialized to 0}} 20*efa7df16SGabor Marton return 1 / div; // expected-note {{Division by zero}} \ 21*efa7df16SGabor Marton // expected-warning {{Division by zero}} 22*efa7df16SGabor Marton } 23*efa7df16SGabor Marton } // namespace test_tracking_of_rhs_multiplier 24*efa7df16SGabor Marton 25*efa7df16SGabor Marton namespace test_tracking_of_nested_multiplier { f(int x,int y,int z)26*efa7df16SGabor Marton int f(int x, int y, int z) { 27*efa7df16SGabor Marton bool p0 = x < 0; // expected-note {{Assuming 'x' is >= 0}} \ 28*efa7df16SGabor Marton // expected-note {{'p0' initialized to 0}} 29*efa7df16SGabor Marton int div = y*z*p0; // expected-note {{'div' initialized to 0}} 30*efa7df16SGabor Marton return 1 / div; // expected-note {{Division by zero}} \ 31*efa7df16SGabor Marton // expected-warning {{Division by zero}} 32*efa7df16SGabor Marton } 33*efa7df16SGabor Marton } // namespace test_tracking_of_nested_multiplier 34*efa7df16SGabor Marton 35*efa7df16SGabor Marton namespace test_tracking_through_multiple_stmts { f(int x,int y)36*efa7df16SGabor Marton int f(int x, int y) { 37*efa7df16SGabor Marton bool p0 = x < 0; // expected-note {{Assuming 'x' is >= 0}} 38*efa7df16SGabor Marton bool p1 = p0 ? 0 : 1; // expected-note {{'p0' is false}} \ 39*efa7df16SGabor Marton // expected-note {{'?' condition is false}} 40*efa7df16SGabor Marton bool p2 = 1 - p1; // expected-note {{'p2' initialized to 0}} 41*efa7df16SGabor Marton int div = p2 * y; // expected-note {{'div' initialized to 0}} 42*efa7df16SGabor Marton return 1 / div; // expected-note {{Division by zero}} \ 43*efa7df16SGabor Marton // expected-warning {{Division by zero}} 44*efa7df16SGabor Marton } 45*efa7df16SGabor Marton } // namespace test_tracking_through_multiple_stmts 46*efa7df16SGabor Marton 47*efa7df16SGabor Marton namespace test_tracking_both_lhs_and_rhs { f(int x,int y)48*efa7df16SGabor Marton int f(int x, int y) { 49*efa7df16SGabor Marton bool p0 = x < 0; // expected-note {{Assuming 'x' is >= 0}} \ 50*efa7df16SGabor Marton // expected-note {{'p0' initialized to 0}} 51*efa7df16SGabor Marton bool p1 = y < 0; // expected-note {{Assuming 'y' is >= 0}} \ 52*efa7df16SGabor Marton // expected-note {{'p1' initialized to 0}} 53*efa7df16SGabor Marton int div = p0 * p1; // expected-note {{'div' initialized to 0}} 54*efa7df16SGabor Marton return 1 / div; // expected-note {{Division by zero}} \ 55*efa7df16SGabor Marton // expected-warning {{Division by zero}} 56*efa7df16SGabor Marton } 57*efa7df16SGabor Marton } // namespace test_tracking_both_lhs_and_rhs 58*efa7df16SGabor Marton 59*efa7df16SGabor Marton namespace test_tracking_of_multiplier_and_parens { f(int x,int y,int z)60*efa7df16SGabor Marton int f(int x, int y, int z) { 61*efa7df16SGabor Marton bool p0 = x < 0; // expected-note {{Assuming 'x' is >= 0}} \ 62*efa7df16SGabor Marton // expected-note {{'p0' initialized to 0}} 63*efa7df16SGabor Marton int div = y*(z*p0); // expected-note {{'div' initialized to 0}} 64*efa7df16SGabor Marton return 1 / div; // expected-note {{Division by zero}} \ 65*efa7df16SGabor Marton // expected-warning {{Division by zero}} 66*efa7df16SGabor Marton } 67*efa7df16SGabor Marton } // namespace test_tracking_of_multiplier_and_parens 68*efa7df16SGabor Marton 69*efa7df16SGabor Marton namespace test_tracking_of_divisible { f(int x,int y)70*efa7df16SGabor Marton int f(int x, int y) { 71*efa7df16SGabor Marton bool p0 = x < 0; // expected-note {{Assuming 'x' is >= 0}} \ 72*efa7df16SGabor Marton // expected-note {{'p0' initialized to 0}} 73*efa7df16SGabor Marton int div = p0 / y; // expected-note {{'div' initialized to 0}} 74*efa7df16SGabor Marton return 1 / div; // expected-note {{Division by zero}} \ 75*efa7df16SGabor Marton // expected-warning {{Division by zero}} 76*efa7df16SGabor Marton } 77*efa7df16SGabor Marton } // namespace test_tracking_of_divisible 78*efa7df16SGabor Marton 79*efa7df16SGabor Marton namespace test_tracking_of_modulo { f(int x,int y)80*efa7df16SGabor Marton int f(int x, int y) { 81*efa7df16SGabor Marton bool p0 = x < 0; // expected-note {{Assuming 'x' is >= 0}} \ 82*efa7df16SGabor Marton // expected-note {{'p0' initialized to 0}} 83*efa7df16SGabor Marton int div = p0 % y; // expected-note {{'div' initialized to 0}} 84*efa7df16SGabor Marton return 1 / div; // expected-note {{Division by zero}} \ 85*efa7df16SGabor Marton // expected-warning {{Division by zero}} 86*efa7df16SGabor Marton } 87*efa7df16SGabor Marton } // namespace test_tracking_of_modulo 88*efa7df16SGabor Marton 89*efa7df16SGabor Marton namespace test_tracking_of_assignment { f(int x)90*efa7df16SGabor Marton int f(int x) { 91*efa7df16SGabor Marton bool p0 = x < 0; // expected-note {{Assuming 'x' is >= 0}} \ 92*efa7df16SGabor Marton // expected-note {{'p0' initialized to 0}} 93*efa7df16SGabor Marton int div = 1; 94*efa7df16SGabor Marton div *= p0; // expected-note {{The value 0 is assigned to 'div'}} 95*efa7df16SGabor Marton return 1 / div; // expected-note {{Division by zero}} \ 96*efa7df16SGabor Marton // expected-warning {{Division by zero}} 97*efa7df16SGabor Marton } 98*efa7df16SGabor Marton } // namespace test_tracking_of_assignment 99