[PATCH] D64666: [Sema] Enable -Wimplicit-float-conversion for integral to floating point precision loss

Ziang Wan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 12 15:04:33 PDT 2019


ziangwan marked 6 inline comments as done.
ziangwan added inline comments.


================
Comment at: clang/include/clang/Basic/DiagnosticSemaKinds.td:3245
+def warn_impcast_integer_float_precision : Warning<
+  "implicit conversion from %0 to %1 may loses integer precision">,
+  InGroup<ImplicitFloatConversion>, DefaultIgnore;
----------------
nickdesaulniers wrote:
> `may lose` or just `loses`.
"may lose". Whether the precision loss really happens depends on the value of i (how many precision bits i has).

For example, `float e = i` where i is an integer. If i is 15 then there isn't precision loss. If i is 222222222, then there is precision loss.


================
Comment at: clang/lib/Sema/SemaChecking.cpp:11417
+    llvm::APFloat SourceToFloatValue(
+      S.Context.getFloatTypeSemantics(QualType(TargetBT, 0)));
+
----------------
nickdesaulniers wrote:
> should this use `SourceBT` rather than `TargetBT`?
Should be `TargetBT`. I've updated the naming convention to make it more clear.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64666/new/

https://reviews.llvm.org/D64666





More information about the cfe-commits mailing list