[analyzer] Introducing FloatingCompare checker

I’ve started implementing different.FloatingCompare checker from the list of potential checkers. I’d like to gather some feedback and do some improvements in order to push the code to the upstream in the near future.

Vassil Vassilev mentioned it might be reasonable if the checker could detect that there is division which might yield precision loss and then detect a check against a ‘constant’ values.

What do you think? What should be the checker’s default behavior?

The first version of checker is attached.

FloatingCompareChecker.patch (4.88 KB)

Hi Kirill,

The checkPreStmt callback should be used by checkers that require symbolic execution. Check out the video of our talk for introduction into how that works http://llvm.org/devmtg/2012-11/videos/Zaks-Rose-Checker24Hours.mp4. Looks like this checker is only performing a syntactic check, so using an AST visitor would be more appropriate http://clang-analyzer.llvm.org/checker_dev_manual.html#ast.

However, most importantly, similar functionality is already implemented in the compiler (see -Wfloat-equal)! Looks like it does not work when comparing against a constant. I am not sure what the reason for that is; was it a a source of false positives or just an oversight.

Since the warning is in place, we should remove this from the list of checkers to be implemented.

Thank you,

Uh, my bad!

I was checking whether such functionality was already implemented by running analysis on the sample piece of code provided by the checker description in the list, I didn’t see any warning, so I assumed it’s not there.

Thank you very much for the feedback! I’ll pick another item from the list :slight_smile: