From 89e302b80c8b283a0e073a92fb2d52ad7ccb6eb8 Mon Sep 17 00:00:00 2001 From: Max Ostapenko Date: Wed, 21 Oct 2015 10:40:54 +0300 Subject: 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 --- gcc/ubsan.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'gcc/ubsan.c') 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 -- cgit v1.1