Skip to content

Commit 8138d85

Browse files
authored
[analyzer] Update the undefined assignment checker diagnostics to not use the term 'garbage' (#126596)
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
1 parent a005861 commit 8138d85

30 files changed

+139
-140
lines changed

clang/lib/StaticAnalyzer/Checkers/UndefinedAssignmentChecker.cpp

Lines changed: 5 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 uninitialized"};
2727

2828
public:
2929
void checkBind(SVal location, SVal val, const Stmt *S,
@@ -57,8 +57,7 @@ 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 uses uninitialized memory";
6261

6362
ex = U->getSubExpr();
6463
break;
@@ -67,8 +66,8 @@ void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
6766
if (const BinaryOperator *B = dyn_cast<BinaryOperator>(StoreE)) {
6867
if (B->isCompoundAssignmentOp()) {
6968
if (C.getSVal(B->getLHS()).isUndef()) {
70-
OS << "The left expression of the compound assignment is an "
71-
"uninitialized value. The computed value will also be garbage";
69+
OS << "The left expression of the compound assignment uses "
70+
<< "uninitialized memory";
7271
ex = B->getLHS();
7372
break;
7473
}
@@ -89,7 +88,7 @@ void UndefinedAssignmentChecker::checkBind(SVal location, SVal val,
8988
for (auto *I : CD->inits()) {
9089
if (I->getInit()->IgnoreImpCasts() == StoreE) {
9190
OS << "Value assigned to field '" << I->getMember()->getName()
92-
<< "' in implicit constructor is garbage or undefined";
91+
<< "' in implicit constructor is uninitialized";
9392
break;
9493
}
9594
}

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 uses uninitialized memory</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 uses uninitialized memory</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 uses uninitialized memory</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 uninitialized</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>324827600c298776167cd9562f71bda6</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 uses uninitialized memory</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 uses uninitialized memory</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 uses uninitialized memory</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 uninitialized</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>faa8858031ed123ff98cc23cf14d462f</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 uses uninitialized memory}}
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 uninitialized}}
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 uninitialized}}
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 uninitialized}}
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 uninitialized }}
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 uninitialized [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 uninitialized}}
27+
// expected-note@-1 {{Assigned value is uninitialized}}
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 uninitialized}}
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 uninitialized}}
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 uninitialized}}
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 uninitialized}}
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 uninitialized}}
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 uninitialized}}
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 uninitialized}}
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 uninitialized}}
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 uninitialized}}
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 uninitialized}}
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 uninitialized}}
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 uninitialized}}
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 uninitialized}}
179179
}
180180

181181
struct Base {

clang/test/Analysis/ctor.mm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,24 @@ void test() {
145145

146146
NonPOD() {}
147147
NonPOD(const NonPOD &Other)
148-
: x(Other.x), y(Other.y) // expected-warning {{undefined}}
148+
: x(Other.x), y(Other.y) // expected-warning {{uninitialized}}
149149
{
150150
}
151151
NonPOD(NonPOD &&Other)
152-
: x(Other.x), y(Other.y) // expected-warning {{undefined}}
152+
: x(Other.x), y(Other.y) // expected-warning {{uninitialized}}
153153
{
154154
}
155155

156156
NonPOD &operator=(const NonPOD &Other)
157157
{
158158
x = Other.x;
159-
y = Other.y; // expected-warning {{undefined}}
159+
y = Other.y; // expected-warning {{uninitialized}}
160160
return *this;
161161
}
162162
NonPOD &operator=(NonPOD &&Other)
163163
{
164164
x = Other.x;
165-
y = Other.y; // expected-warning {{undefined}}
165+
y = Other.y; // expected-warning {{uninitialized}}
166166
return *this;
167167
}
168168
};
@@ -175,23 +175,23 @@ void test() {
175175

176176
Inner() {}
177177
Inner(const Inner &Other)
178-
: x(Other.x), y(Other.y) // expected-warning {{undefined}}
178+
: x(Other.x), y(Other.y) // expected-warning {{uninitialized}}
179179
{
180180
}
181181
Inner(Inner &&Other)
182-
: x(Other.x), y(Other.y) // expected-warning {{undefined}}
182+
: x(Other.x), y(Other.y) // expected-warning {{uninitialized}}
183183
{
184184
}
185185

186186
Inner &operator=(const Inner &Other)
187187
{
188-
x = Other.x; // expected-warning {{undefined}}
188+
x = Other.x; // expected-warning {{uninitialized}}
189189
y = Other.y;
190190
return *this;
191191
}
192192
Inner &operator=(Inner &&Other)
193193
{
194-
x = Other.x; // expected-warning {{undefined}}
194+
x = Other.x; // expected-warning {{uninitialized}}
195195
y = Other.y;
196196
return *this;
197197
}

clang/test/Analysis/diagnostics/no-store-func-path-notes.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ int initFromBlock(void) {
4747
int p; // expected-note{{'p' declared without an initial value}}
4848
initializer1(&p, 0); // expected-note{{Calling 'initializer1'}}
4949
// expected-note@-1{{Returning from 'initializer1'}}
50-
z = p; // expected-warning{{Assigned value is garbage or undefined}}
51-
// expected-note@-1{{Assigned value is garbage or undefined}}
50+
z = p; // expected-warning{{Assigned value is uninitialized}}
51+
// expected-note@-1{{Assigned value is uninitialized}}
5252
}();
5353
return z;
5454
}

clang/test/Analysis/fread.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ void random_access_read1(int index) {
113113
case 0:
114114
// c[0] is not mutated by fread.
115115
if (success) {
116-
char p = c[0]; // expected-warning {{Assigned value is garbage or undefined}} We kept the first byte intact.
116+
char p = c[0]; // expected-warning {{Assigned value is uninitialized}} We kept the first byte intact.
117117
} else {
118-
char p = c[0]; // expected-warning {{Assigned value is garbage or undefined}} We kept the first byte intact.
118+
char p = c[0]; // expected-warning {{Assigned value is uninitialized}} We kept the first byte intact.
119119
}
120120
break;
121121

@@ -147,9 +147,9 @@ void random_access_read1(int index) {
147147
case 3:
148148
// c[3] is not mutated by fread.
149149
if (success) {
150-
long p = c[3]; // expected-warning {{Assigned value is garbage or undefined}}
150+
long p = c[3]; // expected-warning {{Assigned value is uninitialized}}
151151
} else {
152-
long p = c[3]; // expected-warning {{Assigned value is garbage or undefined}}
152+
long p = c[3]; // expected-warning {{Assigned value is uninitialized}}
153153
}
154154
break;
155155
}
@@ -169,10 +169,10 @@ void random_access_read2(int b) {
169169
clang_analyzer_isTainted(p); // expected-warning {{YES}}
170170
clang_analyzer_dump(p); // expected-warning {{conj_}}
171171
} else {
172-
int p = buffer[0]; // expected-warning {{Assigned value is garbage or undefined}}
172+
int p = buffer[0]; // expected-warning {{Assigned value is uninitialized}}
173173
}
174174
} else {
175-
int p = buffer[0]; // expected-warning {{Assigned value is garbage or undefined}}
175+
int p = buffer[0]; // expected-warning {{Assigned value is uninitialized}}
176176
}
177177
fclose(fp);
178178
}
@@ -283,9 +283,9 @@ void compound_read2(void) {
283283
if (fp) {
284284
struct S s; // s.a is not touched by fread.
285285
if (1 == fread(&s.b, sizeof(s.b), 1, fp)) {
286-
long p = s.a; // expected-warning {{Assigned value is garbage or undefined}}
286+
long p = s.a; // expected-warning {{Assigned value is uninitialized}}
287287
} else {
288-
long p = s.a; // expected-warning {{Assigned value is garbage or undefined}}
288+
long p = s.a; // expected-warning {{Assigned value is uninitialized}}
289289
}
290290
fclose(fp);
291291
}
@@ -296,9 +296,9 @@ void var_read(void) {
296296
if (fp) {
297297
int a, b; // 'a' is not touched by fread.
298298
if (1 == fread(&b, sizeof(b), 1, fp)) {
299-
long p = a; // expected-warning{{Assigned value is garbage or undefined}}
299+
long p = a; // expected-warning{{Assigned value is uninitialized}}
300300
} else {
301-
long p = a; // expected-warning{{Assigned value is garbage or undefined}}
301+
long p = a; // expected-warning{{Assigned value is uninitialized}}
302302
}
303303
fclose(fp);
304304
}

0 commit comments

Comments
 (0)