]> git.ipfire.org Git - thirdparty/gcc.git/commit
ubsan: _BitInt -fsanitize=undefined support [PR102989]
authorJakub Jelinek <jakub@redhat.com>
Wed, 6 Sep 2023 15:30:07 +0000 (17:30 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 6 Sep 2023 15:30:07 +0000 (17:30 +0200)
commit95521e15b6ef00c192a1bbd7c13b5f35395c7c9e
treea3e04b6120c089b6bc3da0951f36610677431949
parentb38deff6127778fed453bb647e32738ba5c78e33
ubsan: _BitInt -fsanitize=undefined support [PR102989]

The following patch introduces some -fsanitize=undefined support for _BitInt,
but some of the diagnostics is limited by lack of proper support in the
library.
I've filed https://github.com/llvm/llvm-project/issues/64100 to request
proper support, for now some of the diagnostics might have less or more
confusing or inaccurate wording but UB should still be diagnosed when it
happens.

2023-09-06  Jakub Jelinek  <jakub@redhat.com>

PR c/102989
gcc/
* internal-fn.cc (expand_ubsan_result_store): Add LHS, MODE and
DO_ERROR arguments.  For non-mode precision BITINT_TYPE results
check if all padding bits up to mode precision are zeros or sign
bit copies and if not, jump to DO_ERROR.
(expand_addsub_overflow, expand_neg_overflow, expand_mul_overflow):
Adjust expand_ubsan_result_store callers.
* ubsan.cc: Include target.h and langhooks.h.
(ubsan_encode_value): Pass BITINT_TYPE values which fit into pointer
size converted to pointer sized integer, pass BITINT_TYPE values
which fit into TImode (if supported) or DImode as those integer types
or otherwise for now punt (pass 0).
(ubsan_type_descriptor): Handle BITINT_TYPE.  For pstyle of
UBSAN_PRINT_FORCE_INT use TK_Integer (0x0000) mode with a
TImode/DImode precision rather than TK_Unknown used otherwise for
large/huge BITINT_TYPEs.
(instrument_si_overflow): Instrument BITINT_TYPE operations even when
they don't have mode precision.
* ubsan.h (enum ubsan_print_style): New enumerator.
gcc/c-family/
* c-ubsan.cc (ubsan_instrument_shift): Use UBSAN_PRINT_FORCE_INT
for type0 type descriptor.
gcc/c-family/c-ubsan.cc
gcc/internal-fn.cc
gcc/ubsan.cc
gcc/ubsan.h