diff options
author | Aldy Hernandez <aldyh@redhat.com> | 2020-09-17 09:34:03 +0200 |
---|---|---|
committer | Aldy Hernandez <aldyh@redhat.com> | 2020-10-01 17:11:17 +0200 |
commit | f5299992827048274f2146746ab4abab3accd124 (patch) | |
tree | b0830471dbe0c82c925a6c75a709c558645bc7c8 /gcc/builtins.c | |
parent | a889e06ac680e0aafa62cd5dec99e75d3f1ca1b6 (diff) | |
download | gcc-f5299992827048274f2146746ab4abab3accd124.zip gcc-f5299992827048274f2146746ab4abab3accd124.tar.gz gcc-f5299992827048274f2146746ab4abab3accd124.tar.bz2 |
Convert sprintf/strlen passes to value query class.
gcc/ChangeLog:
* builtins.c (compute_objsize): Replace vr_values with range_query.
(get_range): Same.
(gimple_call_alloc_size): Same.
* builtins.h (class vr_values): Remove.
(gimple_call_alloc_size): Replace vr_values with range_query.
* gimple-ssa-sprintf.c (get_int_range): Same.
(struct directive): Pass gimple context to fmtfunc callback.
(directive::set_width): Replace inline with out-of-line version.
(directive::set_precision): Same.
(format_none): New gimple argument.
(format_percent): New gimple argument.
(format_integer): New gimple argument.
(format_floating): New gimple argument.
(get_string_length): Use range_query API.
(format_character): New gimple argument.
(format_string): New gimple argument.
(format_plain): New gimple argument.
(format_directive): New gimple argument.
(parse_directive): Replace vr_values with range_query.
(compute_format_length): Same.
(handle_printf_call): Same. Adjust for range_query API.
* tree-ssa-strlen.c (get_range): Same.
(compare_nonzero_chars): Same.
(get_addr_stridx) Replace vr_values with range_query.
(get_stridx): Same.
(dump_strlen_info): Same.
(get_range_strlen_dynamic): Adjust for range_query API.
(set_strlen_range): Same
(maybe_warn_overflow): Replace vr_values with range_query.
(handle_builtin_strcpy): Same.
(maybe_diag_stxncpy_trunc): Add FIXME comment.
(handle_builtin_memcpy): Replace vr_values with range_query.
(handle_builtin_memset): Same.
(get_len_or_size): Same.
(strxcmp_eqz_result): Same.
(handle_builtin_string_cmp): Same.
(count_nonzero_bytes_addr): Same, plus adjust for range_query API.
(count_nonzero_bytes): Replace vr_values with range_query.
(handle_store): Same.
(strlen_check_and_optimize_call): Same.
(handle_integral_assign): Same.
(check_and_optimize_stmt): Same.
* tree-ssa-strlen.h (class vr_values): Remove.
(get_range): Replace vr_values with range_query.
(get_range_strlen_dynamic): Same.
(handle_printf_call): Same.
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index 8f2662b..f91266e 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -183,7 +183,8 @@ static void maybe_emit_chk_warning (tree, enum built_in_function); static void maybe_emit_sprintf_chk_warning (tree, enum built_in_function); static void maybe_emit_free_warning (tree); static tree fold_builtin_object_size (tree, tree); -static bool get_range (tree, signop, offset_int[2], const vr_values * = NULL); +static bool get_range (tree, gimple *, signop, offset_int[2], + range_query * = NULL); static bool check_read_access (tree, tree, tree = NULL_TREE, int = 1); unsigned HOST_WIDE_INT target_newline; @@ -4152,7 +4153,7 @@ check_read_access (tree exp, tree src, tree bound /* = NULL_TREE */, tree gimple_call_alloc_size (gimple *stmt, wide_int rng1[2] /* = NULL */, - const vr_values *rvals /* = NULL */) + range_query *rvals /* = NULL */) { if (!stmt) return NULL_TREE; @@ -4206,7 +4207,7 @@ gimple_call_alloc_size (gimple *stmt, wide_int rng1[2] /* = NULL */, const int prec = ADDR_MAX_PRECISION; const tree size_max = TYPE_MAX_VALUE (sizetype); - if (!get_range (size, rng1, rvals)) + if (!get_range (size, stmt, rng1, rvals)) { /* Use the full non-negative range on failure. */ rng1[0] = wi::zero (prec); @@ -4220,7 +4221,7 @@ gimple_call_alloc_size (gimple *stmt, wide_int rng1[2] /* = NULL */, of the upper bounds as a constant. Ignore anti-ranges. */ tree n = argidx2 < nargs ? gimple_call_arg (stmt, argidx2) : integer_one_node; wide_int rng2[2]; - if (!get_range (n, rng2, rvals)) + if (!get_range (n, stmt, rng2, rvals)) { /* As above, use the full non-negative range on failure. */ rng2[0] = wi::zero (prec); @@ -4252,8 +4253,7 @@ gimple_call_alloc_size (gimple *stmt, wide_int rng1[2] /* = NULL */, Return the function parameter on success and null otherwise. */ tree -gimple_parm_array_size (tree ptr, wide_int rng[2], - const vr_values * /* = NULL */) +gimple_parm_array_size (tree ptr, wide_int rng[2], range_query * /* = NULL */) { /* For a function argument try to determine the byte size of the array from the current function declaratation (e.g., attribute access or @@ -4305,11 +4305,11 @@ gimple_parm_array_size (tree ptr, wide_int rng[2], result but accepts offset_int instead. */ static bool -get_range (tree x, signop sgn, offset_int r[2], - const vr_values *rvals /* = NULL */) +get_range (tree x, gimple *stmt, signop sgn, offset_int r[2], + range_query *rvals /* = NULL */) { wide_int wr[2]; - if (!get_range (x, wr, rvals)) + if (!get_range (x, stmt, wr, rvals)) return false; r[0] = offset_int::from (wr[0], sgn); @@ -4333,7 +4333,7 @@ get_range (tree x, signop sgn, offset_int r[2], static bool compute_objsize (tree ptr, int ostype, access_ref *pref, - bitmap *visited, const vr_values *rvals /* = NULL */) + bitmap *visited, range_query *rvals /* = NULL */) { const bool addr = TREE_CODE (ptr) == ADDR_EXPR; if (addr) @@ -4431,7 +4431,7 @@ compute_objsize (tree ptr, int ostype, access_ref *pref, offset_int orng[2]; tree off = TREE_OPERAND (ptr, 1); - if (!get_range (off, SIGNED, orng, rvals)) + if (!get_range (off, NULL, SIGNED, orng, rvals)) /* Fail unless the size of the object is zero. */ return pref->sizrng[0] == 0 && pref->sizrng[0] == pref->sizrng[1]; @@ -4527,7 +4527,7 @@ compute_objsize (tree ptr, int ostype, access_ref *pref, offset to the maximum. */ offset_int orng[2]; tree off = gimple_assign_rhs2 (stmt); - if (!get_range (off, SIGNED, orng, rvals)) + if (!get_range (off, stmt, SIGNED, orng, rvals)) { orng[0] = wi::to_offset (TYPE_MIN_VALUE (ptrdiff_type_node)); orng[1] = wi::to_offset (TYPE_MAX_VALUE (ptrdiff_type_node)); @@ -4551,7 +4551,7 @@ compute_objsize (tree ptr, int ostype, access_ref *pref, && !array_at_struct_end_p (ptr)) { if (tree size = TYPE_SIZE_UNIT (type)) - return get_range (size, UNSIGNED, pref->sizrng, rvals); + return get_range (size, NULL, UNSIGNED, pref->sizrng, rvals); } return false; @@ -4562,7 +4562,7 @@ compute_objsize (tree ptr, int ostype, access_ref *pref, tree compute_objsize (tree ptr, int ostype, access_ref *pref, - const vr_values *rvals /* = NULL */) + range_query *rvals /* = NULL */) { bitmap visited = NULL; @@ -4603,7 +4603,7 @@ compute_objsize (tree ptr, int ostype, access_ref *pref, tree compute_objsize (tree ptr, int ostype, tree *pdecl /* = NULL */, - tree *poff /* = NULL */, const vr_values *rvals /* = NULL */) + tree *poff /* = NULL */, class range_query *rvals /* = NULL */) { /* Set the initial offsets to zero and size to negative to indicate none has been computed yet. */ |