Skip to content

[analyzer] Update the undefined assignment checker diagnostics to not use the term 'garbage' #126596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions clang/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using namespace ento;
namespace {
class UndefinedAssignmentChecker
: public Checker<check::Bind> {
const BugType BT{this, "Assigned value is garbage or undefined"};
const BugType BT{this, "Assigned value is uninitialized"};

public:
void checkBind(SVal location, SVal val, const Stmt *S,
Expand Down Expand Up @@ -57,8 +57,7 @@ void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,

while (StoreE) {
if (const UnaryOperator *U = dyn_cast<UnaryOperator>(StoreE)) {
OS << "The expression is an uninitialized value. "
"The computed value will also be garbage";
OS << "The expression uses uninitialized memory";

ex = U->getSubExpr();
break;
Expand All @@ -67,8 +66,8 @@ void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
if (const BinaryOperator *B = dyn_cast<BinaryOperator>(StoreE)) {
if (B->isCompoundAssignmentOp()) {
if (C.getSVal(B->getLHS()).isUndef()) {
OS << "The left expression of the compound assignment is an "
"uninitialized value. The computed value will also be garbage";
OS << "The left expression of the compound assignment uses "
<< "uninitialized memory";
ex = B->getLHS();
break;
}
Expand All @@ -89,7 +88,7 @@ void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
for (auto *I : CD->inits()) {
if (I->getInit()->IgnoreImpCasts() == StoreE) {
OS << "Value assigned to field '" << I->getMember()->getName()
<< "' in implicit constructor is garbage or undefined";
<< "' in implicit constructor is uninitialized";
break;
}
}
Expand Down
10 changes: 5 additions & 5 deletions clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2578,17 +2578,17 @@
</array>
<key>depth</key><integer>0</integer>
<key>extended_message</key>
<string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
<string>The left expression of the compound assignment uses uninitialized memory</string>
<key>message</key>
<string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
<string>The left expression of the compound assignment uses uninitialized memory</string>
</dict>
</array>
<key>description</key><string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
<key>description</key><string>The left expression of the compound assignment uses uninitialized memory</string>
<key>category</key><string>Logic error</string>
<key>type</key><string>Assigned value is garbage or undefined</string>
<key>type</key><string>Assigned value is uninitialized</string>
<key>check_name</key><string>core.uninitialized.Assign</string>
<!-- This hash is experimental and going to change! -->
<key>issue_hash_content_of_line_in_context</key><string>025372576cd3ba6716044f93a51c978c</string>
<key>issue_hash_content_of_line_in_context</key><string>324827600c298776167cd9562f71bda6</string>
<key>issue_context_kind</key><string>function</string>
<key>issue_context</key><string>test_objc_fast_enumeration_2</string>
<key>issue_hash_function_offset</key><string>5</string>
Expand Down
10 changes: 5 additions & 5 deletions clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5864,17 +5864,17 @@
</array>
<key>depth</key><integer>0</integer>
<key>extended_message</key>
<string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
<string>The left expression of the compound assignment uses uninitialized memory</string>
<key>message</key>
<string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
<string>The left expression of the compound assignment uses uninitialized memory</string>
</dict>
</array>
<key>description</key><string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
<key>description</key><string>The left expression of the compound assignment uses uninitialized memory</string>
<key>category</key><string>Logic error</string>
<key>type</key><string>Assigned value is garbage or undefined</string>
<key>type</key><string>Assigned value is uninitialized</string>
<key>check_name</key><string>core.uninitialized.Assign</string>
<!-- This hash is experimental and going to change! -->
<key>issue_hash_content_of_line_in_context</key><string>21c774309bdfd487c3d09a61a671bbcc</string>
<key>issue_hash_content_of_line_in_context</key><string>faa8858031ed123ff98cc23cf14d462f</string>
<key>issue_context_kind</key><string>function</string>
<key>issue_context</key><string>test_loop_fast_enumeration</string>
<key>issue_hash_function_offset</key><string>5</string>
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/a_flaky_crash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bool bar(S);
void foo() {
int x;
if (true && bar(S()))
++x; // expected-warning{{The expression is an uninitialized value. The computed value will also be garbage}}
++x; // expected-warning{{The expression uses uninitialized memory}}
}

// 256 copies of the same run-line to make it crash more often when it breaks.
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/analysis-after-multiple-dtors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ int main() {

int x;
int y = x;
// expected-warning@-1{{Assigned value is garbage or undefined}}
// expected-warning@-1{{Assigned value is uninitialized}}
(void)y;
}
6 changes: 3 additions & 3 deletions clang/test/Analysis/array-init-loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void array_uninit() {

auto [a, b, c, d, e] = arr;

int x = e; // expected-warning{{Assigned value is garbage or undefined}}
int x = e; // expected-warning{{Assigned value is uninitialized}}
}

void lambda_init() {
Expand Down Expand Up @@ -168,7 +168,7 @@ struct S3_duplicate {
void array_uninit_non_pod() {
S3 arr[1];

auto [a] = arr; // expected-warning@159{{ in implicit constructor is garbage or undefined }}
auto [a] = arr; // expected-warning@159{{ in implicit constructor is uninitialized}}
}

void lambda_init_non_pod() {
Expand All @@ -191,7 +191,7 @@ void lambda_init_non_pod() {
void lambda_uninit_non_pod() {
S3_duplicate arr[4];

int l = [arr] { return arr[3].i; }(); // expected-warning@164{{ in implicit constructor is garbage or undefined }}
int l = [arr] { return arr[3].i; }(); // expected-warning@164{{ in implicit constructor is uninitialized }}
}

// If this struct is being copy/move constructed by the implicit ctors, ArrayInitLoopExpr
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Analysis/array-punned-region.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void array_struct_bitfield_1() {
int array_struct_bitfield_2() {
BITFIELD_CAST ff = {0};
BITFIELD_CAST *pff = &ff;
int a = *((int *)pff + 2); // expected-warning{{Assigned value is garbage or undefined [core.uninitialized.Assign]}}
int a = *((int *)pff + 2); // expected-warning{{Assigned value is uninitialized [core.uninitialized.Assign]}}
return a;
}

Expand Down
4 changes: 2 additions & 2 deletions clang/test/Analysis/builtin_overflow_notes.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ void test_overflow_note(int a, int b)

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 garbage or undefined}}
// expected-note@-1 {{Assigned value is garbage or undefined}}
int var = res; // expected-warning{{Assigned value is uninitialized}}
// expected-note@-1 {{Assigned value is uninitialized}}
return;
}
}
4 changes: 2 additions & 2 deletions clang/test/Analysis/call-invalidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ int testStdCtorDoesNotInvalidateParentObject() {
int testStdCtorDoesNotInvalidateParentObjectSwapped() {
StdWrappingOpaqueSwapped obj;
int x = obj.o.nested_member; // no-garbage: std::Opaque::ctor might initialized this
int y = obj.uninit; // expected-warning {{Assigned value is garbage or undefined}}
int y = obj.uninit; // expected-warning {{Assigned value is uninitialized}}
return x + y;
}

Expand Down Expand Up @@ -277,6 +277,6 @@ struct StdWrappingFancyOpaque {
int testNestedStdNamespacesAndRecords() {
StdWrappingFancyOpaque obj;
int x = obj.o.nested_member; // no-garbage: ctor
int y = obj.uninit; // expected-warning {{Assigned value is garbage or undefined}}
int y = obj.uninit; // expected-warning {{Assigned value is uninitialized}}
return x + y;
}
22 changes: 11 additions & 11 deletions clang/test/Analysis/ctor-array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ struct s {
void a1(void) {
s arr[3];
int x = arr[0].x;
// expected-warning@-1{{Assigned value is garbage or undefined}}
// expected-warning@-1{{Assigned value is uninitialized}}
}

void a2(void) {
s arr[3];
int x = arr[1].x;
// expected-warning@-1{{Assigned value is garbage or undefined}}
// expected-warning@-1{{Assigned value is uninitialized}}
}

void a3(void) {
s arr[3];
int x = arr[2].x;
// expected-warning@-1{{Assigned value is garbage or undefined}}
// expected-warning@-1{{Assigned value is uninitialized}}
}

struct s2 {
Expand All @@ -37,23 +37,23 @@ void b1(void) {

clang_analyzer_eval(arr[0].y == 2); // expected-warning{{TRUE}}
int x = arr[0].x;
// expected-warning@-1{{Assigned value is garbage or undefined}}
// expected-warning@-1{{Assigned value is uninitialized}}
}

void b2(void) {
s2 arr[3];

clang_analyzer_eval(arr[1].y == 2); // expected-warning{{TRUE}}
int x = arr[1].x;
// expected-warning@-1{{Assigned value is garbage or undefined}}
// expected-warning@-1{{Assigned value is uninitialized}}
}

void b3(void) {
s2 arr[3];

clang_analyzer_eval(arr[2].y == 2); // expected-warning{{TRUE}}
int x = arr[2].x;
// expected-warning@-1{{Assigned value is garbage or undefined}}
// expected-warning@-1{{Assigned value is uninitialized}}
}

void c1(void) {
Expand All @@ -70,7 +70,7 @@ void c1(void) {

clang_analyzer_eval(arr[1].y == 2); // expected-warning{{TRUE}}
int x = arr[1].x;
// expected-warning@-1{{Assigned value is garbage or undefined}}
// expected-warning@-1{{Assigned value is uninitialized}}
}
}

Expand Down Expand Up @@ -100,15 +100,15 @@ void e1(void) {
clang_analyzer_eval(arr[1].arr[1].y == 2); // expected-warning{{TRUE}}

int x = arr[1].sarr[1].x;
// expected-warning@-1{{Assigned value is garbage or undefined}}
// expected-warning@-1{{Assigned value is uninitialized}}
}

void f1(void) {
s2 arr[2][2];

clang_analyzer_eval(arr[1][1].y == 2); // expected-warning{{TRUE}}
int x = arr[1][1].x;
// expected-warning@-1{{Assigned value is garbage or undefined}}
// expected-warning@-1{{Assigned value is uninitialized}}
}

struct s5 {
Expand Down Expand Up @@ -168,14 +168,14 @@ void h2(void) {
s a[2][2], b[2][2];

int x = a[1][1].x;
// expected-warning@-1{{Assigned value is garbage or undefined}}
// expected-warning@-1{{Assigned value is uninitialized}}
}

void h3(void) {
s a[2][2], b[2][2];

int x = b[1][1].y;
// expected-warning@-1{{Assigned value is garbage or undefined}}
// expected-warning@-1{{Assigned value is uninitialized}}
}

struct Base {
Expand Down
16 changes: 8 additions & 8 deletions clang/test/Analysis/ctor.mm
Original file line number Diff line number Diff line change
Expand Up @@ -145,24 +145,24 @@ void test() {

NonPOD() {}
NonPOD(const NonPOD &Other)
: x(Other.x), y(Other.y) // expected-warning {{undefined}}
: x(Other.x), y(Other.y) // expected-warning {{uninitialized}}
{
}
NonPOD(NonPOD &&Other)
: x(Other.x), y(Other.y) // expected-warning {{undefined}}
: x(Other.x), y(Other.y) // expected-warning {{uninitialized}}
{
}

NonPOD &operator=(const NonPOD &Other)
{
x = Other.x;
y = Other.y; // expected-warning {{undefined}}
y = Other.y; // expected-warning {{uninitialized}}
return *this;
}
NonPOD &operator=(NonPOD &&Other)
{
x = Other.x;
y = Other.y; // expected-warning {{undefined}}
y = Other.y; // expected-warning {{uninitialized}}
return *this;
}
};
Expand All @@ -175,23 +175,23 @@ void test() {

Inner() {}
Inner(const Inner &Other)
: x(Other.x), y(Other.y) // expected-warning {{undefined}}
: x(Other.x), y(Other.y) // expected-warning {{uninitialized}}
{
}
Inner(Inner &&Other)
: x(Other.x), y(Other.y) // expected-warning {{undefined}}
: x(Other.x), y(Other.y) // expected-warning {{uninitialized}}
{
}

Inner &operator=(const Inner &Other)
{
x = Other.x; // expected-warning {{undefined}}
x = Other.x; // expected-warning {{uninitialized}}
y = Other.y;
return *this;
}
Inner &operator=(Inner &&Other)
{
x = Other.x; // expected-warning {{undefined}}
x = Other.x; // expected-warning {{uninitialized}}
y = Other.y;
return *this;
}
Expand Down
4 changes: 2 additions & 2 deletions clang/test/Analysis/diagnostics/no-store-func-path-notes.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ int initFromBlock(void) {
int p; // expected-note{{'p' declared without an initial value}}
initializer1(&p, 0); // expected-note{{Calling 'initializer1'}}
// expected-note@-1{{Returning from 'initializer1'}}
z = p; // expected-warning{{Assigned value is garbage or undefined}}
// expected-note@-1{{Assigned value is garbage or undefined}}
z = p; // expected-warning{{Assigned value is uninitialized}}
// expected-note@-1{{Assigned value is uninitialized}}
}();
return z;
}
Expand Down
20 changes: 10 additions & 10 deletions clang/test/Analysis/fread.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ void random_access_read1(int index) {
case 0:
// c[0] is not mutated by fread.
if (success) {
char p = c[0]; // expected-warning {{Assigned value is garbage or undefined}} We kept the first byte intact.
char p = c[0]; // expected-warning {{Assigned value is uninitialized}} We kept the first byte intact.
} else {
char p = c[0]; // expected-warning {{Assigned value is garbage or undefined}} We kept the first byte intact.
char p = c[0]; // expected-warning {{Assigned value is uninitialized}} We kept the first byte intact.
}
break;

Expand Down Expand Up @@ -147,9 +147,9 @@ void random_access_read1(int index) {
case 3:
// c[3] is not mutated by fread.
if (success) {
long p = c[3]; // expected-warning {{Assigned value is garbage or undefined}}
long p = c[3]; // expected-warning {{Assigned value is uninitialized}}
} else {
long p = c[3]; // expected-warning {{Assigned value is garbage or undefined}}
long p = c[3]; // expected-warning {{Assigned value is uninitialized}}
}
break;
}
Expand All @@ -169,10 +169,10 @@ void random_access_read2(int b) {
clang_analyzer_isTainted(p); // expected-warning {{YES}}
clang_analyzer_dump(p); // expected-warning {{conj_}}
} else {
int p = buffer[0]; // expected-warning {{Assigned value is garbage or undefined}}
int p = buffer[0]; // expected-warning {{Assigned value is uninitialized}}
}
} else {
int p = buffer[0]; // expected-warning {{Assigned value is garbage or undefined}}
int p = buffer[0]; // expected-warning {{Assigned value is uninitialized}}
}
fclose(fp);
}
Expand Down Expand Up @@ -283,9 +283,9 @@ void compound_read2(void) {
if (fp) {
struct S s; // s.a is not touched by fread.
if (1 == fread(&s.b, sizeof(s.b), 1, fp)) {
long p = s.a; // expected-warning {{Assigned value is garbage or undefined}}
long p = s.a; // expected-warning {{Assigned value is uninitialized}}
} else {
long p = s.a; // expected-warning {{Assigned value is garbage or undefined}}
long p = s.a; // expected-warning {{Assigned value is uninitialized}}
}
fclose(fp);
}
Expand All @@ -296,9 +296,9 @@ void var_read(void) {
if (fp) {
int a, b; // 'a' is not touched by fread.
if (1 == fread(&b, sizeof(b), 1, fp)) {
long p = a; // expected-warning{{Assigned value is garbage or undefined}}
long p = a; // expected-warning{{Assigned value is uninitialized}}
} else {
long p = a; // expected-warning{{Assigned value is garbage or undefined}}
long p = a; // expected-warning{{Assigned value is uninitialized}}
}
fclose(fp);
}
Expand Down
Loading