[cfe-commits] r99221 - in /cfe/trunk: lib/Checker/UndefinedAssignmentChecker.cpp test/Analysis/uninit-vals-ps-region.m
Ted Kremenek
kremenek at apple.com
Mon Mar 22 15:16:26 PDT 2010
Author: kremenek
Date: Mon Mar 22 17:16:26 2010
New Revision: 99221
URL: http://llvm.org/viewvc/llvm-project?rev=99221&view=rev
Log:
Improve the diagnostics for the UndefinedAssignmentChecker when an
uninitialized value is used in the LHS of a compound assignment.
Modified:
cfe/trunk/lib/Checker/UndefinedAssignmentChecker.cpp
cfe/trunk/test/Analysis/uninit-vals-ps-region.m
Modified: cfe/trunk/lib/Checker/UndefinedAssignmentChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/UndefinedAssignmentChecker.cpp?rev=99221&r1=99220&r2=99221&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/UndefinedAssignmentChecker.cpp (original)
+++ cfe/trunk/lib/Checker/UndefinedAssignmentChecker.cpp Mon Mar 22 17:16:26 2010
@@ -53,27 +53,43 @@
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);
-}
+}
Modified: cfe/trunk/test/Analysis/uninit-vals-ps-region.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/uninit-vals-ps-region.m?rev=99221&r1=99220&r2=99221&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/uninit-vals-ps-region.m (original)
+++ cfe/trunk/test/Analysis/uninit-vals-ps-region.m Mon Mar 22 17:16:26 2010
@@ -59,4 +59,11 @@
[o passVal:x]; // expected-warning{{Passed-by-value struct argument contains uninitialized data (e.g., field: 'x')}}
}
+// Test case from <rdar://problem/7780304>. That shows an uninitialized value
+// being used in the LHS of a compound assignment.
+void rdar_7780304() {
+ typedef struct s_r7780304 { int x; } s_r7780304;
+ s_r7780304 b;
+ b.x |= 1; // expected-warning{{The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage}}
+}
More information about the cfe-commits
mailing list