+2015-01-08 Jason Merrill <jason@redhat.com>
+
+ * ubsan.c (do_ubsan_in_current_function): New.
+ (pass_ubsan::gate): Use it.
+ * ubsan.h: Declare it.
+ * convert.c (convert_to_integer): Use it.
+
2015-01-08 Jakub Jelinek <jakub@redhat.com>
PR target/64338
+2015-01-08 Jason Merrill <jason@redhat.com>
+
+ * c-ubsan.c (ubsan_maybe_instrument_array_ref): Use
+ do_ubsan_in_current_function.
+ (ubsan_maybe_instrument_reference_or_call): Likewise.
+ * c-ubsan.h: Declare it.
+
2015-01-08 Mike Stump <mikestump@comcast.net>
* c-common.c (c_common_attribute_table): Add no_sanitize_thread.
ubsan_maybe_instrument_array_ref (tree *expr_p, bool ignore_off_by_one)
{
if (!ubsan_array_ref_instrumented_p (*expr_p)
- && current_function_decl != NULL_TREE
- && !lookup_attribute ("no_sanitize_undefined",
- DECL_ATTRIBUTES (current_function_decl)))
+ && do_ubsan_in_current_function ())
{
tree op0 = TREE_OPERAND (*expr_p, 0);
tree op1 = TREE_OPERAND (*expr_p, 1);
ubsan_maybe_instrument_reference_or_call (location_t loc, tree op, tree ptype,
enum ubsan_null_ckind ckind)
{
- if (current_function_decl == NULL_TREE
- || lookup_attribute ("no_sanitize_undefined",
- DECL_ATTRIBUTES (current_function_decl)))
+ if (!do_ubsan_in_current_function ())
return NULL_TREE;
tree type = TREE_TYPE (ptype);
extern void ubsan_maybe_instrument_reference (tree);
extern void ubsan_maybe_instrument_member_call (tree, bool);
+/* Declare this here as well as in ubsan.h. */
+extern bool do_ubsan_in_current_function (void);
+
#endif /* GCC_C_UBSAN_H */
case REAL_TYPE:
if (flag_sanitize & SANITIZE_FLOAT_CAST
- && current_function_decl != NULL_TREE
- && !lookup_attribute ("no_sanitize_undefined",
- DECL_ATTRIBUTES (current_function_decl)))
+ && do_ubsan_in_current_function ())
{
expr = save_expr (expr);
tree check = ubsan_instrument_float_cast (loc, type, expr, expr);
+2015-01-08 Jason Merrill <jason@redhat.com>
+
+ * cp-gimplify.c (cp_genericize): Use do_ubsan_in_current_function.
+ * decl.c (compute_array_index_type): Likewise.
+ * init.c (build_vec_init): Likewise.
+ * typeck.c (cp_build_binary_op): Likewise.
+
2015-01-08 Jason Merrill <jason@redhat.com>
* init.c (build_vec_init): Call ubsan_instrument_bounds to check
cp_genericize_tree (&DECL_SAVED_TREE (fndecl));
if (flag_sanitize & SANITIZE_RETURN
- && current_function_decl != NULL_TREE
- && !lookup_attribute ("no_sanitize_undefined",
- DECL_ATTRIBUTES (current_function_decl)))
+ && do_ubsan_in_current_function ())
cp_ubsan_maybe_instrument_return (fndecl);
/* Do everything else. */
stabilize_vla_size (itype);
if (flag_sanitize & SANITIZE_VLA
- && current_function_decl != NULL_TREE
- && !lookup_attribute ("no_sanitize_undefined",
- DECL_ATTRIBUTES
- (current_function_decl)))
+ && do_ubsan_in_current_function ())
{
/* We have to add 1 -- in the ubsan routine we generate
LE_EXPR rather than LT_EXPR. */
/* Don't check an array new when -fno-exceptions. */
}
else if (flag_sanitize & SANITIZE_BOUNDS
- && current_function_decl
- && !lookup_attribute ("no_sanitize_undefined",
- DECL_ATTRIBUTES
- (current_function_decl)))
+ && do_ubsan_in_current_function ())
{
/* Make sure the last element of the initializer is in bounds. */
finish_expr_stmt
if ((flag_sanitize & (SANITIZE_SHIFT | SANITIZE_DIVIDE
| SANITIZE_FLOAT_DIVIDE))
&& !processing_template_decl
- && 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. */
gsi_insert_before (gsi, g, GSI_SAME_STMT);
}
+/* True if we want to play UBSan games in the current function. */
+
+bool
+do_ubsan_in_current_function ()
+{
+ return (current_function_decl != NULL_TREE
+ && !lookup_attribute ("no_sanitize_undefined",
+ DECL_ATTRIBUTES (current_function_decl)));
+}
+
namespace {
const pass_data pass_data_ubsan =
| SANITIZE_NONNULL_ATTRIBUTE
| SANITIZE_RETURNS_NONNULL_ATTRIBUTE
| SANITIZE_OBJECT_SIZE)
- && current_function_decl != NULL_TREE
- && !lookup_attribute ("no_sanitize_undefined",
- DECL_ATTRIBUTES (current_function_decl));
+ && do_ubsan_in_current_function ();
}
virtual unsigned int execute (function *);
UBSAN_PRINT_ARRAY
};
+extern bool do_ubsan_in_current_function (void);
extern bool ubsan_expand_bounds_ifn (gimple_stmt_iterator *);
extern bool ubsan_expand_null_ifn (gimple_stmt_iterator *);
extern bool ubsan_expand_objsize_ifn (gimple_stmt_iterator *);