diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-07-06 21:05:52 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-07-06 21:05:52 +0000 |
commit | 9e52c43090f8cd980167bbd2719878ae36bcf6b5 (patch) | |
tree | 6bce1fdee58d77561140122cc32ea388c48459df /clang/docs | |
parent | a7145c45a7ea138baac62f67f7730951a70c6703 (diff) | |
download | bcm5719-llvm-9e52c43090f8cd980167bbd2719878ae36bcf6b5.tar.gz bcm5719-llvm-9e52c43090f8cd980167bbd2719878ae36bcf6b5.zip |
Treat the range of representable values of floating-point types as [-inf, +inf] not as [-max, +max].
Summary:
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.
Reviewers: rnk, BillyONeal
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D63793
llvm-svn: 365272
Diffstat (limited to 'clang/docs')
-rw-r--r-- | clang/docs/UndefinedBehaviorSanitizer.rst | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/clang/docs/UndefinedBehaviorSanitizer.rst b/clang/docs/UndefinedBehaviorSanitizer.rst index 2456f5040d4..7a4eaf4f60d 100644 --- a/clang/docs/UndefinedBehaviorSanitizer.rst +++ b/clang/docs/UndefinedBehaviorSanitizer.rst @@ -83,9 +83,13 @@ Available checks are: type. - ``-fsanitize=float-cast-overflow``: Conversion to, from, or between floating-point types which would overflow the - destination. + destination. Because the range of representable values for all + floating-point types supported by Clang is [-inf, +inf], the only + cases detected are conversions from floating point to integer types. - ``-fsanitize=float-divide-by-zero``: Floating point division by - zero. + zero. This is undefined per the C and C++ standards, but is defined + by Clang (and by ISO/IEC/IEEE 60559 / IEEE 754) as producing either an + infinity or NaN value, so is not included in ``-fsanitize=undefined``. - ``-fsanitize=function``: Indirect call of a function through a function pointer of the wrong type (Darwin/Linux, C++ and x86/x86_64 only). @@ -163,8 +167,8 @@ Available checks are: You can also use the following check groups: - ``-fsanitize=undefined``: All of the checks listed above other than - ``unsigned-integer-overflow``, ``implicit-conversion`` and the - ``nullability-*`` group of checks. + ``float-divide-by-zero``, ``unsigned-integer-overflow``, + ``implicit-conversion``, and the ``nullability-*`` group of checks. - ``-fsanitize=undefined-trap``: Deprecated alias of ``-fsanitize=undefined``. - ``-fsanitize=implicit-integer-truncation``: Catches lossy integral @@ -174,16 +178,16 @@ You can also use the following check groups: conversions that change the arithmetic value of the integer. Enables ``implicit-signed-integer-truncation`` and ``implicit-integer-sign-change``. - ``-fsanitize=implicit-conversion``: Checks for suspicious - behaviour of implicit conversions. Enables + behavior of implicit conversions. Enables ``implicit-unsigned-integer-truncation``, - ``implicit-signed-integer-truncation`` and + ``implicit-signed-integer-truncation``, and ``implicit-integer-sign-change``. - ``-fsanitize=integer``: Checks for undefined or suspicious integer behavior (e.g. unsigned integer overflow). Enables ``signed-integer-overflow``, ``unsigned-integer-overflow``, ``shift``, ``integer-divide-by-zero``, ``implicit-unsigned-integer-truncation``, - ``implicit-signed-integer-truncation`` and + ``implicit-signed-integer-truncation``, and ``implicit-integer-sign-change``. - ``-fsanitize=nullability``: Enables ``nullability-arg``, ``nullability-assign``, and ``nullability-return``. While violating |