diff options
author | Jeff Law <law@redhat.com> | 2020-03-05 14:01:30 -0700 |
---|---|---|
committer | Jeff Law <law@redhat.com> | 2020-03-05 14:01:30 -0700 |
commit | 55ace4d14637866466498ed43e02d6f95af98f10 (patch) | |
tree | 0bcdec4218fa6088b63ee2eb78903424aeb38f58 /gcc/gimple-ssa-warn-restrict.c | |
parent | 3a0e583bf17240e55fee7b490e13753cca52bfe1 (diff) | |
download | gcc-55ace4d14637866466498ed43e02d6f95af98f10.zip gcc-55ace4d14637866466498ed43e02d6f95af98f10.tar.gz gcc-55ace4d14637866466498ed43e02d6f95af98f10.tar.bz2 |
Fix location maybe_diag_overlap passes to diagnostics so that diagnostic pragmas work better.
PR tree-optimization/91890
* gimple-ssa-warn-restrict.c (maybe_diag_overlap): Remove LOC argument.
Use gimple_or_expr_nonartificial_location.
(check_bounds_overlap): Drop LOC argument to maybe_diag_access_bounds.
Use gimple_or_expr_nonartificial_location.
* gimple.c (gimple_or_expr_nonartificial_location): New function.
* gimple.h (gimple_or_expr_nonartificial_location): Declare it.
* tree-ssa-strlen.c (maybe_warn_overflow): Use
gimple_or_expr_nonartificial_location.
(maybe_diag_stxncpy_trunc, handle_builtin_stxncpy_strncat): Likewise.
(maybe_warn_pointless_strcmp): Likewise.
* gcc.dg/pragma-diag-8.c: New test.
Diffstat (limited to 'gcc/gimple-ssa-warn-restrict.c')
-rw-r--r-- | gcc/gimple-ssa-warn-restrict.c | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/gcc/gimple-ssa-warn-restrict.c b/gcc/gimple-ssa-warn-restrict.c index 2c582a6..5e7e5d4 100644 --- a/gcc/gimple-ssa-warn-restrict.c +++ b/gcc/gimple-ssa-warn-restrict.c @@ -1692,10 +1692,11 @@ maybe_diag_overlap (location_t loc, gimple *call, builtin_access &acs) has been issued, or would have been issued if DO_WARN had been true. */ static bool -maybe_diag_access_bounds (location_t loc, gimple *call, tree func, int strict, +maybe_diag_access_bounds (gimple *call, tree func, int strict, const builtin_memref &ref, offset_int wroff, bool do_warn) { + location_t loc = gimple_or_expr_nonartificial_location (call, ref.ptr); const offset_int maxobjsize = ref.maxobjsize; /* Check for excessive size first and regardless of warning options @@ -1711,11 +1712,6 @@ maybe_diag_access_bounds (location_t loc, gimple *call, tree func, int strict, if (warn_stringop_overflow) { - if (EXPR_HAS_LOCATION (ref.ptr)) - loc = EXPR_LOCATION (ref.ptr); - - loc = expansion_point_location_if_in_system_header (loc); - if (ref.sizrange[0] == ref.sizrange[1]) return warning_at (loc, OPT_Wstringop_overflow_, "%G%qD specified bound %wu " @@ -1754,11 +1750,6 @@ maybe_diag_access_bounds (location_t loc, gimple *call, tree func, int strict, || (ref.ref && TREE_NO_WARNING (ref.ref))) return false; - if (EXPR_HAS_LOCATION (ref.ptr)) - loc = EXPR_LOCATION (ref.ptr); - - loc = expansion_point_location_if_in_system_header (loc); - char rangestr[2][64]; if (ooboff[0] == ooboff[1] || (ooboff[0] != ref.offrange[0] @@ -2018,9 +2009,6 @@ check_bounds_or_overlap (gimple *call, tree dst, tree src, tree dstsize, tree srcsize, bool bounds_only /* = false */, bool do_warn /* = true */) { - location_t loc = gimple_nonartificial_location (call); - loc = expansion_point_location_if_in_system_header (loc); - tree func = gimple_call_fndecl (call); builtin_memref dstref (dst, dstsize); @@ -2041,8 +2029,8 @@ check_bounds_or_overlap (gimple *call, tree dst, tree src, tree dstsize, /* Validate offsets to each reference before the access first to make sure they are within the bounds of the destination object if its size is known, or PTRDIFF_MAX otherwise. */ - if (maybe_diag_access_bounds (loc, call, func, strict, dstref, wroff, do_warn) - || maybe_diag_access_bounds (loc, call, func, strict, srcref, 0, do_warn)) + if (maybe_diag_access_bounds (call, func, strict, dstref, wroff, do_warn) + || maybe_diag_access_bounds (call, func, strict, srcref, 0, do_warn)) { if (do_warn) gimple_set_no_warning (call, true); @@ -2066,6 +2054,7 @@ check_bounds_or_overlap (gimple *call, tree dst, tree src, tree dstsize, } } + location_t loc = gimple_or_expr_nonartificial_location (call, dst); if (operand_equal_p (dst, src, 0)) { /* Issue -Wrestrict unless the pointers are null (those do |