]> granicus.if.org Git - clang/commitdiff
Fix APFloat assertion failure in IdempotentOperationChecker resulting in having
authorTed Kremenek <kremenek@apple.com>
Sat, 17 Jul 2010 00:40:32 +0000 (00:40 +0000)
committerTed Kremenek <kremenek@apple.com>
Sat, 17 Jul 2010 00:40:32 +0000 (00:40 +0000)
an APFloat with different "float semantics" than the compared float literal.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108590 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 744fe2ba99290406c363cfd63f3ef5ad3d9bd46b..48b5a597caf6b1c19331505e39180dff20328305 100644 (file)
@@ -515,10 +515,12 @@ bool IdempotentOperationChecker::containsOneConstant(const Stmt *S) {
   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)
index 72adb8ef25cfc67ef4513412287330a04911d309..94e972c5519c80d7f7d18138cfb4ef2adddbf855 100644 (file)
@@ -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 @@ void basic() {
   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
+}