// when TransferFunctions visits it. A compound-assignment does not affect
// whether a variable is uninitialized, and there's no point counting it as a
// use.
- if (BO->isAssignmentOp())
+ if (BO->isCompoundAssignmentOp())
+ classify(BO->getLHS(), Use);
+ else if (BO->getOpcode() == BO_Assign)
classify(BO->getLHS(), Ignore);
}
else {
AC.getCFGBuildOptions()
.setAlwaysAdd(Stmt::BinaryOperatorClass)
+ .setAlwaysAdd(Stmt::CompoundAssignOperatorClass)
.setAlwaysAdd(Stmt::BlockExprClass)
.setAlwaysAdd(Stmt::CStyleCastExprClass)
.setAlwaysAdd(Stmt::DeclRefExprClass)
int test6() {
int x; // expected-note{{initialize the variable 'x' to silence this warning}}
- x += 2;
- return x; // expected-warning{{variable 'x' is uninitialized when used here}}
+ x += 2; // expected-warning{{variable 'x' is uninitialized when used here}}
+ return x;
}
int test7(int y) {
int compound_assign(int *arr, int n) {
int sum; // expected-note {{initialize}}
for (int i = 0; i < n; ++i)
- sum += arr[i];
- return sum / n; // expected-warning {{variable 'sum' is uninitialized}}
+ sum += arr[i]; // expected-warning {{variable 'sum' is uninitialized}}
+ return sum / n;
}
-void compound_assign_2(int n) {
- volatile int ignore;
- for (int j = 0; j < n; ++j)
- ignore += test1(); // ok
+int compound_assign_2() {
+ int x; // expected-note {{initialize}}
+ return x += 1; // expected-warning {{variable 'x' is uninitialized}}
+}
+
+int compound_assign_3() {
+ int x; // expected-note {{initialize}}
+ x *= 0; // expected-warning {{variable 'x' is uninitialized}}
+ return x;
}