brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.0 KiB · 51ea25e Raw
74 lines · cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=core.DivideZero -verify %s2 3int 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 15namespace GH148875 {16struct A {17  int x;18  A(int v) : x(v) {}19};20 21struct B {22  int x;23  B() : x(0) {}24};25 26struct C {27  int x, y;28  C(int a, int b) : x(a), y(b) {}29};30 31struct D {32  int x;33};34 35struct E {36  D d;37  E(int a) : d{a} {}38};39 40struct F {41  int x;42};43 44int t1() {45  A a{42};46  return 1 / (a.x - 42); // expected-warning {{Division by zero}}47}48 49int t2() {50  B b{};51  return 1 / b.x; // expected-warning {{Division by zero}}52}53 54int t3() {55  C c1{1, -1};56  return 1 / (c1.x + c1.y); // expected-warning {{Division by zero}}57}58 59int t4() {60  C c2{0, 0};61  return 1 / (c2.x + c2.y); // expected-warning {{Division by zero}}62}63 64int t5() {65  E e{32};66  return 1 / (e.d.x - 32); // expected-warning {{Division by zero}}67}68 69int t6() {70  F f{32};71  return 1 / (f.x - 32); // expected-warning {{Division by zero}}72}73}74