aboutsummaryrefslogtreecommitdiff
path: root/lib/Checker/UndefinedAssignmentChecker.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2010-03-22 22:16:26 +0000
committerTed Kremenek <kremenek@apple.com>2010-03-22 22:16:26 +0000
commit12182a0344c11970f307bc79eeb102633561b680 (patch)
tree9aa92be6eda93e6d4c8271e079b1c24aae5637da /lib/Checker/UndefinedAssignmentChecker.cpp
parentf6728fcbec62be94469a6e80c7e7e32e3f2c3329 (diff)
Improve the diagnostics for the UndefinedAssignmentChecker when an
uninitialized value is used in the LHS of a compound assignment. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99221 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Checker/UndefinedAssignmentChecker.cpp')
-rw-r--r--lib/Checker/UndefinedAssignmentChecker.cpp38
1 files changed, 27 insertions, 11 deletions
diff --git a/lib/Checker/UndefinedAssignmentChecker.cpp b/lib/Checker/UndefinedAssignmentChecker.cpp
index 7c33c1d392..9f17ef126d 100644
--- a/lib/Checker/UndefinedAssignmentChecker.cpp
+++ b/lib/Checker/UndefinedAssignmentChecker.cpp
@@ -53,27 +53,43 @@ void UndefinedAssignmentChecker::PreVisitBind(CheckerContext &C,
if (!N)
return;
+ const char *str = "Assigned value is garbage or undefined";
+
if (!BT)
- BT = new BuiltinBug("Assigned value is garbage or undefined");
+ BT = new BuiltinBug(str);
// Generate a report for this bug.
- EnhancedBugReport *R = new EnhancedBugReport(*BT, BT->getName(), N);
+ const Expr *ex = 0;
- if (AssignE) {
- const Expr *ex = 0;
+ while (AssignE) {
+ if (const BinaryOperator *B = dyn_cast<BinaryOperator>(AssignE)) {
+ if (B->isCompoundAssignmentOp()) {
+ const GRState *state = C.getState();
+ if (state->getSVal(B->getLHS()).isUndef()) {
+ str = "The left expression of the compound assignment is an "
+ "uninitialized value. The computed value will also be garbage";
+ ex = B->getLHS();
+ break;
+ }
+ }
- if (const BinaryOperator *B = dyn_cast<BinaryOperator>(AssignE))
ex = B->getRHS();
- else if (const DeclStmt *DS = dyn_cast<DeclStmt>(AssignE)) {
+ break;
+ }
+
+ if (const DeclStmt *DS = dyn_cast<DeclStmt>(AssignE)) {
const VarDecl* VD = dyn_cast<VarDecl>(DS->getSingleDecl());
ex = VD->getInit();
}
- if (ex) {
- R->addRange(ex->getSourceRange());
- R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, ex);
- }
+
+ break;
}
+ EnhancedBugReport *R = new EnhancedBugReport(*BT, str, N);
+ if (ex) {
+ R->addRange(ex->getSourceRange());
+ R->addVisitorCreator(bugreporter::registerTrackNullOrUndefValue, ex);
+ }
C.EmitReport(R);
-}
+}