aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-cfg.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2017-06-13 15:59:05 +0200
committerMartin Liska <marxin@gcc.gnu.org>2017-06-13 13:59:05 +0000
commit45b2222a13eae86582966de6b8203ca75660c1fe (patch)
tree36d6c2af79ae50b3f1411ab1d312739c1d808a8e /gcc/tree-cfg.c
parentef0e3441246ee1dc01b3bf39622bc53644b181f8 (diff)
downloadgcc-45b2222a13eae86582966de6b8203ca75660c1fe.zip
gcc-45b2222a13eae86582966de6b8203ca75660c1fe.tar.gz
gcc-45b2222a13eae86582966de6b8203ca75660c1fe.tar.bz2
Implement no_sanitize function attribute
2017-06-13 Martin Liska <mliska@suse.cz> PR sanitize/78204 * c-c++-common/ubsan/attrib-2.c (float_cast2): Enhance the test by adding no_sanitize attribute. * gcc.dg/asan/use-after-scope-4.c: Likewise. 2017-06-13 Martin Liska <mliska@suse.cz> PR sanitize/78204 * c-attribs.c (add_no_sanitize_value): New function. (handle_no_sanitize_attribute): Likewise. (handle_no_sanitize_address_attribute): Use the function. (handle_no_sanitize_thread_attribute): New function. (handle_no_address_safety_analysis_attribute): Use add_no_sanitize_value. (handle_no_sanitize_undefined_attribute): Likewise. * c-common.h: Declare new functions. * c-ubsan.c (ubsan_instrument_division): Use sanitize_flags_p. (ubsan_instrument_shift): Likewise. (ubsan_instrument_bounds): Likewise. (ubsan_maybe_instrument_array_ref): Likewise. (ubsan_maybe_instrument_reference_or_call): Likewise. 2017-06-13 Martin Liska <mliska@suse.cz> PR sanitize/78204 * asan.c (asan_sanitize_stack_p): Use sanitize_flags_p. (gate_asan): Likewise. * asan.h (asan_no_sanitize_address_p): Remove the function. (sanitize_flags_p): New function. * builtins.def: Fix coding style. * common.opt: Use renamed enum value. * convert.c (convert_to_integer_1): Use sanitize_flags_p. * doc/extend.texi: Document no_sanitize attribute. * flag-types.h (enum sanitize_code): Rename SANITIZE_NONDEFAULT to SANITIZE_UNDEFINED_NONDEFAULT. * gcc.c (sanitize_spec_function): Use the renamed enum value. * gimple-fold.c (optimize_atomic_compare_exchange_p): Use sanitize_flags_p. * gimplify.c (gimplify_function_tree): Likewise. * ipa-inline.c (sanitize_attrs_match_for_inline_p): Likewise. * opts.c (parse_no_sanitize_attribute): New function. (common_handle_option): Use renamed enum value. * opts.h (parse_no_sanitize_attribute): Declare. * tree.c (sanitize_flags_p): New function. * tree.h: Declared here. * tsan.c: Use sanitize_flags_p. * ubsan.c (ubsan_expand_null_ifn): Likewise. (instrument_mem_ref): Likewise. (instrument_bool_enum_load): Likewise. (do_ubsan_in_current_function): Remove the function. (pass_ubsan::execute): Use sanitize_flags_p. * ubsan.h: Remove do_ubsan_in_current_function * tree-cfg.c (print_no_sanitize_attr_value): New function. (dump_function_to_file): Use it here. 2017-06-13 Martin Liska <mliska@suse.cz> PR sanitize/78204 * class.c (build_base_path): Use sanitize_flags_p. * cp-gimplify.c (cp_genericize_r): Likewise. (cp_genericize_tree): Likewise. (cp_genericize): Likewise. * cp-ubsan.c (cp_ubsan_instrument_vptr_p): Likewise. * decl.c (compute_array_index_type): Likewise. (start_preparsed_function): Likewise. * decl2.c (one_static_initialization_or_destruction): Likewise. * init.c (finish_length_check): Likewise. * lambda.c (maybe_add_lambda_conv_op): Likewise. * typeck.c (cp_build_binary_op): Likewise. (build_static_cast_1): Likewise. 2017-06-13 Martin Liska <mliska@suse.cz> PR sanitize/78204 * c-convert.c (convert): Use sanitize_flags_p. * c-decl.c (grokdeclarator): Likewise. * c-typeck.c (convert_for_assignment): Likewise. (c_finish_return): Likewise. (build_binary_op): Likewise. From-SVN: r249158
Diffstat (limited to 'gcc/tree-cfg.c')
-rw-r--r--gcc/tree-cfg.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index c84e99d..7df80f8 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -60,6 +60,7 @@ along with GCC; see the file COPYING3. If not see
#include "gimplify.h"
#include "attribs.h"
#include "selftest.h"
+#include "opts.h"
/* This file contains functions for building the Control Flow Graph (CFG)
for a function tree. */
@@ -7555,6 +7556,25 @@ dump_default_def (FILE *file, tree def, int spc, dump_flags_t flags)
fprintf (file, ";\n");
}
+/* Print no_sanitize attribute to FILE for a given attribute VALUE. */
+
+static void
+print_no_sanitize_attr_value (FILE *file, tree value)
+{
+ unsigned int flags = tree_to_uhwi (value);
+ bool first = true;
+ for (int i = 0; sanitizer_opts[i].name != NULL; ++i)
+ {
+ if ((sanitizer_opts[i].flag & flags) == sanitizer_opts[i].flag)
+ {
+ if (!first)
+ fprintf (file, " | ");
+ fprintf (file, "%s", sanitizer_opts[i].name);
+ first = false;
+ }
+ }
+}
+
/* Dump FUNCTION_DECL FN to file FILE using FLAGS (see TDF_* in dumpfile.h)
*/
@@ -7582,11 +7602,16 @@ dump_function_to_file (tree fndecl, FILE *file, dump_flags_t flags)
if (!first)
fprintf (file, ", ");
- print_generic_expr (file, get_attribute_name (chain), dump_flags);
+ tree name = get_attribute_name (chain);
+ print_generic_expr (file, name, dump_flags);
if (TREE_VALUE (chain) != NULL_TREE)
{
fprintf (file, " (");
- print_generic_expr (file, TREE_VALUE (chain), dump_flags);
+
+ if (strstr (IDENTIFIER_POINTER (name), "no_sanitize"))
+ print_no_sanitize_attr_value (file, TREE_VALUE (chain));
+ else
+ print_generic_expr (file, TREE_VALUE (chain), dump_flags);
fprintf (file, ")");
}
}