[cfe-commits] r113269 - in /cfe/trunk: lib/Checker/IdempotentOperationChecker.cpp test/Analysis/idempotent-operations.c
Tom Care
tcare at apple.com
Tue Sep 7 13:27:57 PDT 2010
Author: tcare
Date: Tue Sep 7 15:27:56 2010
New Revision: 113269
URL: http://llvm.org/viewvc/llvm-project?rev=113269&view=rev
Log:
Re-enabled truncation/extension checking in IdempotentOperationChecker and added a test case.
Modified:
cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp
cfe/trunk/test/Analysis/idempotent-operations.c
Modified: cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp?rev=113269&r1=113268&r2=113269&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp (original)
+++ cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp Tue Sep 7 15:27:56 2010
@@ -78,8 +78,8 @@
// False positive reduction methods
static bool isSelfAssign(const Expr *LHS, const Expr *RHS);
static bool isUnused(const Expr *E, AnalysisContext *AC);
- //static bool isTruncationExtensionAssignment(const Expr *LHS,
- // const Expr *RHS);
+ static bool isTruncationExtensionAssignment(const Expr *LHS,
+ const Expr *RHS);
static bool PathWasCompletelyAnalyzed(const CFG *C,
const CFGBlock *CB,
const GRCoreEngine &CE);
@@ -196,9 +196,10 @@
case BO_Assign:
// x Assign x can be used to silence unused variable warnings intentionally.
// If this is a self assignment and the variable is referenced elsewhere,
- // then it is a false positive.
+ // and the assignment is not a truncation or extension, then it is a false
+ // positive.
if (isSelfAssign(LHS, RHS)) {
- if (!isUnused(LHS, AC)) {
+ if (!isUnused(LHS, AC) && !isTruncationExtensionAssignment(LHS, RHS)) {
UpdateAssumption(A, Equal);
return;
}
@@ -500,7 +501,6 @@
return true;
}
-#if 0
// Check for self casts truncating/extending a variable
bool IdempotentOperationChecker::isTruncationExtensionAssignment(
const Expr *LHS,
@@ -523,7 +523,6 @@
return dyn_cast<DeclRefExpr>(RHS->IgnoreParens()) == NULL;
}
-#endif
// Returns false if a path to this block was not completely analyzed, or true
// otherwise.
Modified: cfe/trunk/test/Analysis/idempotent-operations.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/idempotent-operations.c?rev=113269&r1=113268&r2=113269&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/idempotent-operations.c (original)
+++ cfe/trunk/test/Analysis/idempotent-operations.c Tue Sep 7 15:27:56 2010
@@ -187,3 +187,10 @@
return a;
}
+
+// Check truncations do not flag as self-assignments
+void false8() {
+ int a = 10000000;
+ a = (short)a; // no-warning
+ test(a);
+}
More information about the cfe-commits
mailing list