On Fri, May 23, 2014 at 04:19:00PM +0200, Marek Polacek wrote: > This is the latest patch for -fsanitize=float-cast-overflow. Since last > version it: > - adds tons of tests written by Jakub; > - patches libubsan so it can handle 96-bit floating-point types > (that is, long double and __float80 in -m32 mode);
CCing Kostya on this one liner, which has been posted to llvm-commits, but nothing has been done yet. I'm approving this anyway, I don't see anything controversial on it and clang fails without that change the same (supposedly insufficient test coverage on the compiler-rt side). > - includes a hack for printing __float{80,128}/_Decimal* types in > libubsan. Since libubsan handles only float/double/long double > floating-point types, we use TK_Unknown for other types, meaning > that libubsan prints "<unknown>" instead of the value. I think this is for now good, while in theory I can imagine not very long code to print _Decimal* to string (convert to binary integer format if in the densely packed format (hey, ppc*), print __int128 significand (or do 2x wide long long division/modulo) into string using snprintf, take care of exponent and sign and putting in decimal dot), it is not high prio for me, and for __float128 you can hardly avoid libquadmath or something similarly large, unless you want to print it as C99 hexadecimal float (that would be again pretty easy). > Regtested/bootstrapped on x86_64-linux. Couldn't test ppc64, as > libsanitizer currently doesn't build on this architecture. > > Ok for trunk? > > 2014-05-23 Marek Polacek <pola...@redhat.com> > Jakub Jelinek <ja...@redhat.com> > > * builtins.def: Change SANITIZE_FLOAT_DIVIDE to SANITIZE_NONDEFAULT. > * gcc.c (sanitize_spec_function): Likewise. > * convert.c (convert_to_integer): Include "ubsan.h". Add > floating-point to integer instrumentation. > * doc/invoke.texi: Document -fsanitize=float-cast-overflow. > * flag-types.h (enum sanitize_code): Add SANITIZE_FLOAT_CAST and > SANITIZE_NONDEFAULT. > * opts.c (common_handle_option): Handle -fsanitize=float-cast-overflow. > * sanitizer.def (BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW, > BUILT_IN_UBSAN_HANDLE_FLOAT_CAST_OVERFLOW_ABORT): Add. > * ubsan.c: Include "realmpfr.h" and "dfp.h". > (get_ubsan_type_info_for_type): Handle REAL_TYPEs. > (ubsan_type_descriptor): Set tkind to 0xffff for types other than > float/double/long double. > (ubsan_instrument_float_cast): New function. > * ubsan.h (ubsan_instrument_float_cast): Declare. > testsuite/ > * c-c++-common/ubsan/float-cast-overflow-1.c: New test. > * c-c++-common/ubsan/float-cast-overflow-10.c: New test. > * c-c++-common/ubsan/float-cast-overflow-2.c: New test. > * c-c++-common/ubsan/float-cast-overflow-3.c: New test. > * c-c++-common/ubsan/float-cast-overflow-4.c: New test. > * c-c++-common/ubsan/float-cast-overflow-5.c: New test. > * c-c++-common/ubsan/float-cast-overflow-6.c: New test. > * c-c++-common/ubsan/float-cast-overflow-7.c: New test. > * c-c++-common/ubsan/float-cast-overflow-7.h: New file. > * c-c++-common/ubsan/float-cast-overflow-8.c: New test. > * c-c++-common/ubsan/float-cast-overflow-9.c: New test. > * c-c++-common/ubsan/float-cast.h: New file. > * g++.dg/ubsan/float-cast-overflow-bf.C: New test. > * gcc.dg/ubsan/float-cast-overflow-bf.c: New test. > libsanitizer/ > * ubsan/ubsan_value.cc (getFloatValue): Handle 96-bit > floating-point types. Ok, thanks. Jakub