brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 94c79b5 Raw
35 lines · c
1// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output text \2// RUN:   -verify %s3 4void 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 20void test_overflow_note(int a, int b)21{22   int res;23 24   if (__builtin_add_overflow(a, b, &res)) { // expected-note {{Assuming overflow}}25                                             // expected-note@-1 {{Taking true branch}}26     if (res) { // expected-note {{Assuming 'res' is not equal to 0}}27                // expected-note@-1 {{Taking true branch}}28        int *ptr = 0; // expected-note {{'ptr' initialized to a null pointer value}}29        int var = *(int *) ptr; //expected-warning {{Dereference of null pointer}}30                                //expected-note@-1 {{Dereference of null pointer}}31     }32     return;33   }34}35