gimple-ssa-warn-access.cc: add missing auto_diagnostic_group

Whilst working on SARIF output I noticed some places where followup notes
weren't being properly associated with their warnings in
gcc/gimple-ssa-warn-access.cc.

Fixed thusly.

gcc/ChangeLog:
	* gimple-ssa-warn-access.cc (warn_string_no_nul): Add
	auto_diagnostic_group to group any warning with its note.
	(maybe_warn_for_bound): Likewise.
	(check_access): Likewise.
	(warn_dealloc_offset): Likewise.
	(pass_waccess::maybe_warn_memmodel): Likewise.
	(pass_waccess::maybe_check_dealloc_call): Likewise.
	(pass_waccess::warn_invalid_pointer): Likewise.
	(pass_waccess::check_dangling_stores): Likewise.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
This commit is contained in:
David Malcolm 2022-06-16 17:37:15 -04:00
parent d3e0da54c1
commit 6ab98d8b58

View File

@ -160,6 +160,8 @@ warn_string_no_nul (location_t loc, GimpleOrTree expr, const char *fname,
(unsigned long long) bndrng[1].to_uhwi ());
}
auto_diagnostic_group d;
const tree maxobjsize = max_object_size ();
const wide_int maxsiz = wi::to_wide (maxobjsize);
if (expr)
@ -718,6 +720,7 @@ maybe_warn_for_bound (opt_code opt, location_t loc, GimpleOrTree exp, tree func,
maybe = false;
}
auto_diagnostic_group d;
if (tree_int_cst_lt (maxobjsize, bndrng[0]))
{
if (bndrng[0] == bndrng[1])
@ -1387,6 +1390,7 @@ check_access (GimpleOrTree exp, tree dstwrite,
&& warning_suppressed_p (pad->dst.ref, opt)))
return false;
auto_diagnostic_group d;
location_t loc = get_location (exp);
bool warned = false;
if (dstwrite == slen && at_least_one)
@ -1505,6 +1509,7 @@ check_access (GimpleOrTree exp, tree dstwrite,
const bool read
= mode == access_read_only || mode == access_read_write;
const bool maybe = pad && pad->dst.parmarray;
auto_diagnostic_group d;
if (warn_for_access (loc, func, exp, opt, range, slen, false, read,
maybe))
{
@ -2019,6 +2024,7 @@ warn_dealloc_offset (location_t loc, gimple *call, const access_ref &aref)
(long long)aref.offrng[1].to_shwi ());
}
auto_diagnostic_group d;
if (!warning_at (loc, OPT_Wfree_nonheap_object,
"%qD called on pointer %qE with nonzero offset%s",
dealloc_decl, aref.ref, offstr))
@ -2902,6 +2908,7 @@ pass_waccess::maybe_warn_memmodel (gimple *stmt, tree ord_sucs,
if (!is_valid)
{
bool warned = false;
auto_diagnostic_group d;
if (const char *modname = memmodel_name (sucs))
warned = warning_at (loc, OPT_Winvalid_memory_model,
"invalid memory model %qs for %qD",
@ -2935,6 +2942,7 @@ pass_waccess::maybe_warn_memmodel (gimple *stmt, tree ord_sucs,
{
/* If both memory model arguments are valid but their combination
is not, use their names in the warning. */
auto_diagnostic_group d;
if (!warning_at (loc, OPT_Winvalid_memory_model,
"invalid failure memory model %qs for %qD",
failname, fndecl))
@ -2955,6 +2963,7 @@ pass_waccess::maybe_warn_memmodel (gimple *stmt, tree ord_sucs,
{
/* If both memory model arguments are valid but their combination
is not, use their names in the warning. */
auto_diagnostic_group d;
if (!warning_at (loc, OPT_Winvalid_memory_model,
"failure memory model %qs cannot be stronger "
"than success memory model %qs for %qD",
@ -3684,13 +3693,16 @@ pass_waccess::maybe_check_dealloc_call (gcall *call)
if (DECL_P (ref) || EXPR_P (ref))
{
/* Diagnose freeing a declared object. */
if (aref.ref_declared ()
&& warning_at (loc, OPT_Wfree_nonheap_object,
"%qD called on unallocated object %qD",
dealloc_decl, ref))
if (aref.ref_declared ())
{
inform (get_location (ref), "declared here");
return;
auto_diagnostic_group d;
if (warning_at (loc, OPT_Wfree_nonheap_object,
"%qD called on unallocated object %qD",
dealloc_decl, ref))
{
inform (get_location (ref), "declared here");
return;
}
}
/* Diagnose freeing a pointer that includes a positive offset.
@ -3702,6 +3714,7 @@ pass_waccess::maybe_check_dealloc_call (gcall *call)
}
else if (CONSTANT_CLASS_P (ref))
{
auto_diagnostic_group d;
if (warning_at (loc, OPT_Wfree_nonheap_object,
"%qD called on a pointer to an unallocated "
"object %qE", dealloc_decl, ref))
@ -3904,6 +3917,7 @@ pass_waccess::warn_invalid_pointer (tree ref, gimple *use_stmt,
const tree inval_decl = gimple_call_fndecl (inval_stmt);
auto_diagnostic_group d;
if ((ref && warning_at (use_loc, OPT_Wuse_after_free,
(maybe
? G_("pointer %qE may be used after %qD")
@ -3929,6 +3943,7 @@ pass_waccess::warn_invalid_pointer (tree ref, gimple *use_stmt,
if (DECL_NAME (var))
{
auto_diagnostic_group d;
if ((ref
&& warning_at (use_loc, OPT_Wdangling_pointer_,
(maybe
@ -4576,6 +4591,7 @@ pass_waccess::check_dangling_stores (basic_block bb,
if (!is_auto_decl (rhs_ref.ref))
continue;
auto_diagnostic_group d;
location_t loc = gimple_location (stmt);
if (warning_at (loc, OPT_Wdangling_pointer_,
"storing the address of local variable %qD in %qE",