I noticed that we can use the do_ubsan_in_current_function wrapper more, which allows us to simplify the code a bit further.
Ran ubsan testsuite on x86_64-linux, ok for trunk? 2015-03-09 Marek Polacek <pola...@redhat.com> * c-convert.c (convert): Make use of do_ubsan_in_current_function. * c-decl.c (grokdeclarator): Likewise. * c-typeck.c (build_binary_op): Likewise. * cp-ubsan.c (cp_ubsan_instrument_vptr_p): Make use of do_ubsan_in_current_function. diff --git gcc/c/c-convert.c gcc/c/c-convert.c index 2cb53f7..27fc3fc 100644 --- gcc/c/c-convert.c +++ gcc/c/c-convert.c @@ -121,9 +121,7 @@ convert (tree type, tree expr) if (flag_sanitize & SANITIZE_FLOAT_CAST && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE && COMPLETE_TYPE_P (type) - && current_function_decl != NULL_TREE - && !lookup_attribute ("no_sanitize_undefined", - DECL_ATTRIBUTES (current_function_decl))) + && do_ubsan_in_current_function ()) { tree arg; if (in_late_binary_op) diff --git gcc/c/c-decl.c gcc/c/c-decl.c index 7497858..c140837 100644 --- gcc/c/c-decl.c +++ gcc/c/c-decl.c @@ -5837,10 +5837,7 @@ grokdeclarator (const struct c_declarator *declarator, warn_variable_length_array (name, size); if (flag_sanitize & SANITIZE_VLA && decl_context == NORMAL - && current_function_decl != NULL_TREE - && !lookup_attribute ("no_sanitize_undefined", - DECL_ATTRIBUTES - (current_function_decl))) + && do_ubsan_in_current_function ()) { /* Evaluate the array size only once. */ size = c_save_expr (size); diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c index a3a9c77..7c6d974 100644 --- gcc/c/c-typeck.c +++ gcc/c/c-typeck.c @@ -11229,9 +11229,7 @@ build_binary_op (location_t location, enum tree_code code, if ((flag_sanitize & (SANITIZE_SHIFT | SANITIZE_DIVIDE | SANITIZE_FLOAT_DIVIDE)) - && current_function_decl != 0 - && !lookup_attribute ("no_sanitize_undefined", - DECL_ATTRIBUTES (current_function_decl)) + && do_ubsan_in_current_function () && (doing_div_or_mod || doing_shift)) { /* OP0 and/or OP1 might have side-effects. */ diff --git gcc/cp/cp-ubsan.c gcc/cp/cp-ubsan.c index ce12263..e0c8c2e4 100644 --- gcc/cp/cp-ubsan.c +++ gcc/cp/cp-ubsan.c @@ -63,9 +63,7 @@ cp_ubsan_instrument_vptr_p (tree type) if (!flag_rtti || flag_sanitize_undefined_trap_on_error) return false; - if (current_function_decl - && lookup_attribute ("no_sanitize_undefined", - DECL_ATTRIBUTES (current_function_decl))) + if (!do_ubsan_in_current_function ()) return false; if (type) Marek