[PATCH] D63793: Treat the range of representable values of floating-point types as [-inf, +inf] not as [-max, +max].

Richard Smith - zygoloid via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 25 14:45:20 PDT 2019


rsmith created this revision.
rsmith added reviewers: rnk, BillyONeal.
Herald added a project: clang.

Prior to r329065, we used [-max, max] as the range of representable
values because LLVM's `fptrunc` did not guarantee defined behavior when
truncating from a larger floating-point type to a smaller one. Now that
has been fixed, we can make clang follow normal IEEE 754 semantics in this
regard and take the larger range [-inf, +inf] as the range of representable
values.

In practice, this affects two parts of the frontend:

- the constant evaluator no longer treats floating-point evaluations that result in +-inf as being undefined (because they no longer leave the range of representable values of the type)
- UBSan no longer treats conversions to floating-point type that are outside the [-max, +max] range as being undefined

In passing, also remove the float-divide-by-zero sanitizer from
-fsanitize=undefined, on the basis that while it's undefined per C++
rules (and we disallow it in constant expressions for that reason), it
is defined by Clang / LLVM / IEEE 754.


Repository:
  rC Clang

https://reviews.llvm.org/D63793

Files:
  docs/UndefinedBehaviorSanitizer.rst
  include/clang/Basic/Sanitizers.def
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGExprScalar.cpp
  test/CXX/expr/expr.const/p2-0x.cpp
  test/CodeGen/catch-undef-behavior.c
  test/Driver/fsanitize.c
  test/SemaCXX/constant-expression-cxx1y.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63793.206532.patch
Type: text/x-patch
Size: 31720 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190625/84fcabf2/attachment-0001.bin>


More information about the cfe-commits mailing list