Skip to content

Commit 06eb668

Browse files
committed
[analyzer] Update undefined assignment diagnostics to not use 'garbage'
A clang user pointed out that messages for the static analyzer undefined assignment checker use the term 'garbage'. This is kind of snarky and also imprecise. This change replaces the term 'garbage' in those messages with 'not meaningful'. It moves the term 'undefined' to be first in the messages because of the possible ambiguous parsing of the term 'not meaningful and undefined'. That could be parsed as '(not meaningful) and undefined' or 'not (meaningful and undefined'). The use of the term 'meaningless' was considered, but not chosen because it has two meanings in English. One meaning is 'without meaning'. The other meaning is 'having no point'. The 2nd meaning could be construed as indicating the computation could be deleted. rdar://133418644
1 parent d7fd2a2 commit 06eb668

25 files changed

+125
-124
lines changed

clang/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ using namespace ento;
2323
namespace {
2424
class UndefinedAssignmentChecker
2525
: public Checker<check::Bind> {
26-
const BugType BT{this, "Assigned value is garbage or undefined"};
26+
const BugType BT{this, "Assigned value is undefined and not meaningful"};
2727

2828
public:
2929
void checkBind(SVal location, SVal val, const Stmt *S,
@@ -57,8 +57,8 @@ void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
5757

5858
while (StoreE) {
5959
if (const UnaryOperator *U = dyn_cast<UnaryOperator>(StoreE)) {
60-
OS << "The expression is an uninitialized value. "
61-
"The computed value will also be garbage";
60+
OS << "The expression is an uninitialized value, so the computed value "
61+
<< "is not meaningful";
6262

6363
ex = U->getSubExpr();
6464
break;
@@ -68,7 +68,7 @@ void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
6868
if (B->isCompoundAssignmentOp()) {
6969
if (C.getSVal(B->getLHS()).isUndef()) {
7070
OS << "The left expression of the compound assignment is an "
71-
"uninitialized value. The computed value will also be garbage";
71+
<< "uninitialized value, so the computed value is not meaningful";
7272
ex = B->getLHS();
7373
break;
7474
}
@@ -88,8 +88,9 @@ void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
8888
if (CD->isImplicit()) {
8989
for (auto *I : CD->inits()) {
9090
if (I->getInit()->IgnoreImpCasts() == StoreE) {
91-
OS << "Value assigned to field '" << I->getMember()->getName()
92-
<< "' in implicit constructor is garbage or undefined";
91+
OS << "Value assigned to field '"
92+
<< I->getMember()->getName()
93+
<< "' in implicit constructor is undefined and not meaningful.";
9394
break;
9495
}
9596
}

clang/test/Analysis/Inputs/expected-plists/edges-new.mm.plist

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,17 +2578,17 @@
25782578
</array>
25792579
<key>depth</key><integer>0</integer>
25802580
<key>extended_message</key>
2581-
<string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
2581+
<string>The left expression of the compound assignment is an uninitialized value, so the computed value is not meaningful</string>
25822582
<key>message</key>
2583-
<string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
2583+
<string>The left expression of the compound assignment is an uninitialized value, so the computed value is not meaningful</string>
25842584
</dict>
25852585
</array>
2586-
<key>description</key><string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
2586+
<key>description</key><string>The left expression of the compound assignment is an uninitialized value, so the computed value is not meaningful</string>
25872587
<key>category</key><string>Logic error</string>
2588-
<key>type</key><string>Assigned value is garbage or undefined</string>
2588+
<key>type</key><string>Assigned value is undefined and not meaningful</string>
25892589
<key>check_name</key><string>core.uninitialized.Assign</string>
25902590
<!-- This hash is experimental and going to change! -->
2591-
<key>issue_hash_content_of_line_in_context</key><string>025372576cd3ba6716044f93a51c978c</string>
2591+
<key>issue_hash_content_of_line_in_context</key><string>936a5fabf36091d0c1e1e1553232d6f5</string>
25922592
<key>issue_context_kind</key><string>function</string>
25932593
<key>issue_context</key><string>test_objc_fast_enumeration_2</string>
25942594
<key>issue_hash_function_offset</key><string>5</string>

clang/test/Analysis/Inputs/expected-plists/plist-output.m.plist

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5864,17 +5864,17 @@
58645864
</array>
58655865
<key>depth</key><integer>0</integer>
58665866
<key>extended_message</key>
5867-
<string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
5867+
<string>The left expression of the compound assignment is an uninitialized value, so the computed value is not meaningful</string>
58685868
<key>message</key>
5869-
<string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
5869+
<string>The left expression of the compound assignment is an uninitialized value, so the computed value is not meaningful</string>
58705870
</dict>
58715871
</array>
5872-
<key>description</key><string>The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage</string>
5872+
<key>description</key><string>The left expression of the compound assignment is an uninitialized value, so the computed value is not meaningful</string>
58735873
<key>category</key><string>Logic error</string>
5874-
<key>type</key><string>Assigned value is garbage or undefined</string>
5874+
<key>type</key><string>Assigned value is undefined and not meaningful</string>
58755875
<key>check_name</key><string>core.uninitialized.Assign</string>
58765876
<!-- This hash is experimental and going to change! -->
5877-
<key>issue_hash_content_of_line_in_context</key><string>21c774309bdfd487c3d09a61a671bbcc</string>
5877+
<key>issue_hash_content_of_line_in_context</key><string>c1d7b1284317d7e45bda4bfa6b3a281e</string>
58785878
<key>issue_context_kind</key><string>function</string>
58795879
<key>issue_context</key><string>test_loop_fast_enumeration</string>
58805880
<key>issue_hash_function_offset</key><string>5</string>

clang/test/Analysis/a_flaky_crash.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bool bar(S);
1414
void foo() {
1515
int x;
1616
if (true && bar(S()))
17-
++x; // expected-warning{{The expression is an uninitialized value. The computed value will also be garbage}}
17+
++x; // expected-warning{{The expression is an uninitialized value, so the computed value is not meaningful}}
1818
}
1919

2020
// 256 copies of the same run-line to make it crash more often when it breaks.

clang/test/Analysis/analysis-after-multiple-dtors.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ int main() {
2323

2424
int x;
2525
int y = x;
26-
// expected-warning@-1{{Assigned value is garbage or undefined}}
26+
// expected-warning@-1{{Assigned value is undefined and not meaningful}}
2727
(void)y;
2828
}

clang/test/Analysis/array-init-loop.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void array_uninit() {
1919

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

22-
int x = e; // expected-warning{{Assigned value is garbage or undefined}}
22+
int x = e; // expected-warning{{Assigned value is undefined and not meaningful}}
2323
}
2424

2525
void lambda_init() {
@@ -168,7 +168,7 @@ struct S3_duplicate {
168168
void array_uninit_non_pod() {
169169
S3 arr[1];
170170

171-
auto [a] = arr; // expected-warning@159{{ in implicit constructor is garbage or undefined }}
171+
auto [a] = arr; // expected-warning@159{{ in implicit constructor is undefined and not meaningful}}
172172
}
173173

174174
void lambda_init_non_pod() {
@@ -191,7 +191,7 @@ void lambda_init_non_pod() {
191191
void lambda_uninit_non_pod() {
192192
S3_duplicate arr[4];
193193

194-
int l = [arr] { return arr[3].i; }(); // expected-warning@164{{ in implicit constructor is garbage or undefined }}
194+
int l = [arr] { return arr[3].i; }(); // expected-warning@164{{ in implicit constructor is undefined and not meaningful }}
195195
}
196196

197197
// If this struct is being copy/move constructed by the implicit ctors, ArrayInitLoopExpr

clang/test/Analysis/array-punned-region.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void array_struct_bitfield_1() {
2020
int array_struct_bitfield_2() {
2121
BITFIELD_CAST ff = {0};
2222
BITFIELD_CAST *pff = &ff;
23-
int a = *((int *)pff + 2); // expected-warning{{Assigned value is garbage or undefined [core.uninitialized.Assign]}}
23+
int a = *((int *)pff + 2); // expected-warning{{Assigned value is undefined and not meaningful [core.uninitialized.Assign]}}
2424
return a;
2525
}
2626

clang/test/Analysis/builtin_overflow_notes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ void test_overflow_note(int a, int b)
2323

2424
if (__builtin_add_overflow(a, b, &res)) { // expected-note {{Assuming overflow}}
2525
// 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}}
26+
int var = res; // expected-warning{{Assigned value is undefined and not meaningful}}
27+
// expected-note@-1 {{Assigned value is undefined and not meaningful}}
2828
return;
2929
}
3030
}

clang/test/Analysis/call-invalidation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ int testStdCtorDoesNotInvalidateParentObject() {
197197
int testStdCtorDoesNotInvalidateParentObjectSwapped() {
198198
StdWrappingOpaqueSwapped obj;
199199
int x = obj.o.nested_member; // no-garbage: std::Opaque::ctor might initialized this
200-
int y = obj.uninit; // expected-warning {{Assigned value is garbage or undefined}}
200+
int y = obj.uninit; // expected-warning {{Assigned value is undefined and not meaningful}}
201201
return x + y;
202202
}
203203

@@ -277,6 +277,6 @@ struct StdWrappingFancyOpaque {
277277
int testNestedStdNamespacesAndRecords() {
278278
StdWrappingFancyOpaque obj;
279279
int x = obj.o.nested_member; // no-garbage: ctor
280-
int y = obj.uninit; // expected-warning {{Assigned value is garbage or undefined}}
280+
int y = obj.uninit; // expected-warning {{Assigned value is undefined and not meaningful}}
281281
return x + y;
282282
}

clang/test/Analysis/ctor-array.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ struct s {
1212
void a1(void) {
1313
s arr[3];
1414
int x = arr[0].x;
15-
// expected-warning@-1{{Assigned value is garbage or undefined}}
15+
// expected-warning@-1{{Assigned value is undefined and not meaningful}}
1616
}
1717

1818
void a2(void) {
1919
s arr[3];
2020
int x = arr[1].x;
21-
// expected-warning@-1{{Assigned value is garbage or undefined}}
21+
// expected-warning@-1{{Assigned value is undefined and not meaningful}}
2222
}
2323

2424
void a3(void) {
2525
s arr[3];
2626
int x = arr[2].x;
27-
// expected-warning@-1{{Assigned value is garbage or undefined}}
27+
// expected-warning@-1{{Assigned value is undefined and not meaningful}}
2828
}
2929

3030
struct s2 {
@@ -37,23 +37,23 @@ void b1(void) {
3737

3838
clang_analyzer_eval(arr[0].y == 2); // expected-warning{{TRUE}}
3939
int x = arr[0].x;
40-
// expected-warning@-1{{Assigned value is garbage or undefined}}
40+
// expected-warning@-1{{Assigned value is undefined and not meaningful}}
4141
}
4242

4343
void b2(void) {
4444
s2 arr[3];
4545

4646
clang_analyzer_eval(arr[1].y == 2); // expected-warning{{TRUE}}
4747
int x = arr[1].x;
48-
// expected-warning@-1{{Assigned value is garbage or undefined}}
48+
// expected-warning@-1{{Assigned value is undefined and not meaningful}}
4949
}
5050

5151
void b3(void) {
5252
s2 arr[3];
5353

5454
clang_analyzer_eval(arr[2].y == 2); // expected-warning{{TRUE}}
5555
int x = arr[2].x;
56-
// expected-warning@-1{{Assigned value is garbage or undefined}}
56+
// expected-warning@-1{{Assigned value is undefined and not meaningful}}
5757
}
5858

5959
void c1(void) {
@@ -70,7 +70,7 @@ void c1(void) {
7070

7171
clang_analyzer_eval(arr[1].y == 2); // expected-warning{{TRUE}}
7272
int x = arr[1].x;
73-
// expected-warning@-1{{Assigned value is garbage or undefined}}
73+
// expected-warning@-1{{Assigned value is undefined and not meaningful}}
7474
}
7575
}
7676

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

102102
int x = arr[1].sarr[1].x;
103-
// expected-warning@-1{{Assigned value is garbage or undefined}}
103+
// expected-warning@-1{{Assigned value is undefined and not meaningful}}
104104
}
105105

106106
void f1(void) {
107107
s2 arr[2][2];
108108

109109
clang_analyzer_eval(arr[1][1].y == 2); // expected-warning{{TRUE}}
110110
int x = arr[1][1].x;
111-
// expected-warning@-1{{Assigned value is garbage or undefined}}
111+
// expected-warning@-1{{Assigned value is undefined and not meaningful}}
112112
}
113113

114114
struct s5 {
@@ -168,14 +168,14 @@ void h2(void) {
168168
s a[2][2], b[2][2];
169169

170170
int x = a[1][1].x;
171-
// expected-warning@-1{{Assigned value is garbage or undefined}}
171+
// expected-warning@-1{{Assigned value is undefined and not meaningful}}
172172
}
173173

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

177177
int x = b[1][1].y;
178-
// expected-warning@-1{{Assigned value is garbage or undefined}}
178+
// expected-warning@-1{{Assigned value is undefined and not meaningful}}
179179
}
180180

181181
struct Base {

0 commit comments

Comments
 (0)