xref: /llvm-project/clang/test/Analysis/builtin_overflow_notes.c (revision a017ed04cc9bcc75b3c3ef35c923dbe7dc4606f8)
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output text \
2 // RUN:   -verify %s
3 
4 void test_no_overflow_note(int a, int b)
5 {
6    int res;
7 
8    if (__builtin_add_overflow(a, b, &res)) // expected-note {{Assuming no overflow}}
9                                            // expected-note@-1 {{Taking false branch}}
10      return;
11 
12    if (res) { // expected-note {{Assuming 'res' is not equal to 0}}
13               // expected-note@-1 {{Taking true branch}}
14      int *ptr = 0; // expected-note {{'ptr' initialized to a null pointer value}}
15      int var = *(int *) ptr; //expected-warning {{Dereference of null pointer}}
16                              //expected-note@-1 {{Dereference of null pointer}}
17    }
18 }
19 
20 void test_overflow_note(int a, int b)
21 {
22    int res; // expected-note{{'res' declared without an initial value}}
23 
24    if (__builtin_add_overflow(a, b, &res)) { // expected-note {{Assuming overflow}}
25                                              // expected-note@-1 {{Taking true branch}}
26      int var = res; // expected-warning{{Assigned value is garbage or undefined}}
27                     // expected-note@-1 {{Assigned value is garbage or undefined}}
28      return;
29    }
30 }
31