[PATCH] D147906: [clang-tidy] Avoid float compare in bugprone-incorrect-roundings
Piotr Zegar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 10 08:07:02 PDT 2023
PiotrZSL updated this revision to Diff 512149.
PiotrZSL added a comment.
Fix review comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D147906/new/
https://reviews.llvm.org/D147906
Files:
clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
Index: clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/IncorrectRoundingsCheck.cpp
@@ -17,13 +17,17 @@
namespace clang::tidy::bugprone {
+static llvm::APFloat getHalf(const llvm::fltSemantics &Semantics) {
+ return llvm::APFloat(Semantics, 1U) / llvm::APFloat(Semantics, 2U);
+}
+
namespace {
AST_MATCHER(FloatingLiteral, floatHalf) {
- const auto &Literal = Node.getValue();
+ const llvm::APFloat Literal = Node.getValue();
if ((&Node.getSemantics()) == &llvm::APFloat::IEEEsingle())
- return Literal.convertToFloat() == 0.5f;
+ return Literal == getHalf(llvm::APFloat::IEEEsingle());
if ((&Node.getSemantics()) == &llvm::APFloat::IEEEdouble())
- return Literal.convertToDouble() == 0.5;
+ return Literal == getHalf(llvm::APFloat::IEEEdouble());
return false;
}
} // namespace
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147906.512149.patch
Type: text/x-patch
Size: 1009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230410/89f8bc75/attachment.bin>
More information about the cfe-commits
mailing list