brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 1fcb670 Raw
56 lines · cpp
1// RUN: %clang_analyze_cc1 -w -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-allocator-inlining=true -std=c++11 -verify -analyzer-config eagerly-assume=false %s2 3void clang_analyzer_eval(bool);4void clang_analyzer_warnIfReached();5 6struct S {7  int x;8  S() : x(1) {}9  ~S() {}10};11 12void checkConstructorInlining() {13  S *s = new S;14  clang_analyzer_eval(s->x == 1); // expected-warning{{TRUE}}15}16 17void checkNewPODunit() {18  int *i = new int;19  clang_analyzer_eval(*i == 0); // expected-warning{{The left operand of '==' is a garbage value [core.UndefinedBinaryOperatorResult]}}20}21 22void checkNewPOD() {23  int *j = new int();24  clang_analyzer_eval(*j == 0); // expected-warning{{TRUE}}25  int *k = new int(5);26  clang_analyzer_eval(*k == 5); // expected-warning{{TRUE}}27}28 29void checkNewArray() {30  S *s = new S[10];31 32  // FIXME: Handle big array construction33  clang_analyzer_eval(s[0].x == 1); // expected-warning{{UNKNOWN}}34  clang_analyzer_eval(s[1].x == 1); // expected-warning{{UNKNOWN}}35 36  s = new S[4];37  clang_analyzer_eval(s[0].x == 1); // expected-warning{{TRUE}}38  clang_analyzer_eval(s[1].x == 1); // expected-warning{{TRUE}}39}40 41struct NullS {42  NullS() {43    if (this) {}44  }45  NullS(int x) {46    if (!this) {47      clang_analyzer_warnIfReached(); // no-warning48    }49  }50};51 52void checkNullThis() {53  NullS *nulls = new NullS(); // no-crash54  NullS *nulls2 = new NullS(0);55}56