mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-16 22:46:37 +00:00

A clang user pointed out that messages for the static analyzer undefined assignment checker use the term ‘garbage’, which might have a negative connotation to some users. This change updates the messages to use the term ‘uninitialized’. This is the usual reason why a value is undefined in the static analyzer and describes the logical error that a programmer should take action to fix. Out-of-bounds reads can also produce undefined values in the static analyzer. The right long-term design is to have to the array bounds checker cover out-of-bounds reads, so we do not cover that case in the updated messages. The recent improvements to the array bounds checker make it a candidate to add to the core set of checkers. rdar://133418644
31 lines
1.1 KiB
C
31 lines
1.1 KiB
C
// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-output text \
|
|
// RUN: -verify %s
|
|
|
|
void test_no_overflow_note(int a, int b)
|
|
{
|
|
int res;
|
|
|
|
if (__builtin_add_overflow(a, b, &res)) // expected-note {{Assuming no overflow}}
|
|
// expected-note@-1 {{Taking false branch}}
|
|
return;
|
|
|
|
if (res) { // expected-note {{Assuming 'res' is not equal to 0}}
|
|
// expected-note@-1 {{Taking true branch}}
|
|
int *ptr = 0; // expected-note {{'ptr' initialized to a null pointer value}}
|
|
int var = *(int *) ptr; //expected-warning {{Dereference of null pointer}}
|
|
//expected-note@-1 {{Dereference of null pointer}}
|
|
}
|
|
}
|
|
|
|
void test_overflow_note(int a, int b)
|
|
{
|
|
int res; // expected-note{{'res' declared without an initial value}}
|
|
|
|
if (__builtin_add_overflow(a, b, &res)) { // expected-note {{Assuming overflow}}
|
|
// expected-note@-1 {{Taking true branch}}
|
|
int var = res; // expected-warning{{Assigned value is uninitialized}}
|
|
// expected-note@-1 {{Assigned value is uninitialized}}
|
|
return;
|
|
}
|
|
}
|