Clang Project

clang_source_code/test/Analysis/non-diagnosable-assumptions.c
1// RUN: %clang_analyze_cc1 -w -analyzer-checker=core.DivideZero -analyzer-output=text -verify %s
2
3// This test file verifies the "Assuming..." diagnostic pieces that are being
4// reported when the branch condition was too complicated to explain.
5// Therefore, if your change replaces the generic "Assuming the condition is
6// true" with a more specific message, causing this test to fail, the condition
7// should be replaced with a more complicated condition that we still cannot
8// properly explain to the user. Once we reach the point at which all conditions
9// are "diagnosable", this test (or this note) should probably be removed,
10// together with the code section that handles generic messages for
11// non-diagnosable conditions.
12
13// Function calls are currently non-diagnosable.
14int non_diagnosable();
15
16void test_true() {
17  if (non_diagnosable()) {
18    // expected-note@-1{{Assuming the condition is true}}
19    // expected-note@-2{{Taking true branch}}
20    1 / 0;
21    // expected-warning@-1{{Division by zero}}
22    // expected-note@-2{{Division by zero}}
23  }
24}
25
26void test_false() {
27  if (non_diagnosable()) {
28    // expected-note@-1{{Assuming the condition is false}}
29    // expected-note@-2{{Taking false branch}}
30  } else {
31    1 / 0;
32    // expected-warning@-1{{Division by zero}}
33    // expected-note@-2{{Division by zero}}
34  }
35}
36
37// Test that we're still reporting that the condition is true,
38// when we encounter an exclamation mark (used to be broken).
39void test_exclamation_mark() {
40  if (!non_diagnosable()) {
41    // expected-note@-1{{Assuming the condition is true}}
42    // expected-note@-2{{Taking true branch}}
43    1 / 0;
44    // expected-warning@-1{{Division by zero}}
45    // expected-note@-2{{Division by zero}}
46  }
47}
48