aboutsummaryrefslogtreecommitdiff
path: root/gcc/ubsan.c
diff options
context:
space:
mode:
authorMax Ostapenko <m.ostapenko@partner.samsung.com>2015-10-21 10:40:54 +0300
committerMaxim Ostapenko <chefmax@gcc.gnu.org>2015-10-21 10:40:54 +0300
commit89e302b80c8b283a0e073a92fb2d52ad7ccb6eb8 (patch)
treeb7543b32302329374f126d54ffc91193bf4f4f25 /gcc/ubsan.c
parent696d846a56cc12549f080c6c87e6a0272bdb29f1 (diff)
downloadgcc-89e302b80c8b283a0e073a92fb2d52ad7ccb6eb8.zip
gcc-89e302b80c8b283a0e073a92fb2d52ad7ccb6eb8.tar.gz
gcc-89e302b80c8b283a0e073a92fb2d52ad7ccb6eb8.tar.bz2
libsanitizer merge from upstream r250806, compiler part.
gcc/ * asan.c (asan_emit_stack_protection): Don't pass local stack to asan_stack_malloc_[n] anymore. Check if asan_stack_malloc_[n] returned NULL and use local stack than. (asan_finish_file): Insert __asan_version_mismatch_check_v[n] call in addition to __asan_init. * sanitizer.def (BUILT_IN_ASAN_INIT): Rename to __asan_init. (BUILT_IN_ASAN_VERSION_MISMATCH_CHECK): Add new builtin call. * asan.h (asan_intercepted_p): Handle new string builtins. * ubsan.c (ubsan_use_new_style_p): New function. (ubsan_instrument_float_cast): If location is unknown, assign input_location to loc. Propagate loc to ubsan_create_data if ubsan_use_new_style_p returned true. config/ * bootstrap-asan.mk: Replace ASAN_OPTIONS=detect_leaks with LSAN_OPTIONS=detect_leaks. gcc/testsuite/ * c-c++-common/ubsan/float-cast-overflow-10.c: Adjust test. * c-c++-common/ubsan/float-cast-overflow-8.c: Likewise. * c-c++-common/ubsan/float-cast-overflow-9.c: Likewise. * g++.dg/asan/default-options-1.C: Likewise. From-SVN: r229112
Diffstat (limited to 'gcc/ubsan.c')
-rw-r--r--gcc/ubsan.c39
1 files changed, 37 insertions, 2 deletions
diff --git a/gcc/ubsan.c b/gcc/ubsan.c
index af586e3..f30a2d5 100644
--- a/gcc/ubsan.c
+++ b/gcc/ubsan.c
@@ -1472,6 +1472,30 @@ instrument_bool_enum_load (gimple_stmt_iterator *gsi)
*gsi = gsi_for_stmt (stmt);
}
+/* Determine if we can propagate given LOCATION to ubsan_data descriptor to use
+ new style handlers. Libubsan uses heuristics to destinguish between old and
+ new styles and relies on these properties for filename:
+
+ a) Location's filename must not be NULL.
+ b) Location's filename must not be equal to "".
+ c) Location's filename must not be equal to "\1".
+ d) First two bytes of filename must not contain '\xff' symbol. */
+
+static bool
+ubsan_use_new_style_p (location_t loc)
+{
+ if (loc == UNKNOWN_LOCATION)
+ return false;
+
+ expanded_location xloc = expand_location (loc);
+ if (xloc.file == NULL || strncmp (xloc.file, "\1", 2) == 0
+ || xloc.file == '\0' || xloc.file[0] == '\xff'
+ || xloc.file[1] == '\xff')
+ return false;
+
+ return true;
+}
+
/* Instrument float point-to-integer conversion. TYPE is an integer type of
destination, EXPR is floating-point expression. ARG is what to pass
the libubsan call as value, often EXPR itself. */
@@ -1484,6 +1508,7 @@ ubsan_instrument_float_cast (location_t loc, tree type, tree expr, tree arg)
machine_mode mode = TYPE_MODE (expr_type);
int prec = TYPE_PRECISION (type);
bool uns_p = TYPE_UNSIGNED (type);
+ if (!loc) loc = input_location;
/* Float to integer conversion first truncates toward zero, so
even signed char c = 127.875f; is not problematic.
@@ -1580,9 +1605,19 @@ ubsan_instrument_float_cast (location_t loc, tree type, tree expr, tree arg)
fn = build_call_expr_loc (loc, builtin_decl_explicit (BUILT_IN_TRAP), 0);
else
{
+ location_t *loc_ptr = NULL;
+ unsigned num_locations = 0;
+ /* Figure out if we can propagate location to ubsan_data and use new
+ style handlers in libubsan. */
+ if (ubsan_use_new_style_p (loc))
+ {
+ loc_ptr = &loc;
+ num_locations = 1;
+ }
/* Create the __ubsan_handle_float_cast_overflow fn call. */
- tree data = ubsan_create_data ("__ubsan_float_cast_overflow_data", 0,
- NULL, ubsan_type_descriptor (expr_type),
+ tree data = ubsan_create_data ("__ubsan_float_cast_overflow_data",
+ num_locations, loc_ptr,
+ ubsan_type_descriptor (expr_type),
ubsan_type_descriptor (type), NULL_TREE,
NULL_TREE);
enum built_in_function bcode