[cfe-commits] r108590 - in /cfe/trunk: lib/Checker/IdempotentOperationChecker.cpp test/Analysis/idempotent-operations.c

Ted Kremenek kremenek at apple.com
Fri Jul 16 17:40:32 PDT 2010


Author: kremenek
Date: Fri Jul 16 19:40:32 2010
New Revision: 108590

URL: http://llvm.org/viewvc/llvm-project?rev=108590&view=rev
Log:
Fix APFloat assertion failure in IdempotentOperationChecker resulting in having
an APFloat with different "float semantics" than the compared float literal.

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=108590&r1=108589&r2=108590&view=diff
==============================================================================
--- cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp (original)
+++ cfe/trunk/lib/Checker/IdempotentOperationChecker.cpp Fri Jul 16 19:40:32 2010
@@ -515,10 +515,12 @@
   if (IL && IL->getValue() == 1)
     return true;
 
-  const FloatingLiteral *FL = dyn_cast<FloatingLiteral>(S);
-  const llvm::APFloat one(1.0);
-  if (FL && FL->getValue().compare(one) == llvm::APFloat::cmpEqual)
-    return true;
+  if (const FloatingLiteral *FL = dyn_cast<FloatingLiteral>(S)) {
+    const llvm::APFloat &val = FL->getValue();
+    const llvm::APFloat one(val.getSemantics(), 1);
+    if (val.compare(one) == llvm::APFloat::cmpEqual)
+      return true;
+  }
 
   for (Stmt::const_child_iterator I = S->child_begin(); I != S->child_end();
       ++I)

Modified: cfe/trunk/test/Analysis/idempotent-operations.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/idempotent-operations.c?rev=108590&r1=108589&r2=108590&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/idempotent-operations.c (original)
+++ cfe/trunk/test/Analysis/idempotent-operations.c Fri Jul 16 19:40:32 2010
@@ -3,6 +3,7 @@
 // Basic tests
 
 extern void test(int i);
+extern void test_f(float f);
 
 void basic() {
   int x = 10, zero = 0, one = 1;
@@ -50,3 +51,8 @@
   test(zero << x); // expected-warning {{idempotent operation; the left operand is always 0}}
   test(zero >> x); // expected-warning {{idempotent operation; the left operand is always 0}}
 }
+
+void floats(float x) {
+  test_f(x * 1.0); // no-warning
+  test_f(x * 1.0F); // no-warning
+}





More information about the cfe-commits mailing list