brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.6 KiB · 8210e57 Raw
85 lines · c
1// RUN: %clang_analyze_cc1 %s \2// RUN:   -analyzer-checker=core \3// RUN:   -analyzer-checker=debug.ExprInspection \4// RUN:   -verify5 6void clang_analyzer_warnIfReached(void);7void clang_analyzer_eval(int);8 9void rem_constant_rhs_ne_zero(int x, int y) {10  if (x % 3 == 0) // x % 3 != 0 -> x != 011    return;12  if (x * y != 0) // x * y == 013    return;14  if (y != 1)     // y == 1     -> x == 015    return;16  clang_analyzer_warnIfReached(); // no-warning17  (void)x; // keep the constraints alive.18}19 20void rem_symbolic_rhs_ne_zero(int x, int y, int z) {21  if (x % z == 0) // x % z != 0 -> x != 022    return;23  if (x * y != 0) // x * y == 024    return;25  if (y != 1)     // y == 1     -> x == 026    return;27  clang_analyzer_warnIfReached(); // no-warning28  (void)x; // keep the constraints alive.29}30 31void rem_symbolic_rhs_ne_zero_nested(int w, int x, int y, int z) {32  if (w % x % z == 0) // w % x % z != 0 -> w % x != 033    return;34  if (w % x * y != 0) // w % x * y == 035    return;36  if (y != 1)         // y == 1         -> w % x == 037    return;38  clang_analyzer_warnIfReached(); // no-warning39  (void)(w * x); // keep the constraints alive.40}41 42void rem_constant_rhs_ne_zero_early_contradiction(int x, int y) {43  if ((x + y) != 0)     // (x + y) == 044    return;45  if ((x + y) % 3 == 0) // (x + y) % 3 != 0 -> (x + y) != 0 -> contradiction46    return;47  clang_analyzer_warnIfReached(); // no-warning48  (void)x; // keep the constraints alive.49}50 51void rem_symbolic_rhs_ne_zero_early_contradiction(int x, int y, int z) {52  if ((x + y) != 0)     // (x + y) == 053    return;54  if ((x + y) % z == 0) // (x + y) % z != 0 -> (x + y) != 0 -> contradiction55    return;56  clang_analyzer_warnIfReached(); // no-warning57  (void)x; // keep the constraints alive.58}59 60void internal_unsigned_signed_mismatch(unsigned a) {61  int d = a;62  // Implicit casts are not handled, thus the analyzer models `d % 2` as63  // `(reg_$0<unsigned int a>) % 2`64  // However, this should not result in internal signedness mismatch error when65  // we assign new constraints below.66  if (d % 2 != 0)67    return;68}69 70void remainder_with_adjustment(int x) {71  if ((x + 1) % 3 == 0) // (x + 1) % 3 != 0 -> x + 1 != 0 -> x != -172    return;73  clang_analyzer_eval(x + 1 != 0); // expected-warning{{TRUE}}74  clang_analyzer_eval(x != -1);    // expected-warning{{TRUE}}75  (void)x; // keep the constraints alive.76}77 78void remainder_with_adjustment_of_composit_lhs(int x, int y) {79  if ((x + y + 1) % 3 == 0) // (x + 1) % 3 != 0 -> x + 1 != 0 -> x != -180    return;81  clang_analyzer_eval(x + y + 1 != 0); // expected-warning{{TRUE}}82  clang_analyzer_eval(x + y != -1);    // expected-warning{{TRUE}}83  (void)(x * y); // keep the constraints alive.84}85