diff options
author | Martin Sebor <msebor@redhat.com> | 2021-06-24 19:22:06 -0600 |
---|---|---|
committer | Martin Sebor <msebor@redhat.com> | 2021-06-24 19:30:47 -0600 |
commit | e9e2bad7251477db92ab9ebcdc010f9282dd9890 (patch) | |
tree | 1cefadb261cd37cdf95da17157209feab279dbb8 /gcc/tree-ssa-strlen.c | |
parent | 65870e75616ee4359d1c13b99be794e6a577bc65 (diff) | |
download | gcc-e9e2bad7251477db92ab9ebcdc010f9282dd9890.zip gcc-e9e2bad7251477db92ab9ebcdc010f9282dd9890.tar.gz gcc-e9e2bad7251477db92ab9ebcdc010f9282dd9890.tar.bz2 |
middle-end: add support for per-location warning groups.
gcc/ChangeLog:
* builtins.c (warn_string_no_nul): Replace uses of TREE_NO_WARNING,
gimple_no_warning_p and gimple_set_no_warning with
warning_suppressed_p, and suppress_warning.
(c_strlen): Same.
(maybe_warn_for_bound): Same.
(warn_for_access): Same.
(check_access): Same.
(expand_builtin_strncmp): Same.
(fold_builtin_varargs): Same.
* calls.c (maybe_warn_nonstring_arg): Same.
(maybe_warn_rdwr_sizes): Same.
* cfgexpand.c (expand_call_stmt): Same.
* cgraphunit.c (check_global_declaration): Same.
* fold-const.c (fold_undefer_overflow_warnings): Same.
(fold_truth_not_expr): Same.
(fold_unary_loc): Same.
(fold_checksum_tree): Same.
* gimple-array-bounds.cc (array_bounds_checker::check_array_ref): Same.
(array_bounds_checker::check_mem_ref): Same.
(array_bounds_checker::check_addr_expr): Same.
(array_bounds_checker::check_array_bounds): Same.
* gimple-expr.c (copy_var_decl): Same.
* gimple-fold.c (gimple_fold_builtin_strcpy): Same.
(gimple_fold_builtin_strncat): Same.
(gimple_fold_builtin_stxcpy_chk): Same.
(gimple_fold_builtin_stpcpy): Same.
(gimple_fold_builtin_sprintf): Same.
(fold_stmt_1): Same.
* gimple-ssa-isolate-paths.c (diag_returned_locals): Same.
* gimple-ssa-nonnull-compare.c (do_warn_nonnull_compare): Same.
* gimple-ssa-sprintf.c (handle_printf_call): Same.
* gimple-ssa-store-merging.c (imm_store_chain_info::output_merged_store): Same.
* gimple-ssa-warn-restrict.c (maybe_diag_overlap): Same.
* gimple-ssa-warn-restrict.h: Adjust declarations.
(maybe_diag_access_bounds): Replace uses of TREE_NO_WARNING,
gimple_no_warning_p and gimple_set_no_warning with
warning_suppressed_p, and suppress_warning.
(check_call): Same.
(check_bounds_or_overlap): Same.
* gimple.c (gimple_build_call_from_tree): Same.
* gimplify.c (gimplify_return_expr): Same.
(gimplify_cond_expr): Same.
(gimplify_modify_expr_complex_part): Same.
(gimplify_modify_expr): Same.
(gimple_push_cleanup): Same.
(gimplify_expr): Same.
* omp-expand.c (expand_omp_for_generic): Same.
(expand_omp_taskloop_for_outer): Same.
* omp-low.c (lower_rec_input_clauses): Same.
(lower_lastprivate_clauses): Same.
(lower_send_clauses): Same.
(lower_omp_target): Same.
* tree-cfg.c (pass_warn_function_return::execute): Same.
* tree-complex.c (create_one_component_var): Same.
* tree-inline.c (remap_gimple_op_r): Same.
(copy_tree_body_r): Same.
(declare_return_variable): Same.
(expand_call_inline): Same.
* tree-nested.c (lookup_field_for_decl): Same.
* tree-sra.c (create_access_replacement): Same.
(generate_subtree_copies): Same.
* tree-ssa-ccp.c (pass_post_ipa_warn::execute): Same.
* tree-ssa-forwprop.c (combine_cond_expr_cond): Same.
* tree-ssa-loop-ch.c (ch_base::copy_headers): Same.
* tree-ssa-loop-im.c (execute_sm): Same.
* tree-ssa-phiopt.c (cond_store_replacement): Same.
* tree-ssa-strlen.c (maybe_warn_overflow): Same.
(handle_builtin_strcpy): Same.
(maybe_diag_stxncpy_trunc): Same.
(handle_builtin_stxncpy_strncat): Same.
(handle_builtin_strcat): Same.
* tree-ssa-uninit.c (get_no_uninit_warning): Same.
(set_no_uninit_warning): Same.
(uninit_undefined_value_p): Same.
(warn_uninit): Same.
(maybe_warn_operand): Same.
* tree-vrp.c (compare_values_warnv): Same.
* vr-values.c (vr_values::extract_range_for_var_from_comparison_expr): Same.
(test_for_singularity): Same.
* gimple.h (warning_suppressed_p): New function.
(suppress_warning): Same.
(copy_no_warning): Same.
(gimple_set_block): Call gimple_set_location.
(gimple_set_location): Call copy_warning.
Diffstat (limited to 'gcc/tree-ssa-strlen.c')
-rw-r--r-- | gcc/tree-ssa-strlen.c | 68 |
1 files changed, 33 insertions, 35 deletions
diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index 6add8c9..13ea107 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -1938,7 +1938,7 @@ maybe_warn_overflow (gimple *stmt, tree len, pointer_query &ptr_qry, strinfo *si = NULL, bool plus_one = false, bool rawmem = false) { - if (!len || gimple_no_warning_p (stmt)) + if (!len || warning_suppressed_p (stmt, OPT_Wstringop_overflow_)) return; /* The DECL of the function performing the write if it is done @@ -1957,7 +1957,7 @@ maybe_warn_overflow (gimple *stmt, tree len, pointer_query &ptr_qry, else return; - if (TREE_NO_WARNING (dest)) + if (warning_suppressed_p (dest, OPT_Wstringop_overflow_)) return; const int ostype = rawmem ? 0 : 1; @@ -2101,7 +2101,7 @@ maybe_warn_overflow (gimple *stmt, tree len, pointer_query &ptr_qry, if (!warned) return; - gimple_set_no_warning (stmt, true); + suppress_warning (stmt, OPT_Wstringop_overflow_); aref.inform_access (access_write_only); } @@ -2624,16 +2624,16 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi, len = fold_convert_loc (loc, type, unshare_expr (srclen)); len = fold_build2_loc (loc, PLUS_EXPR, type, len, build_int_cst (type, 1)); - /* Set the no-warning bit on the transformed statement? */ - bool set_no_warning = false; + /* Disable warning for the transformed statement? */ + opt_code no_warning_opt = no_warning; - if (const strinfo *chksi = olddsi ? olddsi : dsi) - if (si - && check_bounds_or_overlap (stmt, chksi->ptr, si->ptr, NULL_TREE, len)) - { - gimple_set_no_warning (stmt, true); - set_no_warning = true; - } + if (const strinfo *chksi = si ? olddsi ? olddsi : dsi : NULL) + { + no_warning_opt = check_bounds_or_overlap (stmt, chksi->ptr, si->ptr, + NULL_TREE, len); + if (no_warning_opt) + suppress_warning (stmt, no_warning_opt); + } if (fn == NULL_TREE) return; @@ -2667,8 +2667,8 @@ handle_builtin_strcpy (enum built_in_function bcode, gimple_stmt_iterator *gsi, else if (dump_file && (dump_flags & TDF_DETAILS) != 0) fprintf (dump_file, "not possible.\n"); - if (set_no_warning) - gimple_set_no_warning (stmt, true); + if (no_warning_opt) + suppress_warning (stmt, no_warning_opt); } /* Check the size argument to the built-in forms of stpncpy and strncpy @@ -2796,7 +2796,7 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt, pointer_query *ptr_qry /* = NULL */) { gimple *stmt = gsi_stmt (gsi); - if (gimple_no_warning_p (stmt)) + if (warning_suppressed_p (stmt, OPT_Wstringop_truncation)) return false; wide_int cntrange[2]; @@ -3156,9 +3156,10 @@ handle_builtin_stxncpy_strncat (bool append_p, gimple_stmt_iterator *gsi) else srclenp1 = NULL_TREE; - if (check_bounds_or_overlap (stmt, dst, src, dstlenp1, srclenp1)) + opt_code opt = check_bounds_or_overlap (stmt, dst, src, dstlenp1, srclenp1); + if (opt != no_warning) { - gimple_set_no_warning (stmt, true); + suppress_warning (stmt, opt); return; } @@ -3169,7 +3170,7 @@ handle_builtin_stxncpy_strncat (bool append_p, gimple_stmt_iterator *gsi) if (!pss || pss->first <= 0) { if (maybe_diag_stxncpy_trunc (*gsi, src, len)) - gimple_set_no_warning (stmt, true); + suppress_warning (stmt, OPT_Wstringop_truncation); return; } @@ -3206,8 +3207,8 @@ handle_builtin_stxncpy_strncat (bool append_p, gimple_stmt_iterator *gsi) /* Issue -Wstringop-overflow when appending or when writing into a destination of a known size. Otherwise, when copying into a destination of an unknown size, it's truncation. */ - int opt = (append_p || dstsize - ? OPT_Wstringop_overflow_ : OPT_Wstringop_truncation); + opt_code opt = (append_p || dstsize + ? OPT_Wstringop_overflow_ : OPT_Wstringop_truncation); warned = warning_at (callloc, opt, "%G%qD specified bound depends on the length " "of the source argument", @@ -3448,8 +3449,8 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi, srclen = get_string_length (si); } - /* Set the no-warning bit on the transformed statement? */ - bool set_no_warning = false; + /* Disable warning for the transformed statement? */ + opt_code no_warning_opt = no_warning; if (dsi == NULL || get_string_length (dsi) == NULL_TREE) { @@ -3466,12 +3467,10 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi, } tree sptr = si && si->ptr ? si->ptr : src; - - if (check_bounds_or_overlap (stmt, dst, sptr, NULL_TREE, slen)) - { - gimple_set_no_warning (stmt, true); - set_no_warning = true; - } + no_warning_opt = check_bounds_or_overlap (stmt, dst, sptr, NULL_TREE, + slen); + if (no_warning_opt) + suppress_warning (stmt, no_warning_opt); } /* strcat (p, q) can be transformed into @@ -3578,11 +3577,10 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi, tree dstsize = fold_build2 (PLUS_EXPR, type, dstlen, one); tree sptr = si && si->ptr ? si->ptr : src; - if (check_bounds_or_overlap (stmt, dst, sptr, dstsize, srcsize)) - { - gimple_set_no_warning (stmt, true); - set_no_warning = true; - } + no_warning_opt = check_bounds_or_overlap (stmt, dst, sptr, dstsize, + srcsize); + if (no_warning_opt) + suppress_warning (stmt, no_warning_opt); } tree len = NULL_TREE; @@ -3648,8 +3646,8 @@ handle_builtin_strcat (enum built_in_function bcode, gimple_stmt_iterator *gsi, else if (dump_file && (dump_flags & TDF_DETAILS) != 0) fprintf (dump_file, "not possible.\n"); - if (set_no_warning) - gimple_set_no_warning (stmt, true); + if (no_warning_opt) + suppress_warning (stmt, no_warning_opt); } /* Handle a call to an allocation function like alloca, malloc or calloc, |