+2017-07-31 Martin Liska <mliska@suse.cz>
+
+ PR sanitize/81530
+ * convert.c (convert_to_integer_1): Guard condition with flag_sanitize_p
+ also with current_function_decl non-null equality.
+
2017-07-31 Jakub Jelinek <jakub@redhat.com>
PR sanitizer/81604
+2017-07-31 Martin Liska <mliska@suse.cz>
+
+ PR sanitize/81530
+ * c-ubsan.c (ubsan_maybe_instrument_array_ref):
+ Guard condition with flag_sanitize_p also with current_function_decl
+ non-null equality.
+ (ubsan_maybe_instrument_reference_or_call): Likewise.
+
2017-07-30 Uros Bizjak <ubizjak@gmail.com>
* c-format.c (asm_fprintf_char_table): Add 'z' to format_chars.
ubsan_maybe_instrument_array_ref (tree *expr_p, bool ignore_off_by_one)
{
if (!ubsan_array_ref_instrumented_p (*expr_p)
- && sanitize_flags_p (SANITIZE_BOUNDS | SANITIZE_BOUNDS_STRICT))
+ && sanitize_flags_p (SANITIZE_BOUNDS | SANITIZE_BOUNDS_STRICT)
+ && current_function_decl != NULL_TREE)
{
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 (!sanitize_flags_p (SANITIZE_ALIGNMENT | SANITIZE_NULL))
+ if (!sanitize_flags_p (SANITIZE_ALIGNMENT | SANITIZE_NULL)
+ || current_function_decl == NULL_TREE)
return NULL_TREE;
tree type = TREE_TYPE (ptype);
+2017-07-31 Martin Liska <mliska@suse.cz>
+
+ PR sanitize/81530
+ * c-convert.c (convert): Guard condition with flag_sanitize_p
+ also with current_function_decl non-null equality.
+ * c-decl.c (grokdeclarator): Likewise.
+ * c-typeck.c (build_binary_op): Likewise.
+
2017-07-25 Marek Polacek <polacek@redhat.com>
* c-decl.c (grokfield): Remove local variable.
case INTEGER_TYPE:
case ENUMERAL_TYPE:
if (sanitize_flags_p (SANITIZE_FLOAT_CAST)
+ && current_function_decl != NULL_TREE
&& TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
&& COMPLETE_TYPE_P (type))
{
this_size_varies = size_varies = true;
warn_variable_length_array (name, size);
if (sanitize_flags_p (SANITIZE_VLA)
+ && current_function_decl != NULL_TREE
&& decl_context == NORMAL)
{
/* Evaluate the array size only once. */
if (sanitize_flags_p ((SANITIZE_SHIFT
| SANITIZE_DIVIDE | SANITIZE_FLOAT_DIVIDE))
+ && current_function_decl != NULL_TREE
&& (doing_div_or_mod || doing_shift)
&& !require_constant_value)
{
return build1 (CONVERT_EXPR, type, expr);
case REAL_TYPE:
- if (sanitize_flags_p (SANITIZE_FLOAT_CAST))
+ if (sanitize_flags_p (SANITIZE_FLOAT_CAST)
+ && current_function_decl != NULL_TREE)
{
expr = save_expr (expr);
tree check = ubsan_instrument_float_cast (loc, type, expr);
+2017-07-31 Martin Liska <mliska@suse.cz>
+
+ PR sanitize/81530
+ * cp-gimplify.c (cp_genericize): Guard condition with flag_sanitize_p
+ also with current_function_decl non-null equality.
+ * cp-ubsan.c (cp_ubsan_instrument_vptr_p): Likewise.
+ * decl.c (compute_array_index_type): Likewise.
+ * init.c (finish_length_check): Likewise.
+ * typeck.c (cp_build_binary_op): Likewise.
+
2017-07-29 Jakub Jelinek <jakub@redhat.com>
* cp-objcp-common.c (cp_decl_dwarf_attribute): Handle
walk_tree's hash functionality. */
cp_genericize_tree (&DECL_SAVED_TREE (fndecl), true);
- if (sanitize_flags_p (SANITIZE_RETURN))
+ if (sanitize_flags_p (SANITIZE_RETURN)
+ && current_function_decl != NULL_TREE)
cp_ubsan_maybe_instrument_return (fndecl);
/* Do everything else. */
if (!sanitize_flags_p (SANITIZE_VPTR))
return false;
+ if (current_function_decl == NULL_TREE)
+ return false;
+
if (type)
{
type = TYPE_MAIN_VARIANT (type);
stabilize_vla_size (itype);
- if (sanitize_flags_p (SANITIZE_VLA))
+ if (sanitize_flags_p (SANITIZE_VLA)
+ && current_function_decl != NULL_TREE)
{
/* 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 (sanitize_flags_p (SANITIZE_BOUNDS))
+ else if (sanitize_flags_p (SANITIZE_BOUNDS)
+ && current_function_decl != NULL_TREE)
{
/* Make sure the last element of the initializer is in bounds. */
finish_expr_stmt
if (sanitize_flags_p ((SANITIZE_SHIFT
| SANITIZE_DIVIDE | SANITIZE_FLOAT_DIVIDE))
+ && current_function_decl != NULL_TREE
&& !processing_template_decl
&& (doing_div_or_mod || doing_shift))
{
+2017-07-31 Martin Liska <mliska@suse.cz>
+
+ PR sanitize/81530
+ * g++.dg/ubsan/pr81530.C: New test.
+
2017-07-31 Jakub Jelinek <jakub@redhat.com>
PR sanitizer/81604
--- /dev/null
+/* PR sanitizer/81530 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=undefined" } */
+
+int a[(long) 4e20]; /* { dg-error "overflow in constant expression" } */
+/* { dg-error "size of array .a. is too large" "" { target *-*-* } .-1 } */