[PATCH] D52730: [analyzer] ConversionChecker: handle floating point
DonĂ¡t Nagy via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 18 08:41:02 PDT 2018
donat.nagy added inline comments.
================
Comment at: lib/StaticAnalyzer/Checkers/ConversionChecker.cpp:164
+ // double and possibly long double on some systems
+ RepresentsUntilExp = 53; break;
+ case 32:
----------------
xazax.hun wrote:
> A link to the source of these number would be useful. How are these calculated. Also, as far as I know the current C++ standard does not require anything about how floating points are represented in an implementation. So it would be great to somehow refer to the representation used by clang rather than hardcoding these values. (Note that I am perfectly fine with warning for implementation defined behavior as the original version also warn for such in case of integers.)
I took these magic numbers from the IEEE 754 standard; I completely agree that their introduction is far from being elegant.
Unfortunately it seems that referring to the representation used by clang seems to be somewhat difficult, see e.g. this old [[ https://stackoverflow.com/questions/13780931/how-do-i-get-llvm-types-from-clang | stackoverflow answer ]]. In the Z3 solver a similar problem was solved by defining a static function ([[ https://clang.llvm.org/doxygen/Z3ConstraintManager_8cpp_source.html#l00269 | getFloatSemantics() ]]) which uses a switch to translate the bit width of a floating point type into an llvm::fltSemantics value (which contains the precision value as a field).
I could imagine three solutions:
- reimplementing the logic getFloatSemantics,
- moving getFloatSemantics to some utility library and using it from there,
- keeping the current code, with comments describing my assumptions and referencing the IEEE standard.
Which of these is the best?
Note: According to the documentation [[ https://releases.llvm.org/2.5/docs/LangRef.html#t_floating | the floating point types ]] supported by the LLVM IR are just float, double and some high precision extension types (which are handled by the `default:` branch of my code). Unfortunately, I do not know what happens to the [[ https://clang.llvm.org/docs/LanguageExtensions.html#half-precision-floating-point | `_Float16` ]] half-width float type.
Repository:
rC Clang
https://reviews.llvm.org/D52730
More information about the cfe-commits
mailing list