]> granicus.if.org Git - clang/commitdiff
Re-enabled truncation/extension checking in IdempotentOperationChecker and added...
authorTom Care <tom.care@uqconnect.edu.au>
Tue, 7 Sep 2010 20:27:56 +0000 (20:27 +0000)
committerTom Care <tom.care@uqconnect.edu.au>
Tue, 7 Sep 2010 20:27:56 +0000 (20:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113269 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Checker/IdempotentOperationChecker.cpp
test/Analysis/idempotent-operations.c

index 6411c790ef7c8f47127be37f9759f519b6b953ba..2e85013a76898e357e38523625664886847b4142 100644 (file)
@@ -78,8 +78,8 @@ class IdempotentOperationChecker
     // 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 @@ void IdempotentOperationChecker::PreVisitBinaryOperator(
   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 @@ bool IdempotentOperationChecker::isUnused(const Expr *E,
   return true;
 }
 
-#if 0
 // Check for self casts truncating/extending a variable
 bool IdempotentOperationChecker::isTruncationExtensionAssignment(
                                                               const Expr *LHS,
@@ -523,7 +523,6 @@ bool IdempotentOperationChecker::isTruncationExtensionAssignment(
 
   return dyn_cast<DeclRefExpr>(RHS->IgnoreParens()) == NULL;
 }
-#endif
 
 // Returns false if a path to this block was not completely analyzed, or true
 // otherwise.
index 5c9a59d736166fd8f2fc2db42f7eb383e47898d3..d88bf49485eef9d28b1d6c92100763a4a611cda7 100644 (file)
@@ -187,3 +187,10 @@ int false7() {
 
   return a;
 }
+
+// Check truncations do not flag as self-assignments
+void false8() {
+  int a = 10000000;
+  a = (short)a; // no-warning
+  test(a);
+}