// Regression test: we used to assert here. // PR16664 and PR18159 void testConsistencyNested(int i) { extern bool compute(bool); if (i == 5 && (i == 4 || i == 5 || check(NoReturnDtor()))) clang_analyzer_eval(true); // expected-warning{{TRUE}} if (i == 5 && (i == 4 || i == 5 || check(NoReturnDtor()))) clang_analyzer_eval(true); // expected-warning{{TRUE}} if (i != 5) return; if (compute(i == 5 && (i == 4 || compute(true) || compute(i == 5 && (i == 4 || check(NoReturnDtor()))))) || i != 4) { clang_analyzer_eval(true); // expected-warning{{TRUE}} } if (compute(i == 5 && (i == 4 || i == 4 || compute(i == 5 && (i == 4 || check(NoReturnDtor()))))) || i != 4) { clang_analyzer_eval(true); // no warning, unreachable code } }
void testConsistencyIf(int i) { if (i == 5 && (i == 4 || i == 5 || check(NoReturnDtor()))) clang_analyzer_eval(true); // expected-warning{{TRUE}} if (i != 5) return; if (i == 5 && (i == 4 || check(NoReturnDtor()) || i == 5)) { clang_analyzer_eval(true); // no warning, unreachable code } }
void testConsistencyTernary(int i) { (i == 5 && (i == 4 || check(NoReturnDtor()) || i == 5)) ? 1 : 0; clang_analyzer_eval(true); // expected-warning{{TRUE}} if (i != 5) return; (i == 5 && (i == 4 || check(NoReturnDtor()) || i == 5)) ? 1 : 0; clang_analyzer_eval(true); // no warning, unreachable code }
void testLoop() { for (int i = 0; i < 10; ++i) { if (i < 3 && (i >= 2 || check(NoReturnDtor()))) { clang_analyzer_eval(true); // no warning, unreachable code } } }
// PR16664 and PR18159 void testConsistencyNestedComplexNestedBranch(bool value) { if (value) { if (!value || (!value || check(NoReturnDtor()) || value)) { clang_analyzer_eval(true); // no warning, unreachable code } } }
// PR16664 and PR18159 void testConsistencyNestedWarning(bool value) { if (value) { if (!value || value || check(NoReturnDtor())) { clang_analyzer_eval(true); // expected-warning{{TRUE}} } } }
bool testRecursiveFrames(bool isInner) { if (isInner || (clang_analyzer_warnIfReached(), false) || // expected-warning{{REACHABLE}} check(NoReturnDtor()) || testRecursiveFrames(true)) { clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} } }
// PR16664 and PR18159 void testConsistencyNestedVariableModification(bool value) { bool other = true; if (value) { if (!other || !value || (other = false) || check(NoReturnDtor()) || !other) { clang_analyzer_eval(true); // no warning, unreachable code } } }
void testLambdas() { []() { check(NoReturnDtor()); } != nullptr || check(Dtor()); }
void testTernaryFalseBranchReached(bool value) { value ? check(NoReturnDtor()) : clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} }
void testTernaryIgnoreNoreturnBranch(bool value) { if (value) { bool b = !value && !value ? check(NoReturnDtor()) : true; clang_analyzer_eval(true); // expected-warning{{TRUE}} } }
void testTernaryNoReturnFalseBranch(bool value) { if (value) { bool b = !value && !value ? true : check(NoReturnDtor()); clang_analyzer_eval(true); // no warning, unreachable code } }
void testTernaryNoReturnTrueBranch(bool value) { if (value) { bool b = value && (value ? check(NoReturnDtor()) : true); clang_analyzer_eval(true); // no warning, unreachable code } }
void noReturnInline(int **x) { NoReturnDtor(); }
void noReturnTemp(int *x) { if (! x) NoReturnDtor(); *x = 47; // no warning }