Commit 55ace4d1 by Jeff Law

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.
parent 3a0e583b
2020-03-05 Jeff Law <law@redhat.com>
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.
2020-03-05 Jakub Jelinek <jakub@redhat.com> 2020-03-05 Jakub Jelinek <jakub@redhat.com>
PR target/94046 PR target/94046
......
...@@ -1692,10 +1692,11 @@ maybe_diag_overlap (location_t loc, gimple *call, builtin_access &acs) ...@@ -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. */ has been issued, or would have been issued if DO_WARN had been true. */
static bool 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, const builtin_memref &ref, offset_int wroff,
bool do_warn) bool do_warn)
{ {
location_t loc = gimple_or_expr_nonartificial_location (call, ref.ptr);
const offset_int maxobjsize = ref.maxobjsize; const offset_int maxobjsize = ref.maxobjsize;
/* Check for excessive size first and regardless of warning options /* 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, ...@@ -1711,11 +1712,6 @@ maybe_diag_access_bounds (location_t loc, gimple *call, tree func, int strict,
if (warn_stringop_overflow) 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]) if (ref.sizrange[0] == ref.sizrange[1])
return warning_at (loc, OPT_Wstringop_overflow_, return warning_at (loc, OPT_Wstringop_overflow_,
"%G%qD specified bound %wu " "%G%qD specified bound %wu "
...@@ -1754,11 +1750,6 @@ maybe_diag_access_bounds (location_t loc, gimple *call, tree func, int strict, ...@@ -1754,11 +1750,6 @@ maybe_diag_access_bounds (location_t loc, gimple *call, tree func, int strict,
|| (ref.ref && TREE_NO_WARNING (ref.ref))) || (ref.ref && TREE_NO_WARNING (ref.ref)))
return false; 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]; char rangestr[2][64];
if (ooboff[0] == ooboff[1] if (ooboff[0] == ooboff[1]
|| (ooboff[0] != ref.offrange[0] || (ooboff[0] != ref.offrange[0]
...@@ -2018,9 +2009,6 @@ check_bounds_or_overlap (gimple *call, tree dst, tree src, tree dstsize, ...@@ -2018,9 +2009,6 @@ check_bounds_or_overlap (gimple *call, tree dst, tree src, tree dstsize,
tree srcsize, bool bounds_only /* = false */, tree srcsize, bool bounds_only /* = false */,
bool do_warn /* = true */) 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); tree func = gimple_call_fndecl (call);
builtin_memref dstref (dst, dstsize); builtin_memref dstref (dst, dstsize);
...@@ -2041,8 +2029,8 @@ check_bounds_or_overlap (gimple *call, tree dst, tree src, tree 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 /* Validate offsets to each reference before the access first to make
sure they are within the bounds of the destination object if its sure they are within the bounds of the destination object if its
size is known, or PTRDIFF_MAX otherwise. */ size is known, or PTRDIFF_MAX otherwise. */
if (maybe_diag_access_bounds (loc, call, func, strict, dstref, wroff, do_warn) if (maybe_diag_access_bounds (call, func, strict, dstref, wroff, do_warn)
|| maybe_diag_access_bounds (loc, call, func, strict, srcref, 0, do_warn)) || maybe_diag_access_bounds (call, func, strict, srcref, 0, do_warn))
{ {
if (do_warn) if (do_warn)
gimple_set_no_warning (call, true); gimple_set_no_warning (call, true);
...@@ -2066,6 +2054,7 @@ check_bounds_or_overlap (gimple *call, tree dst, tree src, tree dstsize, ...@@ -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)) if (operand_equal_p (dst, src, 0))
{ {
/* Issue -Wrestrict unless the pointers are null (those do /* Issue -Wrestrict unless the pointers are null (those do
......
...@@ -3285,6 +3285,19 @@ gimple_inexpensive_call_p (gcall *stmt) ...@@ -3285,6 +3285,19 @@ gimple_inexpensive_call_p (gcall *stmt)
return false; return false;
} }
/* Return a non-artificial location for STMT. If STMT does not have
location information, get the location from EXPR. */
location_t
gimple_or_expr_nonartificial_location (gimple *stmt, tree)
{
location_t loc = gimple_nonartificial_location (stmt);
if (loc == UNKNOWN_LOCATION && EXPR_HAS_LOCATION (expr))
loc = tree_nonartificial_location (expr);
return expansion_point_location_if_in_system_header (loc);
}
#if CHECKING_P #if CHECKING_P
namespace selftest { namespace selftest {
......
...@@ -1633,6 +1633,8 @@ extern void gimple_seq_discard (gimple_seq); ...@@ -1633,6 +1633,8 @@ extern void gimple_seq_discard (gimple_seq);
extern void maybe_remove_unused_call_args (struct function *, gimple *); extern void maybe_remove_unused_call_args (struct function *, gimple *);
extern bool gimple_inexpensive_call_p (gcall *); extern bool gimple_inexpensive_call_p (gcall *);
extern bool stmt_can_terminate_bb_p (gimple *); extern bool stmt_can_terminate_bb_p (gimple *);
extern location_t gimple_or_expr_nonartificial_location (gimple *, tree);
/* Formal (expression) temporary table handling: multiple occurrences of /* Formal (expression) temporary table handling: multiple occurrences of
the same scalar expression are evaluated into the same temporary. */ the same scalar expression are evaluated into the same temporary. */
......
2020-03-05 Jeff Law <law@redhat.com>
PR tree-optimization/91890
* gcc.dg/pragma-diag-8.c: New test.
2020-03-05 Jakub Jelinek <jakub@redhat.com> 2020-03-05 Jakub Jelinek <jakub@redhat.com>
PR target/94046 PR target/94046
......
/* { dg-do compile } */
/* { dg-options "-O2 -Wall" } */
char one[50];
char two[50];
void
test_strncat (void)
{
(void) __builtin_strcpy (one, "gh");
(void) __builtin_strcpy (two, "ef");
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-overflow="
#pragma GCC diagnostic ignored "-Warray-bounds"
(void) __builtin_strncat (one, two, 99);
#pragma GCC diagnostic pop
}
...@@ -2129,11 +2129,7 @@ maybe_warn_overflow (gimple *stmt, tree len, ...@@ -2129,11 +2129,7 @@ maybe_warn_overflow (gimple *stmt, tree len,
|| !si || !is_strlen_related_p (si->ptr, len))) || !si || !is_strlen_related_p (si->ptr, len)))
return; return;
location_t loc = gimple_nonartificial_location (stmt); location_t loc = gimple_or_expr_nonartificial_location (stmt, dest);
if (loc == UNKNOWN_LOCATION && dest && EXPR_HAS_LOCATION (dest))
loc = tree_nonartificial_location (dest);
loc = expansion_point_location_if_in_system_header (loc);
bool warned = false; bool warned = false;
if (wi::leu_p (lenrng[0], spcrng[1])) if (wi::leu_p (lenrng[0], spcrng[1]))
{ {
...@@ -3189,9 +3185,7 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt) ...@@ -3189,9 +3185,7 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt)
} }
} }
location_t callloc = gimple_nonartificial_location (stmt); location_t callloc = gimple_or_expr_nonartificial_location (stmt, dst);
callloc = expansion_point_location_if_in_system_header (callloc);
tree func = gimple_call_fndecl (stmt); tree func = gimple_call_fndecl (stmt);
if (lenrange[0] != 0 || !wi::neg_p (lenrange[1])) if (lenrange[0] != 0 || !wi::neg_p (lenrange[1]))
...@@ -3403,8 +3397,7 @@ handle_builtin_stxncpy_strncat (bool append_p, gimple_stmt_iterator *gsi) ...@@ -3403,8 +3397,7 @@ handle_builtin_stxncpy_strncat (bool append_p, gimple_stmt_iterator *gsi)
to strlen(S)). */ to strlen(S)). */
strinfo *silen = get_strinfo (pss->first); strinfo *silen = get_strinfo (pss->first);
location_t callloc = gimple_nonartificial_location (stmt); location_t callloc = gimple_or_expr_nonartificial_location (stmt, dst);
callloc = expansion_point_location_if_in_system_header (callloc);
tree func = gimple_call_fndecl (stmt); tree func = gimple_call_fndecl (stmt);
...@@ -4331,10 +4324,7 @@ maybe_warn_pointless_strcmp (gimple *stmt, HOST_WIDE_INT bound, ...@@ -4331,10 +4324,7 @@ maybe_warn_pointless_strcmp (gimple *stmt, HOST_WIDE_INT bound,
/* FIXME: Include a note pointing to the declaration of the smaller /* FIXME: Include a note pointing to the declaration of the smaller
array. */ array. */
location_t stmt_loc = gimple_nonartificial_location (stmt); location_t stmt_loc = gimple_or_expr_nonartificial_location (stmt, lhs);
if (stmt_loc == UNKNOWN_LOCATION && EXPR_HAS_LOCATION (lhs))
stmt_loc = tree_nonartificial_location (lhs);
stmt_loc = expansion_point_location_if_in_system_header (stmt_loc);
tree callee = gimple_call_fndecl (stmt); tree callee = gimple_call_fndecl (stmt);
bool warned = false; bool warned = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment