On 6/30/21 9:39 AM, Martin Sebor wrote:
Ping. Attached is the same patch rebased on top the latest trunk.
Please see the attached patch instead. The previous one had typo
in it.
As discussed in the review of Aldy's recent changes to the backwards
threader, he has run into the same bug the patch fixes. Getting this
patch set reviewed and approved would be helpful in keeping him from
having to work around the bug.
https://gcc.gnu.org/pipermail/gcc/2021-June/236608.html
On 6/10/21 5:27 PM, Martin Sebor wrote:
This diff removes the uses of %G and %K from all warning_at() calls
throughout GCC front end and middle end. The inlining context is
included in diagnostic output whenever it's present.
Improve warning suppression for inlined functions.
Resolves:
PR middle-end/98871 - Cannot silence -Wmaybe-uninitialized at declaration site
PR middle-end/98512 - #pragma GCC diagnostic ignored ineffective in conjunction with alias attribute
gcc/ChangeLog:
* builtins.c (warn_string_no_nul): Remove %G.
(maybe_warn_for_bound): Same.
(warn_for_access): Same.
(check_access): Same.
(check_strncat_sizes): Same.
(expand_builtin_strncat): Same.
(expand_builtin_strncmp): Same.
(expand_builtin): Same.
(expand_builtin_object_size): Same.
(warn_dealloc_offset): Same.
(maybe_emit_free_warning): Same.
* calls.c (maybe_warn_alloc_args_overflow): Same.
(maybe_warn_nonstring_arg): Same.
(maybe_warn_rdwr_sizes): Same.
* expr.c (expand_expr_real_1): Remove %K.
* gimple-fold.c (gimple_fold_builtin_strncpy): Remove %G.
(gimple_fold_builtin_strncat): Same.
* gimple-ssa-sprintf.c (format_directive): Same.
(handle_printf_call): Same.
* gimple-ssa-warn-alloca.c (pass_walloca::execute): Same.
* gimple-ssa-warn-restrict.c (maybe_diag_overlap): Same.
(maybe_diag_access_bounds): Same. Call gimple_location.
(check_bounds_or_overlap): Same.
* trans-mem.c (ipa_tm_scan_irr_block): Remove %K. Simplify.
* tree-ssa-ccp.c (pass_post_ipa_warn::execute): Remove %G.
* tree-ssa-strlen.c (maybe_warn_overflow): Same.
(maybe_diag_stxncpy_trunc): Same.
(handle_builtin_stxncpy_strncat): Same.
(maybe_warn_pointless_strcmp): Same.
* tree-ssa-uninit.c (maybe_warn_operand): Same.
gcc/testsuite/ChangeLog:
* gcc.dg/Wfree-nonheap-object-4.c: Tighten up.
* gcc.dg/Wobjsize-1.c: Prune expected output.
* gcc.dg/Warray-bounds-71.c: New test.
* gcc.dg/Warray-bounds-71.h: New test.
* gcc.dg/Warray-bounds-72.c: New test.
* gcc.dg/Warray-bounds-73.c: New test.
* gcc.dg/Warray-bounds-74.c: New test.
* gcc.dg/Warray-bounds-75.c: New test.
* gcc.dg/Wfree-nonheap-object-5.c: New test.
* gcc.dg/pragma-diag-10.c: New test.
* gcc.dg/pragma-diag-9.c: New test.
* gcc.dg/uninit-suppress_3.c: New test.
diff --git a/gcc/builtins.c b/gcc/builtins.c
index e5e39386a93..e52fe4291c8 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -1126,30 +1126,30 @@ warn_string_no_nul (location_t loc, tree expr, const char *fname,
{
if (wi::ltu_p (maxsiz, bndrng[0]))
warned = warning_at (loc, opt,
- "%K%qD specified bound %s exceeds "
+ "%qD specified bound %s exceeds "
"maximum object size %E",
- expr, func, bndstr, maxobjsize);
+ func, bndstr, maxobjsize);
else
{
bool maybe = wi::to_wide (size) == bndrng[0];
warned = warning_at (loc, opt,
exact
- ? G_("%K%qD specified bound %s exceeds "
+ ? G_("%qD specified bound %s exceeds "
"the size %E of unterminated array")
: (maybe
- ? G_("%K%qD specified bound %s may "
+ ? G_("%qD specified bound %s may "
"exceed the size of at most %E "
"of unterminated array")
- : G_("%K%qD specified bound %s exceeds "
+ : G_("%qD specified bound %s exceeds "
"the size of at most %E "
"of unterminated array")),
- expr, func, bndstr, size);
+ func, bndstr, size);
}
}
else
warned = warning_at (loc, opt,
- "%K%qD argument missing terminating nul",
- expr, func);
+ "%qD argument missing terminating nul",
+ func);
}
else
{
@@ -3969,35 +3969,34 @@ maybe_warn_for_bound (opt_code opt, location_t loc, tree exp, tree func,
warned = (func
? warning_at (loc, opt,
(maybe
- ? G_("%K%qD specified bound %E may "
+ ? G_("%qD specified bound %E may "
"exceed maximum object size %E")
- : G_("%K%qD specified bound %E "
+ : G_("%qD specified bound %E "
"exceeds maximum object size %E")),
- exp, func, bndrng[0], maxobjsize)
+ func, bndrng[0], maxobjsize)
: warning_at (loc, opt,
(maybe
- ? G_("%Kspecified bound %E may "
+ ? G_("specified bound %E may "
"exceed maximum object size %E")
- : G_("%Kspecified bound %E "
+ : G_("specified bound %E "
"exceeds maximum object size %E")),
- exp, bndrng[0], maxobjsize));
+ bndrng[0], maxobjsize));
else
warned = (func
? warning_at (loc, opt,
(maybe
- ? G_("%K%qD specified bound [%E, %E] may "
+ ? G_("%qD specified bound [%E, %E] may "
"exceed maximum object size %E")
- : G_("%K%qD specified bound [%E, %E] "
+ : G_("%qD specified bound [%E, %E] "
"exceeds maximum object size %E")),
- exp, func,
- bndrng[0], bndrng[1], maxobjsize)
+ func, bndrng[0], bndrng[1], maxobjsize)
: warning_at (loc, opt,
(maybe
- ? G_("%Kspecified bound [%E, %E] may "
+ ? G_("specified bound [%E, %E] may "
"exceed maximum object size %E")
- : G_("%Kspecified bound [%E, %E] "
+ : G_("specified bound [%E, %E] "
"exceeds maximum object size %E")),
- exp, bndrng[0], bndrng[1], maxobjsize));
+ bndrng[0], bndrng[1], maxobjsize));
}
else if (!size || tree_int_cst_le (bndrng[0], size))
return false;
@@ -4005,34 +4004,34 @@ maybe_warn_for_bound (opt_code opt, location_t loc, tree exp, tree func,
warned = (func
? warning_at (loc, opt,
(maybe
- ? G_("%K%qD specified bound %E may exceed "
+ ? G_("%qD specified bound %E may exceed "
"source size %E")
- : G_("%K%qD specified bound %E exceeds "
+ : G_("%qD specified bound %E exceeds "
"source size %E")),
- exp, func, bndrng[0], size)
+ func, bndrng[0], size)
: warning_at (loc, opt,
(maybe
- ? G_("%Kspecified bound %E may exceed "
+ ? G_("specified bound %E may exceed "
"source size %E")
- : G_("%Kspecified bound %E exceeds "
+ : G_("specified bound %E exceeds "
"source size %E")),
- exp, bndrng[0], size));
+ bndrng[0], size));
else
warned = (func
? warning_at (loc, opt,
(maybe
- ? G_("%K%qD specified bound [%E, %E] may "
+ ? G_("%qD specified bound [%E, %E] may "
"exceed source size %E")
- : G_("%K%qD specified bound [%E, %E] exceeds "
+ : G_("%qD specified bound [%E, %E] exceeds "
"source size %E")),
- exp, func, bndrng[0], bndrng[1], size)
+ func, bndrng[0], bndrng[1], size)
: warning_at (loc, opt,
(maybe
- ? G_("%Kspecified bound [%E, %E] may exceed "
+ ? G_("specified bound [%E, %E] may exceed "
"source size %E")
- : G_("%Kspecified bound [%E, %E] exceeds "
+ : G_("specified bound [%E, %E] exceeds "
"source size %E")),
- exp, bndrng[0], bndrng[1], size));
+ bndrng[0], bndrng[1], size));
if (warned)
{
if (pad && pad->src.ref)
@@ -4057,35 +4056,34 @@ maybe_warn_for_bound (opt_code opt, location_t loc, tree exp, tree func,
warned = (func
? warning_at (loc, opt,
(maybe
- ? G_("%K%qD specified size %E may "
+ ? G_("%qD specified size %E may "
"exceed maximum object size %E")
- : G_("%K%qD specified size %E "
+ : G_("%qD specified size %E "
"exceeds maximum object size %E")),
- exp, func, bndrng[0], maxobjsize)
+ func, bndrng[0], maxobjsize)
: warning_at (loc, opt,
(maybe
- ? G_("%Kspecified size %E may exceed "
+ ? G_("specified size %E may exceed "
"maximum object size %E")
- : G_("%Kspecified size %E exceeds "
+ : G_("specified size %E exceeds "
"maximum object size %E")),
- exp, bndrng[0], maxobjsize));
+ bndrng[0], maxobjsize));
else
warned = (func
? warning_at (loc, opt,
(maybe
- ? G_("%K%qD specified size between %E and %E "
+ ? G_("%qD specified size between %E and %E "
"may exceed maximum object size %E")
- : G_("%K%qD specified size between %E and %E "
+ : G_("%qD specified size between %E and %E "
"exceeds maximum object size %E")),
- exp, func,
- bndrng[0], bndrng[1], maxobjsize)
+ func, bndrng[0], bndrng[1], maxobjsize)
: warning_at (loc, opt,
(maybe
- ? G_("%Kspecified size between %E and %E "
+ ? G_("specified size between %E and %E "
"may exceed maximum object size %E")
- : G_("%Kspecified size between %E and %E "
+ : G_("specified size between %E and %E "
"exceeds maximum object size %E")),
- exp, bndrng[0], bndrng[1], maxobjsize));
+ bndrng[0], bndrng[1], maxobjsize));
}
else if (!size || tree_int_cst_le (bndrng[0], size))
return false;
@@ -4093,34 +4091,34 @@ maybe_warn_for_bound (opt_code opt, location_t loc, tree exp, tree func,
warned = (func
? warning_at (loc, opt,
(maybe
- ? G_("%K%qD specified bound %E may exceed "
+ ? G_("%qD specified bound %E may exceed "
"destination size %E")
- : G_("%K%qD specified bound %E exceeds "
+ : G_("%qD specified bound %E exceeds "
"destination size %E")),
- exp, func, bndrng[0], size)
+ func, bndrng[0], size)
: warning_at (loc, opt,
(maybe
- ? G_("%Kspecified bound %E may exceed "
+ ? G_("specified bound %E may exceed "
"destination size %E")
- : G_("%Kspecified bound %E exceeds "
+ : G_("specified bound %E exceeds "
"destination size %E")),
- exp, bndrng[0], size));
+ bndrng[0], size));
else
warned = (func
? warning_at (loc, opt,
(maybe
- ? G_("%K%qD specified bound [%E, %E] may exceed "
+ ? G_("%qD specified bound [%E, %E] may exceed "
"destination size %E")
- : G_("%K%qD specified bound [%E, %E] exceeds "
+ : G_("%qD specified bound [%E, %E] exceeds "
"destination size %E")),
- exp, func, bndrng[0], bndrng[1], size)
+ func, bndrng[0], bndrng[1], size)
: warning_at (loc, opt,
(maybe
- ? G_("%Kspecified bound [%E, %E] exceeds "
+ ? G_("specified bound [%E, %E] exceeds "
"destination size %E")
- : G_("%Kspecified bound [%E, %E] exceeds "
+ : G_("specified bound [%E, %E] exceeds "
"destination size %E")),
- exp, bndrng[0], bndrng[1], size));
+ bndrng[0], bndrng[1], size));
if (warned)
{
@@ -4158,65 +4156,63 @@ warn_for_access (location_t loc, tree func, tree exp, int opt, tree range[2],
warned = (func
? warning_n (loc, opt, tree_to_uhwi (range[0]),
(maybe
- ? G_("%K%qD may access %E byte in a region "
+ ? G_("%qD may access %E byte in a region "
"of size %E")
- : G_("%K%qD accessing %E byte in a region "
+ : G_("%qD accessing %E byte in a region "
"of size %E")),
(maybe
- ? G_ ("%K%qD may access %E bytes in a region "
+ ? G_ ("%qD may access %E bytes in a region "
"of size %E")
- : G_ ("%K%qD accessing %E bytes in a region "
+ : G_ ("%qD accessing %E bytes in a region "
"of size %E")),
- exp, func, range[0], size)
+ func, range[0], size)
: warning_n (loc, opt, tree_to_uhwi (range[0]),
(maybe
- ? G_("%Kmay access %E byte in a region "
+ ? G_("may access %E byte in a region "
"of size %E")
- : G_("%Kaccessing %E byte in a region "
+ : G_("accessing %E byte in a region "
"of size %E")),
(maybe
- ? G_("%Kmay access %E bytes in a region "
+ ? G_("may access %E bytes in a region "
"of size %E")
- : G_("%Kaccessing %E bytes in a region "
+ : G_("accessing %E bytes in a region "
"of size %E")),
- exp, range[0], size));
+ range[0], size));
else if (tree_int_cst_sign_bit (range[1]))
{
/* Avoid printing the upper bound if it's invalid. */
warned = (func
? warning_at (loc, opt,
(maybe
- ? G_("%K%qD may access %E or more bytes "
+ ? G_("%qD may access %E or more bytes "
"in a region of size %E")
- : G_("%K%qD accessing %E or more bytes "
+ : G_("%qD accessing %E or more bytes "
"in a region of size %E")),
- exp, func, range[0], size)
+ func, range[0], size)
: warning_at (loc, opt,
(maybe
- ? G_("%Kmay access %E or more bytes "
+ ? G_("may access %E or more bytes "
"in a region of size %E")
- : G_("%Kaccessing %E or more bytes "
+ : G_("accessing %E or more bytes "
"in a region of size %E")),
- exp, range[0], size));
+ range[0], size));
}
else
warned = (func
? warning_at (loc, opt,
(maybe
- ? G_("%K%qD may access between %E and %E "
+ ? G_("%qD may access between %E and %E "
"bytes in a region of size %E")
- : G_("%K%qD accessing between %E and %E "
+ : G_("%qD accessing between %E and %E "
"bytes in a region of size %E")),
- exp, func, range[0], range[1],
- size)
+ func, range[0], range[1], size)
: warning_at (loc, opt,
(maybe
- ? G_("%Kmay access between %E and %E bytes "
+ ? G_("may access between %E and %E bytes "
"in a region of size %E")
- : G_("%Kaccessing between %E and %E bytes "
+ : G_("accessing between %E and %E bytes "
"in a region of size %E")),
- exp, range[0], range[1],
- size));
+ range[0], range[1], size));
return warned;
}
@@ -4226,69 +4222,67 @@ warn_for_access (location_t loc, tree func, tree exp, int opt, tree range[2],
warned = (func
? warning_n (loc, opt, tree_to_uhwi (range[0]),
(maybe
- ? G_("%K%qD may write %E byte into a region "
+ ? G_("%qD may write %E byte into a region "
"of size %E")
- : G_("%K%qD writing %E byte into a region "
+ : G_("%qD writing %E byte into a region "
"of size %E overflows the destination")),
(maybe
- ? G_("%K%qD may write %E bytes into a region "
+ ? G_("%qD may write %E bytes into a region "
"of size %E")
- : G_("%K%qD writing %E bytes into a region "
+ : G_("%qD writing %E bytes into a region "
"of size %E overflows the destination")),
- exp, func, range[0], size)
+ func, range[0], size)
: warning_n (loc, opt, tree_to_uhwi (range[0]),
(maybe
- ? G_("%Kmay write %E byte into a region "
+ ? G_("may write %E byte into a region "
"of size %E")
- : G_("%Kwriting %E byte into a region "
+ : G_("writing %E byte into a region "
"of size %E overflows the destination")),
(maybe
- ? G_("%Kmay write %E bytes into a region "
+ ? G_("may write %E bytes into a region "
"of size %E")
- : G_("%Kwriting %E bytes into a region "
+ : G_("writing %E bytes into a region "
"of size %E overflows the destination")),
- exp, range[0], size));
+ range[0], size));
else if (tree_int_cst_sign_bit (range[1]))
{
/* Avoid printing the upper bound if it's invalid. */
warned = (func
? warning_at (loc, opt,
(maybe
- ? G_("%K%qD may write %E or more bytes "
+ ? G_("%qD may write %E or more bytes "
"into a region of size %E")
- : G_("%K%qD writing %E or more bytes "
+ : G_("%qD writing %E or more bytes "
"into a region of size %E overflows "
"the destination")),
- exp, func, range[0], size)
+ func, range[0], size)
: warning_at (loc, opt,
(maybe
- ? G_("%Kmay write %E or more bytes into "
+ ? G_("may write %E or more bytes into "
"a region of size %E")
- : G_("%Kwriting %E or more bytes into "
+ : G_("writing %E or more bytes into "
"a region of size %E overflows "
"the destination")),
- exp, range[0], size));
+ range[0], size));
}
else
warned = (func
? warning_at (loc, opt,
(maybe
- ? G_("%K%qD may write between %E and %E bytes "
+ ? G_("%qD may write between %E and %E bytes "
"into a region of size %E")
- : G_("%K%qD writing between %E and %E bytes "
+ : G_("%qD writing between %E and %E bytes "
"into a region of size %E overflows "
"the destination")),
- exp, func, range[0], range[1],
- size)
+ func, range[0], range[1], size)
: warning_at (loc, opt,
(maybe
- ? G_("%Kmay write between %E and %E bytes "
+ ? G_("may write between %E and %E bytes "
"into a region of size %E")
- : G_("%Kwriting between %E and %E bytes "
+ : G_("writing between %E and %E bytes "
"into a region of size %E overflows "
"the destination")),
- exp, range[0], range[1],
- size));
+ range[0], range[1], size));
return warned;
}
@@ -4299,64 +4293,64 @@ warn_for_access (location_t loc, tree func, tree exp, int opt, tree range[2],
? warning_n (loc, OPT_Wstringop_overread,
tree_to_uhwi (range[0]),
(maybe
- ? G_("%K%qD may read %E byte from a region "
+ ? G_("%qD may read %E byte from a region "
"of size %E")
- : G_("%K%qD reading %E byte from a region "
+ : G_("%qD reading %E byte from a region "
"of size %E")),
(maybe
- ? G_("%K%qD may read %E bytes from a region "
+ ? G_("%qD may read %E bytes from a region "
"of size %E")
- : G_("%K%qD reading %E bytes from a region "
+ : G_("%qD reading %E bytes from a region "
"of size %E")),
- exp, func, range[0], size)
+ func, range[0], size)
: warning_n (loc, OPT_Wstringop_overread,
tree_to_uhwi (range[0]),
(maybe
- ? G_("%Kmay read %E byte from a region "
+ ? G_("may read %E byte from a region "
"of size %E")
- : G_("%Kreading %E byte from a region "
+ : G_("reading %E byte from a region "
"of size %E")),
(maybe
- ? G_("%Kmay read %E bytes from a region "
+ ? G_("may read %E bytes from a region "
"of size %E")
- : G_("%Kreading %E bytes from a region "
+ : G_("reading %E bytes from a region "
"of size %E")),
- exp, range[0], size));
+ range[0], size));
else if (tree_int_cst_sign_bit (range[1]))
{
/* Avoid printing the upper bound if it's invalid. */
warned = (func
? warning_at (loc, OPT_Wstringop_overread,
(maybe
- ? G_("%K%qD may read %E or more bytes "
+ ? G_("%qD may read %E or more bytes "
"from a region of size %E")
- : G_("%K%qD reading %E or more bytes "
+ : G_("%qD reading %E or more bytes "
"from a region of size %E")),
- exp, func, range[0], size)
+ func, range[0], size)
: warning_at (loc, OPT_Wstringop_overread,
(maybe
- ? G_("%Kmay read %E or more bytes "
+ ? G_("may read %E or more bytes "
"from a region of size %E")
- : G_("%Kreading %E or more bytes "
+ : G_("reading %E or more bytes "
"from a region of size %E")),
- exp, range[0], size));
+ range[0], size));
}
else
warned = (func
? warning_at (loc, OPT_Wstringop_overread,
(maybe
- ? G_("%K%qD may read between %E and %E bytes "
+ ? G_("%qD may read between %E and %E bytes "
"from a region of size %E")
- : G_("%K%qD reading between %E and %E bytes "
+ : G_("%qD reading between %E and %E bytes "
"from a region of size %E")),
- exp, func, range[0], range[1], size)
+ func, range[0], range[1], size)
: warning_at (loc, opt,
(maybe
- ? G_("%Kmay read between %E and %E bytes "
+ ? G_("may read between %E and %E bytes "
"from a region of size %E")
- : G_("%Kreading between %E and %E bytes "
+ : G_("reading between %E and %E bytes "
"from a region of size %E")),
- exp, range[0], range[1], size));
+ range[0], range[1], size));
if (warned)
suppress_warning (exp, OPT_Wstringop_overread);
@@ -4369,37 +4363,37 @@ warn_for_access (location_t loc, tree func, tree exp, int opt, tree range[2],
warned = (func
? warning_n (loc, OPT_Wstringop_overread,
tree_to_uhwi (range[0]),
- "%K%qD expecting %E byte in a region of size %E",
- "%K%qD expecting %E bytes in a region of size %E",
- exp, func, range[0], size)
+ "%qD expecting %E byte in a region of size %E",
+ "%qD expecting %E bytes in a region of size %E",
+ func, range[0], size)
: warning_n (loc, OPT_Wstringop_overread,
tree_to_uhwi (range[0]),
- "%Kexpecting %E byte in a region of size %E",
- "%Kexpecting %E bytes in a region of size %E",
- exp, range[0], size));
+ "expecting %E byte in a region of size %E",
+ "expecting %E bytes in a region of size %E",
+ range[0], size));
else if (tree_int_cst_sign_bit (range[1]))
{
/* Avoid printing the upper bound if it's invalid. */
warned = (func
? warning_at (loc, OPT_Wstringop_overread,
- "%K%qD expecting %E or more bytes in a region "
+ "%qD expecting %E or more bytes in a region "
"of size %E",
- exp, func, range[0], size)
+ func, range[0], size)
: warning_at (loc, OPT_Wstringop_overread,
- "%Kexpecting %E or more bytes in a region "
+ "expecting %E or more bytes in a region "
"of size %E",
- exp, range[0], size));
+ range[0], size));
}
else
warned = (func
? warning_at (loc, OPT_Wstringop_overread,
- "%K%qD expecting between %E and %E bytes in "
+ "%qD expecting between %E and %E bytes in "
"a region of size %E",
- exp, func, range[0], range[1], size)
+ func, range[0], range[1], size)
: warning_at (loc, OPT_Wstringop_overread,
- "%Kexpecting between %E and %E bytes in "
+ "expecting between %E and %E bytes in "
"a region of size %E",
- exp, range[0], range[1], size));
+ range[0], range[1], size));
if (warned)
suppress_warning (exp, OPT_Wstringop_overread);
@@ -4759,7 +4753,7 @@ check_access (tree exp, tree dstwrite,
&& TREE_CODE (range[0]) == INTEGER_CST
&& tree_int_cst_lt (maxobjsize, range[0]))
{
- location_t loc = tree_inlined_location (exp);
+ location_t loc = EXPR_LOCATION (exp);
maybe_warn_for_bound (OPT_Wstringop_overflow_, loc, exp, func, range,
NULL_TREE, pad);
return false;
@@ -4787,7 +4781,7 @@ check_access (tree exp, tree dstwrite,
&& warning_suppressed_p (pad->dst.ref, opt)))
return false;
- location_t loc = tree_inlined_location (exp);
+ location_t loc = EXPR_LOCATION (exp);
bool warned = false;
if (dstwrite == slen && at_least_one)
{
@@ -4796,15 +4790,15 @@ check_access (tree exp, tree dstwrite,
at least one byte past the end of the destination. */
warned = (func
? warning_at (loc, opt,
- "%K%qD writing %E or more bytes into "
+ "%qD writing %E or more bytes into "
"a region of size %E overflows "
"the destination",
- exp, func, range[0], dstsize)
+ func, range[0], dstsize)
: warning_at (loc, opt,
- "%Kwriting %E or more bytes into "
+ "writing %E or more bytes into "
"a region of size %E overflows "
"the destination",
- exp, range[0], dstsize));
+ range[0], dstsize));
}
else
{
@@ -4840,7 +4834,7 @@ check_access (tree exp, tree dstwrite,
PAD is nonnull and BNDRNG is valid. */
get_size_range (maxread, range, pad ? pad->src.bndrng : NULL);
- location_t loc = tree_inlined_location (exp);
+ location_t loc = EXPR_LOCATION (exp);
tree size = dstsize;
if (pad && pad->mode == access_read_only)
size = wide_int_to_tree (sizetype, pad->src.sizrng[1]);
@@ -4901,7 +4895,7 @@ check_access (tree exp, tree dstwrite,
&& warning_suppressed_p (pad->src.ref, opt)))
return false;
- location_t loc = tree_inlined_location (exp);
+ location_t loc = EXPR_LOCATION (exp);
const bool read
= mode == access_read_only || mode == access_read_write;
const bool maybe = pad && pad->dst.parmarray;
@@ -6481,10 +6475,10 @@ check_strncat_sizes (tree exp, tree objsize)
if (tree_fits_uhwi_p (maxread) && tree_fits_uhwi_p (objsize)
&& tree_int_cst_equal (objsize, maxread))
{
- location_t loc = tree_inlined_location (exp);
+ location_t loc = EXPR_LOCATION (exp);
warning_at (loc, OPT_Wstringop_overflow_,
- "%K%qD specified bound %E equals destination size",
- exp, get_callee_fndecl (exp), maxread);
+ "%qD specified bound %E equals destination size",
+ get_callee_fndecl (exp), maxread);
return false;
}
@@ -6554,10 +6548,10 @@ expand_builtin_strncat (tree exp, rtx)
if (tree_fits_uhwi_p (maxread) && tree_fits_uhwi_p (destsize)
&& tree_int_cst_equal (destsize, maxread))
{
- location_t loc = tree_inlined_location (exp);
+ location_t loc = EXPR_LOCATION (exp);
warning_at (loc, OPT_Wstringop_overflow_,
- "%K%qD specified bound %E equals destination size",
- exp, get_callee_fndecl (exp), maxread);
+ "%qD specified bound %E equals destination size",
+ get_callee_fndecl (exp), maxread);
return NULL_RTX;
}
@@ -7330,7 +7324,7 @@ expand_builtin_strncmp (tree exp, ATTRIBUTE_UNUSED rtx target,
|| !check_nul_terminated_array (exp, arg2, arg3))
return NULL_RTX;
- location_t loc = tree_inlined_location (exp);
+ location_t loc = EXPR_LOCATION (exp);
tree len1 = c_strlen (arg1, 1);
tree len2 = c_strlen (arg2, 1);
@@ -10006,13 +10000,13 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode,
case BUILT_IN_VA_ARG_PACK:
/* All valid uses of __builtin_va_arg_pack () are removed during
inlining. */
- error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp);
+ error ("invalid use of %<__builtin_va_arg_pack ()%>");
return const0_rtx;
case BUILT_IN_VA_ARG_PACK_LEN:
/* All valid uses of __builtin_va_arg_pack_len () are removed during
inlining. */
- error ("%Kinvalid use of %<__builtin_va_arg_pack_len ()%>", exp);
+ error ("invalid use of %<__builtin_va_arg_pack_len ()%>");
return const0_rtx;
/* Return the address of the first anonymous stack arg. */
@@ -12961,8 +12955,8 @@ expand_builtin_object_size (tree exp)
if (!validate_arglist (exp, POINTER_TYPE, INTEGER_TYPE, VOID_TYPE))
{
- error ("%Kfirst argument of %qD must be a pointer, second integer constant",
- exp, fndecl);
+ error ("first argument of %qD must be a pointer, second integer constant",
+ fndecl);
expand_builtin_trap ();
return const0_rtx;
}
@@ -12974,8 +12968,8 @@ expand_builtin_object_size (tree exp)
|| tree_int_cst_sgn (ost) < 0
|| compare_tree_int (ost, 3) > 0)
{
- error ("%Klast argument of %qD is not integer constant between 0 and 3",
- exp, fndecl);
+ error ("last argument of %qD is not integer constant between 0 and 3",
+ fndecl);
expand_builtin_trap ();
return const0_rtx;
}
@@ -13787,8 +13781,8 @@ warn_dealloc_offset (location_t loc, tree exp, const access_ref &aref)
}
if (!warning_at (loc, OPT_Wfree_nonheap_object,
- "%K%qD called on pointer %qE with nonzero offset%s",
- exp, dealloc_decl, aref.ref, offstr))
+ "%qD called on pointer %qE with nonzero offset%s",
+ dealloc_decl, aref.ref, offstr))
return false;
if (DECL_P (aref.ref))
@@ -13843,15 +13837,15 @@ maybe_emit_free_warning (tree exp)
return;
tree dealloc_decl = get_callee_fndecl (exp);
- location_t loc = tree_inlined_location (exp);
+ location_t loc = EXPR_LOCATION (exp);
if (DECL_P (ref) || EXPR_P (ref))
{
/* Diagnose freeing a declared object. */
if (aref.ref_declared ()
&& warning_at (loc, OPT_Wfree_nonheap_object,
- "%K%qD called on unallocated object %qD",
- exp, dealloc_decl, ref))
+ "%qD called on unallocated object %qD",
+ dealloc_decl, ref))
{
loc = (DECL_P (ref)
? DECL_SOURCE_LOCATION (ref)
@@ -13870,8 +13864,8 @@ maybe_emit_free_warning (tree exp)
else if (CONSTANT_CLASS_P (ref))
{
if (warning_at (loc, OPT_Wfree_nonheap_object,
- "%K%qD called on a pointer to an unallocated "
- "object %qE", exp, dealloc_decl, ref))
+ "%qD called on a pointer to an unallocated "
+ "object %qE", dealloc_decl, ref))
{
if (TREE_CODE (ptr) == SSA_NAME)
{
@@ -13909,18 +13903,18 @@ maybe_emit_free_warning (tree exp)
? OPT_Wmismatched_new_delete
: OPT_Wmismatched_dealloc);
warned = warning_at (loc, opt,
- "%K%qD called on pointer returned "
+ "%qD called on pointer returned "
"from a mismatched allocation "
- "function", exp, dealloc_decl);
+ "function", dealloc_decl);
}
}
else if (gimple_call_builtin_p (def_stmt, BUILT_IN_ALLOCA)
|| gimple_call_builtin_p (def_stmt,
BUILT_IN_ALLOCA_WITH_ALIGN))
warned = warning_at (loc, OPT_Wfree_nonheap_object,
- "%K%qD called on pointer to "
+ "%qD called on pointer to "
"an unallocated object",
- exp, dealloc_decl);
+ dealloc_decl);
else if (warn_dealloc_offset (loc, exp, aref))
return;
diff --git a/gcc/calls.c b/gcc/calls.c
index f8a4b79e7f8..d2413a280cf 100644
--- a/gcc/calls.c
+++ b/gcc/calls.c
@@ -1435,8 +1435,8 @@ maybe_warn_alloc_args_overflow (tree fn, tree exp, tree args[2], int idx[2])
if (tree_int_cst_lt (args[i], integer_zero_node))
{
warned = warning_at (loc, OPT_Walloc_size_larger_than_,
- "%Kargument %i value %qE is negative",
- exp, idx[i] + 1, args[i]);
+ "argument %i value %qE is negative",
+ idx[i] + 1, args[i]);
}
else if (integer_zerop (args[i]))
{
@@ -1452,8 +1452,8 @@ maybe_warn_alloc_args_overflow (tree fn, tree exp, tree args[2], int idx[2])
: !lookup_attribute ("returns_nonnull",
TYPE_ATTRIBUTES (fntype)))
warned = warning_at (loc, OPT_Walloc_zero,
- "%Kargument %i value is zero",
- exp, idx[i] + 1);
+ "argument %i value is zero",
+ idx[i] + 1);
}
else if (tree_int_cst_lt (maxobjsize, args[i]))
{
@@ -1470,9 +1470,9 @@ maybe_warn_alloc_args_overflow (tree fn, tree exp, tree args[2], int idx[2])
continue;
warned = warning_at (loc, OPT_Walloc_size_larger_than_,
- "%Kargument %i value %qE exceeds "
+ "argument %i value %qE exceeds "
"maximum object size %E",
- exp, idx[i] + 1, args[i], maxobjsize);
+ idx[i] + 1, args[i], maxobjsize);
}
}
else if (TREE_CODE (args[i]) == SSA_NAME
@@ -1484,16 +1484,16 @@ maybe_warn_alloc_args_overflow (tree fn, tree exp, tree args[2], int idx[2])
&& tree_int_cst_le (argrange[i][1], integer_zero_node))
{
warned = warning_at (loc, OPT_Walloc_size_larger_than_,
- "%Kargument %i range [%E, %E] is negative",
- exp, idx[i] + 1,
+ "argument %i range [%E, %E] is negative",
+ idx[i] + 1,
argrange[i][0], argrange[i][1]);
}
else if (tree_int_cst_lt (maxobjsize, argrange[i][0]))
{
warned = warning_at (loc, OPT_Walloc_size_larger_than_,
- "%Kargument %i range [%E, %E] exceeds "
+ "argument %i range [%E, %E] exceeds "
"maximum object size %E",
- exp, idx[i] + 1,
+ idx[i] + 1,
argrange[i][0], argrange[i][1],
maxobjsize);
}
@@ -1521,15 +1521,15 @@ maybe_warn_alloc_args_overflow (tree fn, tree exp, tree args[2], int idx[2])
if (vflow)
warned = warning_at (loc, OPT_Walloc_size_larger_than_,
- "%Kproduct %<%E * %E%> of arguments %i and %i "
+ "product %<%E * %E%> of arguments %i and %i "
"exceeds %<SIZE_MAX%>",
- exp, argrange[0][0], argrange[1][0],
+ argrange[0][0], argrange[1][0],
idx[0] + 1, idx[1] + 1);
else if (wi::ltu_p (wi::to_wide (maxobjsize, szprec), prod))
warned = warning_at (loc, OPT_Walloc_size_larger_than_,
- "%Kproduct %<%E * %E%> of arguments %i and %i "
+ "product %<%E * %E%> of arguments %i and %i "
"exceeds maximum object size %E",
- exp, argrange[0][0], argrange[1][0],
+ argrange[0][0], argrange[1][0],
idx[0] + 1, idx[1] + 1,
maxobjsize);
@@ -1729,14 +1729,14 @@ maybe_warn_nonstring_arg (tree fndecl, tree exp)
bool warned = false;
if (tree_int_cst_equal (bndrng[0], bndrng[1]))
warned = warning_at (loc, OPT_Wstringop_overread,
- "%K%qD specified bound %E "
+ "%qD specified bound %E "
"exceeds maximum object size %E",
- exp, fndecl, bndrng[0], maxobjsize);
+ fndecl, bndrng[0], maxobjsize);
else
warned = warning_at (loc, OPT_Wstringop_overread,
- "%K%qD specified bound [%E, %E] "
+ "%qD specified bound [%E, %E] "
"exceeds maximum object size %E",
- exp, fndecl, bndrng[0], bndrng[1],
+ fndecl, bndrng[0], bndrng[1],
maxobjsize);
if (warned)
suppress_warning (exp, OPT_Wstringop_overread);
@@ -2068,16 +2068,16 @@ maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp)
= access.second.array_as_string (ptrtype);
if (warning_at (loc, OPT_Wstringop_overflow_,
- "%Kbound argument %i value %s is "
+ "bound argument %i value %s is "
"negative for a variable length array "
"argument %i of type %s",
- exp, sizidx + 1, sizstr,
+ sizidx + 1, sizstr,
ptridx + 1, argtypestr.c_str ()))
arg_warned = OPT_Wstringop_overflow_;
}
else if (warning_at (loc, OPT_Wstringop_overflow_,
- "%Kargument %i value %s is negative",
- exp, sizidx + 1, sizstr))
+ "argument %i value %s is negative",
+ sizidx + 1, sizstr))
arg_warned = OPT_Wstringop_overflow_;
if (arg_warned != no_warning)
@@ -2124,20 +2124,19 @@ maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp)
= access.second.array_as_string (ptrtype);
if (warning_at (loc, OPT_Wnonnull,
- "%Kargument %i of variable length "
+ "argument %i of variable length "
"array %s is null but "
"the corresponding bound argument "
"%i value is %s",
- exp, sizidx + 1, argtypestr.c_str (),
+ sizidx + 1, argtypestr.c_str (),
ptridx + 1, sizstr))
arg_warned = OPT_Wnonnull;
}
else if (warning_at (loc, OPT_Wnonnull,
- "%Kargument %i is null but "
+ "argument %i is null but "
"the corresponding size argument "
"%i value is %s",
- exp, ptridx + 1, sizidx + 1,
- sizstr))
+ ptridx + 1, sizidx + 1, sizstr))
arg_warned = OPT_Wnonnull;
}
else if (access_size && access.second.static_p)
@@ -2145,10 +2144,9 @@ maybe_warn_rdwr_sizes (rdwr_map *rwm, tree fndecl, tree fntype, tree exp)
/* Warn about null pointers for [static N] array arguments
but do not warn for ordinary (i.e., nonstatic) arrays. */
if (warning_at (loc, OPT_Wnonnull,
- "%Kargument %i to %<%T[static %E]%> "
+ "argument %i to %<%T[static %E]%> "
"is null where non-null expected",
- exp, ptridx + 1, argtype,
- access_size))
+ ptridx + 1, argtype, access_size))
arg_warned = OPT_Wnonnull;
}
diff --git a/gcc/expr.c b/gcc/expr.c
index 025033c9ecf..b9fe1cf91d7 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -11401,7 +11401,7 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
/* All valid uses of __builtin_va_arg_pack () are removed during
inlining. */
if (CALL_EXPR_VA_ARG_PACK (exp))
- error ("%Kinvalid use of %<__builtin_va_arg_pack ()%>", exp);
+ error ("invalid use of %<__builtin_va_arg_pack ()%>");
{
tree fndecl = get_callee_fndecl (exp), attr;
@@ -11413,7 +11413,7 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
DECL_ATTRIBUTES (fndecl))) != NULL)
{
const char *ident = lang_hooks.decl_printable_name (fndecl, 1);
- error ("%Kcall to %qs declared with attribute error: %s", exp,
+ error ("call to %qs declared with attribute error: %s",
identifier_to_locale (ident),
TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
}
@@ -11425,10 +11425,10 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
DECL_ATTRIBUTES (fndecl))) != NULL)
{
const char *ident = lang_hooks.decl_printable_name (fndecl, 1);
- warning_at (tree_nonartificial_location (exp),
+ warning_at (EXPR_LOCATION (exp),
OPT_Wattribute_warning,
- "%Kcall to %qs declared with attribute warning: %s",
- exp, identifier_to_locale (ident),
+ "call to %qs declared with attribute warning: %s",
+ identifier_to_locale (ident),
TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr))));
}
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 68031538145..1401092aa9b 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -2115,13 +2115,13 @@ gimple_fold_builtin_strncpy (gimple_stmt_iterator *gsi,
tree slen = get_maxval_strlen (src, SRK_STRLEN);
if (slen && !integer_zerop (slen))
warning_at (loc, OPT_Wstringop_truncation,
- "%G%qD destination unchanged after copying no bytes "
+ "%qD destination unchanged after copying no bytes "
"from a string of length %E",
- stmt, fndecl, slen);
+ fndecl, slen);
else
warning_at (loc, OPT_Wstringop_truncation,
- "%G%qD destination unchanged after copying no bytes",
- stmt, fndecl);
+ "%qD destination unchanged after copying no bytes",
+ fndecl);
}
replace_call_with_value (gsi, dest);
@@ -2498,11 +2498,11 @@ gimple_fold_builtin_strncat (gimple_stmt_iterator *gsi)
location_t loc = gimple_location (stmt);
nowarn = warning_at (loc, OPT_Wstringop_overflow_,
cmpdst == 0
- ? G_("%G%qD specified bound %E equals "
+ ? G_("%qD specified bound %E equals "
"destination size")
- : G_("%G%qD specified bound %E exceeds "
+ : G_("%qD specified bound %E exceeds "
"destination size %wu"),
- stmt, fndecl, len, dstsize);
+ fndecl, len, dstsize);
if (nowarn)
suppress_warning (stmt, OPT_Wstringop_overflow_);
}
@@ -2518,8 +2518,8 @@ gimple_fold_builtin_strncat (gimple_stmt_iterator *gsi)
of the destination is unknown (it's not an uncommon mistake
to specify as the bound to strncpy the length of the source). */
if (warning_at (loc, OPT_Wstringop_overflow_,
- "%G%qD specified bound %E equals source length",
- stmt, fndecl, len))
+ "%qD specified bound %E equals source length",
+ fndecl, len))
suppress_warning (stmt, OPT_Wstringop_overflow_);
}
diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c
index 41e3be6f9f4..f38fb03f068 100644
--- a/gcc/gimple-ssa-sprintf.c
+++ b/gcc/gimple-ssa-sprintf.c
@@ -3115,9 +3115,8 @@ format_directive (const call_info &info,
if (fmtres.nullp)
{
fmtwarn (dirloc, argloc, NULL, info.warnopt (),
- "%G%<%.*s%> directive argument is null",
- info.callstmt, dirlen,
- target_to_host (hostdir, sizeof hostdir, dir.beg));
+ "%<%.*s%> directive argument is null",
+ dirlen, target_to_host (hostdir, sizeof hostdir, dir.beg));
/* Don't bother processing the rest of the format string. */
res->warned = true;
@@ -4620,8 +4619,7 @@ handle_printf_call (gimple_stmt_iterator *gsi, pointer_query &ptr_qry)
is not constant. */
location_t loc = gimple_location (info.callstmt);
warning_at (EXPR_LOC_OR_LOC (dstptr, loc),
- info.warnopt (), "%Gnull destination pointer",
- info.callstmt);
+ info.warnopt (), "null destination pointer");
return false;
}
@@ -4650,8 +4648,7 @@ handle_printf_call (gimple_stmt_iterator *gsi, pointer_query &ptr_qry)
{
location_t loc = gimple_location (info.callstmt);
warning_at (EXPR_LOC_OR_LOC (info.format, loc),
- info.warnopt (), "%Gnull format string",
- info.callstmt);
+ info.warnopt (), "null format string");
return false;
}
diff --git a/gcc/gimple-ssa-warn-alloca.c b/gcc/gimple-ssa-warn-alloca.c
index 72480f1d8cb..4fc7125d378 100644
--- a/gcc/gimple-ssa-warn-alloca.c
+++ b/gcc/gimple-ssa-warn-alloca.c
@@ -283,7 +283,7 @@ pass_walloca::execute (function *fun)
}
else if (warn_alloca)
{
- warning_at (loc, OPT_Walloca, "%Guse of %<alloca%>", stmt);
+ warning_at (loc, OPT_Walloca, "use of %<alloca%>");
continue;
}
else if (warn_alloca_limit < 0)
@@ -322,11 +322,10 @@ pass_walloca::execute (function *fun)
auto_diagnostic_group d;
if (warning_at (loc, wcode,
(is_vla
- ? G_("%Gargument to variable-length "
+ ? G_("argument to variable-length "
"array may be too large")
- : G_("%Gargument to %<alloca%> may be too "
- "large")),
- stmt)
+ : G_("argument to %<alloca%> may be too "
+ "large")))
&& t.limit != 0)
{
print_decu (t.limit, buff);
@@ -342,10 +341,9 @@ pass_walloca::execute (function *fun)
auto_diagnostic_group d;
if (warning_at (loc, wcode,
(is_vla
- ? G_("%Gargument to variable-length"
+ ? G_("argument to variable-length"
" array is too large")
- : G_("%Gargument to %<alloca%> is too large")),
- stmt)
+ : G_("argument to %<alloca%> is too large")))
&& t.limit != 0)
{
print_decu (t.limit, buff);
@@ -361,22 +359,20 @@ pass_walloca::execute (function *fun)
warning_at (loc, wcode,
(is_vla
- ? G_("%Gunbounded use of variable-length array")
- : G_("%Gunbounded use of %<alloca%>")),
- stmt);
+ ? G_("unbounded use of variable-length array")
+ : G_("unbounded use of %<alloca%>")));
break;
case ALLOCA_IN_LOOP:
gcc_assert (!is_vla);
warning_at (loc, wcode,
- "%Guse of %<alloca%> within a loop", stmt);
+ "use of %<alloca%> within a loop");
break;
case ALLOCA_ARG_IS_ZERO:
warning_at (loc, wcode,
(is_vla
- ? G_("%Gargument to variable-length array "
+ ? G_("argument to variable-length array "
"is zero")
- : G_("%Gargument to %<alloca%> is zero")),
- stmt);
+ : G_("argument to %<alloca%> is zero")));
break;
default:
gcc_unreachable ();
diff --git a/gcc/gimple-ssa-warn-restrict.c b/gcc/gimple-ssa-warn-restrict.c
index 02771e4cd60..efb8db98393 100644
--- a/gcc/gimple-ssa-warn-restrict.c
+++ b/gcc/gimple-ssa-warn-restrict.c
@@ -1494,36 +1494,36 @@ maybe_diag_overlap (location_t loc, gimple *call, builtin_access &acs)
warning_at (loc, OPT_Wrestrict,
sizrange[0] == 1
? (ovlsiz[0] == 1
- ? G_("%G%qD accessing %wu byte at offsets %s "
+ ? G_("%qD accessing %wu byte at offsets %s "
"and %s overlaps %wu byte at offset %s")
- : G_("%G%qD accessing %wu byte at offsets %s "
+ : G_("%qD accessing %wu byte at offsets %s "
"and %s overlaps %wu bytes at offset "
"%s"))
: (ovlsiz[0] == 1
- ? G_("%G%qD accessing %wu bytes at offsets %s "
+ ? G_("%qD accessing %wu bytes at offsets %s "
"and %s overlaps %wu byte at offset %s")
- : G_("%G%qD accessing %wu bytes at offsets %s "
+ : G_("%qD accessing %wu bytes at offsets %s "
"and %s overlaps %wu bytes at offset "
"%s")),
- call, func, sizrange[0],
+ func, sizrange[0],
offstr[0], offstr[1], ovlsiz[0], offstr[2]);
else if (ovlsiz[1] >= 0 && ovlsiz[1] < maxobjsize.to_shwi ())
warning_n (loc, OPT_Wrestrict, sizrange[0],
- "%G%qD accessing %wu byte at offsets %s "
+ "%qD accessing %wu byte at offsets %s "
"and %s overlaps between %wu and %wu bytes "
"at offset %s",
- "%G%qD accessing %wu bytes at offsets %s "
+ "%qD accessing %wu bytes at offsets %s "
"and %s overlaps between %wu and %wu bytes "
"at offset %s",
- call, func, sizrange[0], offstr[0], offstr[1],
+ func, sizrange[0], offstr[0], offstr[1],
ovlsiz[0], ovlsiz[1], offstr[2]);
else
warning_n (loc, OPT_Wrestrict, sizrange[0],
- "%G%qD accessing %wu byte at offsets %s and "
+ "%qD accessing %wu byte at offsets %s and "
"%s overlaps %wu or more bytes at offset %s",
- "%G%qD accessing %wu bytes at offsets %s and "
+ "%qD accessing %wu bytes at offsets %s and "
"%s overlaps %wu or more bytes at offset %s",
- call, func, sizrange[0],
+ func, sizrange[0],
offstr[0], offstr[1], ovlsiz[0], offstr[2]);
return true;
}
@@ -1532,28 +1532,28 @@ maybe_diag_overlap (location_t loc, gimple *call, builtin_access &acs)
{
if (ovlsiz[0] == ovlsiz[1])
warning_n (loc, OPT_Wrestrict, ovlsiz[0],
- "%G%qD accessing between %wu and %wu bytes "
+ "%qD accessing between %wu and %wu bytes "
"at offsets %s and %s overlaps %wu byte at "
"offset %s",
- "%G%qD accessing between %wu and %wu bytes "
+ "%qD accessing between %wu and %wu bytes "
"at offsets %s and %s overlaps %wu bytes "
"at offset %s",
- call, func, sizrange[0], sizrange[1],
+ func, sizrange[0], sizrange[1],
offstr[0], offstr[1], ovlsiz[0], offstr[2]);
else if (ovlsiz[1] >= 0 && ovlsiz[1] < maxobjsize.to_shwi ())
warning_at (loc, OPT_Wrestrict,
- "%G%qD accessing between %wu and %wu bytes at "
+ "%qD accessing between %wu and %wu bytes at "
"offsets %s and %s overlaps between %wu and %wu "
"bytes at offset %s",
- call, func, sizrange[0], sizrange[1],
+ func, sizrange[0], sizrange[1],
offstr[0], offstr[1], ovlsiz[0], ovlsiz[1],
offstr[2]);
else
warning_at (loc, OPT_Wrestrict,
- "%G%qD accessing between %wu and %wu bytes at "
+ "%qD accessing between %wu and %wu bytes at "
"offsets %s and %s overlaps %wu or more bytes "
"at offset %s",
- call, func, sizrange[0], sizrange[1],
+ func, sizrange[0], sizrange[1],
offstr[0], offstr[1], ovlsiz[0], offstr[2]);
return true;
}
@@ -1563,24 +1563,24 @@ maybe_diag_overlap (location_t loc, gimple *call, builtin_access &acs)
if (ovlsiz[0] == ovlsiz[1])
warning_n (loc, OPT_Wrestrict, ovlsiz[0],
- "%G%qD accessing %wu or more bytes at offsets "
+ "%qD accessing %wu or more bytes at offsets "
"%s and %s overlaps %wu byte at offset %s",
- "%G%qD accessing %wu or more bytes at offsets "
+ "%qD accessing %wu or more bytes at offsets "
"%s and %s overlaps %wu bytes at offset %s",
- call, func, sizrange[0], offstr[0], offstr[1],
+ func, sizrange[0], offstr[0], offstr[1],
ovlsiz[0], offstr[2]);
else if (ovlsiz[1] >= 0 && ovlsiz[1] < maxobjsize.to_shwi ())
warning_at (loc, OPT_Wrestrict,
- "%G%qD accessing %wu or more bytes at offsets %s "
+ "%qD accessing %wu or more bytes at offsets %s "
"and %s overlaps between %wu and %wu bytes "
"at offset %s",
- call, func, sizrange[0], offstr[0], offstr[1],
+ func, sizrange[0], offstr[0], offstr[1],
ovlsiz[0], ovlsiz[1], offstr[2]);
else
warning_at (loc, OPT_Wrestrict,
- "%G%qD accessing %wu or more bytes at offsets %s "
+ "%qD accessing %wu or more bytes at offsets %s "
"and %s overlaps %wu or more bytes at offset %s",
- call, func, sizrange[0], offstr[0], offstr[1],
+ func, sizrange[0], offstr[0], offstr[1],
ovlsiz[0], offstr[2]);
return true;
}
@@ -1606,36 +1606,36 @@ maybe_diag_overlap (location_t loc, gimple *call, builtin_access &acs)
{
if (open_range)
warning_n (loc, OPT_Wrestrict, sizrange[1],
- "%G%qD accessing %wu byte may overlap "
+ "%qD accessing %wu byte may overlap "
"%wu byte",
- "%G%qD accessing %wu bytes may overlap "
+ "%qD accessing %wu bytes may overlap "
"%wu byte",
- call, func, sizrange[1], ovlsiz[1]);
+ func, sizrange[1], ovlsiz[1]);
else
warning_n (loc, OPT_Wrestrict, sizrange[1],
- "%G%qD accessing %wu byte at offsets %s "
+ "%qD accessing %wu byte at offsets %s "
"and %s may overlap %wu byte at offset %s",
- "%G%qD accessing %wu bytes at offsets %s "
+ "%qD accessing %wu bytes at offsets %s "
"and %s may overlap %wu byte at offset %s",
- call, func, sizrange[1], offstr[0], offstr[1],
+ func, sizrange[1], offstr[0], offstr[1],
ovlsiz[1], offstr[2]);
return true;
}
if (open_range)
warning_n (loc, OPT_Wrestrict, sizrange[1],
- "%G%qD accessing %wu byte may overlap "
+ "%qD accessing %wu byte may overlap "
"up to %wu bytes",
- "%G%qD accessing %wu bytes may overlap "
+ "%qD accessing %wu bytes may overlap "
"up to %wu bytes",
- call, func, sizrange[1], ovlsiz[1]);
+ func, sizrange[1], ovlsiz[1]);
else
warning_n (loc, OPT_Wrestrict, sizrange[1],
- "%G%qD accessing %wu byte at offsets %s and "
+ "%qD accessing %wu byte at offsets %s and "
"%s may overlap up to %wu bytes at offset %s",
- "%G%qD accessing %wu bytes at offsets %s and "
+ "%qD accessing %wu bytes at offsets %s and "
"%s may overlap up to %wu bytes at offset %s",
- call, func, sizrange[1], offstr[0], offstr[1],
+ func, sizrange[1], offstr[0], offstr[1],
ovlsiz[1], offstr[2]);
return true;
}
@@ -1644,30 +1644,30 @@ maybe_diag_overlap (location_t loc, gimple *call, builtin_access &acs)
{
if (open_range)
warning_n (loc, OPT_Wrestrict, ovlsiz[1],
- "%G%qD accessing between %wu and %wu bytes "
+ "%qD accessing between %wu and %wu bytes "
"may overlap %wu byte",
- "%G%qD accessing between %wu and %wu bytes "
+ "%qD accessing between %wu and %wu bytes "
"may overlap up to %wu bytes",
- call, func, sizrange[0], sizrange[1], ovlsiz[1]);
+ func, sizrange[0], sizrange[1], ovlsiz[1]);
else
warning_n (loc, OPT_Wrestrict, ovlsiz[1],
- "%G%qD accessing between %wu and %wu bytes "
+ "%qD accessing between %wu and %wu bytes "
"at offsets %s and %s may overlap %wu byte "
"at offset %s",
- "%G%qD accessing between %wu and %wu bytes "
+ "%qD accessing between %wu and %wu bytes "
"at offsets %s and %s may overlap up to %wu "
"bytes at offset %s",
- call, func, sizrange[0], sizrange[1],
+ func, sizrange[0], sizrange[1],
offstr[0], offstr[1], ovlsiz[1], offstr[2]);
return true;
}
warning_n (loc, OPT_Wrestrict, ovlsiz[1],
- "%G%qD accessing %wu or more bytes at offsets %s "
+ "%qD accessing %wu or more bytes at offsets %s "
"and %s may overlap %wu byte at offset %s",
- "%G%qD accessing %wu or more bytes at offsets %s "
+ "%qD accessing %wu or more bytes at offsets %s "
"and %s may overlap up to %wu bytes at offset %s",
- call, func, sizrange[0], offstr[0], offstr[1],
+ func, sizrange[0], offstr[0], offstr[1],
ovlsiz[1], offstr[2]);
return true;
@@ -1689,7 +1689,7 @@ 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);
+ location_t loc = gimple_location (call);
const offset_int maxobjsize = ref.maxobjsize;
/* Check for excessive size first and regardless of warning options
@@ -1709,15 +1709,15 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict,
{
if (ref.sizrange[0] == ref.sizrange[1])
warned = warning_at (loc, opt,
- "%G%qD specified bound %wu "
+ "%qD specified bound %wu "
"exceeds maximum object size %wu",
- call, func, ref.sizrange[0].to_uhwi (),
+ func, ref.sizrange[0].to_uhwi (),
maxobjsize.to_uhwi ());
else
warned = warning_at (loc, opt,
- "%G%qD specified bound between %wu and %wu "
+ "%qD specified bound between %wu and %wu "
"exceeds maximum object size %wu",
- call, func, ref.sizrange[0].to_uhwi (),
+ func, ref.sizrange[0].to_uhwi (),
ref.sizrange[1].to_uhwi (),
maxobjsize.to_uhwi ());
return warned ? opt : no_warning;
@@ -1776,9 +1776,9 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict,
{
auto_diagnostic_group d;
if (warning_at (loc, opt,
- "%G%qD pointer overflow between offset %s "
+ "%qD pointer overflow between offset %s "
"and size %s accessing array %qD with type %qT",
- call, func, rangestr[0], rangestr[1], ref.base, type))
+ func, rangestr[0], rangestr[1], ref.base, type))
{
inform (DECL_SOURCE_LOCATION (ref.base),
"array %qD declared here", ref.base);
@@ -1786,15 +1786,15 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict,
}
else
warned = warning_at (loc, opt,
- "%G%qD pointer overflow between offset %s "
+ "%qD pointer overflow between offset %s "
"and size %s",
- call, func, rangestr[0], rangestr[1]);
+ func, rangestr[0], rangestr[1]);
}
else
warned = warning_at (loc, opt,
- "%G%qD pointer overflow between offset %s "
+ "%qD pointer overflow between offset %s "
"and size %s",
- call, func, rangestr[0], rangestr[1]);
+ func, rangestr[0], rangestr[1]);
}
else if (oobref == ref.base)
{
@@ -1809,20 +1809,20 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict,
if ((ref.basesize < maxobjsize
&& warning_at (loc, opt,
form
- ? G_("%G%qD forming offset %s is out of "
+ ? G_("%qD forming offset %s is out of "
"the bounds [0, %wu] of object %qD with "
"type %qT")
- : G_("%G%qD offset %s is out of the bounds "
+ : G_("%qD offset %s is out of the bounds "
"[0, %wu] of object %qD with type %qT"),
- call, func, rangestr[0], ref.basesize.to_uhwi (),
+ func, rangestr[0], ref.basesize.to_uhwi (),
ref.base, TREE_TYPE (ref.base)))
|| warning_at (loc, opt,
form
- ? G_("%G%qD forming offset %s is out of "
+ ? G_("%qD forming offset %s is out of "
"the bounds of object %qD with type %qT")
- : G_("%G%qD offset %s is out of the bounds "
+ : G_("%qD offset %s is out of the bounds "
"of object %qD with type %qT"),
- call, func, rangestr[0],
+ func, rangestr[0],
ref.base, TREE_TYPE (ref.base)))
{
inform (DECL_SOURCE_LOCATION (ref.base),
@@ -1833,17 +1833,17 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict,
else if (ref.basesize < maxobjsize)
warned = warning_at (loc, opt,
form
- ? G_("%G%qD forming offset %s is out "
+ ? G_("%qD forming offset %s is out "
"of the bounds [0, %wu]")
- : G_("%G%qD offset %s is out "
+ : G_("%qD offset %s is out "
"of the bounds [0, %wu]"),
- call, func, rangestr[0], ref.basesize.to_uhwi ());
+ func, rangestr[0], ref.basesize.to_uhwi ());
else
warned = warning_at (loc, opt,
form
- ? G_("%G%qD forming offset %s is out of bounds")
- : G_("%G%qD offset %s is out of bounds"),
- call, func, rangestr[0]);
+ ? G_("%qD forming offset %s is out of bounds")
+ : G_("%qD offset %s is out of bounds"),
+ func, rangestr[0]);
}
else if (TREE_CODE (ref.ref) == MEM_REF)
{
@@ -1854,9 +1854,9 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict,
type = TYPE_MAIN_VARIANT (type);
if (warning_at (loc, opt,
- "%G%qD offset %s from the object at %qE is out "
+ "%qD offset %s from the object at %qE is out "
"of the bounds of %qT",
- call, func, rangestr[0], ref.base, type))
+ func, rangestr[0], ref.base, type))
{
if (TREE_CODE (ref.ref) == COMPONENT_REF)
refop = TREE_OPERAND (ref.ref, 1);
@@ -1872,10 +1872,10 @@ maybe_diag_access_bounds (gimple *call, tree func, int strict,
tree type = TYPE_MAIN_VARIANT (TREE_TYPE (ref.ref));
if (warning_at (loc, opt,
- "%G%qD offset %s from the object at %qE is out "
+ "%qD offset %s from the object at %qE is out "
"of the bounds of referenced subobject %qD with "
"type %qT at offset %wi",
- call, func, rangestr[0], ref.base,
+ func, rangestr[0], ref.base,
TREE_OPERAND (ref.ref, 1), type,
ref.refoff.to_shwi ()))
{
@@ -2065,7 +2065,7 @@ check_bounds_or_overlap (range_query *query,
}
}
- location_t loc = gimple_or_expr_nonartificial_location (call, dst);
+ location_t loc = gimple_location (call);
if (operand_equal_p (dst, src, 0))
{
/* Issue -Wrestrict unless the pointers are null (those do
@@ -2075,8 +2075,8 @@ check_bounds_or_overlap (range_query *query,
if (!integer_zerop (dst) && !warning_suppressed_p (call, OPT_Wrestrict))
{
warning_at (loc, OPT_Wrestrict,
- "%G%qD source argument is the same as destination",
- call, func);
+ "%qD source argument is the same as destination",
+ func);
suppress_warning (call, OPT_Wrestrict);
return OPT_Wrestrict;
}
diff --git a/gcc/testsuite/g++.dg/warn/Wdtor1.s b/gcc/testsuite/g++.dg/warn/Wdtor1.s
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-71.c b/gcc/testsuite/gcc.dg/Warray-bounds-71.c
new file mode 100644
index 00000000000..425bb122909
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Warray-bounds-71.c
@@ -0,0 +1,7 @@
+/* Verify that -Warray-bounds suppression via #pragma GCC diagnostic
+ works at any call site in an inlining stack
+ { dg-do compile }
+ { dg-options "-O2 -Wall" } */
+
+#define IGNORE '1'
+#include "Warray-bounds-71.h"
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-71.h b/gcc/testsuite/gcc.dg/Warray-bounds-71.h
new file mode 100644
index 00000000000..89d1068a266
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Warray-bounds-71.h
@@ -0,0 +1,46 @@
+/* Verify that -Warray-bounds suppression via #pragma GCC diagnostic
+ works at any call site in an inlining stack
+ { dg-do compile }
+ { dg-options "-O2 -Wall" } */
+
+int a[4];
+
+void f1 (int *p, int i)
+{
+#pragma GCC diagnostic push
+#if IGNORE == '1'
+# pragma GCC diagnostic ignored "-Warray-bounds"
+#endif
+ p[i + 1] = 0;
+#pragma GCC diagnostic pop
+}
+
+void f2 (int *p, int i)
+{
+#pragma GCC diagnostic push
+#if IGNORE == '2'
+# pragma GCC diagnostic ignored "-Warray-bounds"
+#endif
+ f1 (p + 1, i + 1);
+#pragma GCC diagnostic pop
+}
+
+void f3 (int *p, int i)
+{
+#pragma GCC diagnostic push
+#if IGNORE == '3'
+# pragma GCC diagnostic ignored "-Warray-bounds"
+#endif
+ f2 (p + 1, i + 1);
+#pragma GCC diagnostic pop
+}
+
+void f4 (void)
+{
+#pragma GCC diagnostic push
+#if IGNORE == '4'
+# pragma GCC diagnostic ignored "-Warray-bounds"
+#endif
+ f3 (a, 1);
+#pragma GCC diagnostic pop
+}
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-72.c b/gcc/testsuite/gcc.dg/Warray-bounds-72.c
new file mode 100644
index 00000000000..eb3f664c0c8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Warray-bounds-72.c
@@ -0,0 +1,7 @@
+/* Verify that -Warray-bounds suppression via #pragma GCC diagnostic
+ works at any call site in an inlining stack
+ { dg-do compile }
+ { dg-options "-O2 -Wall" } */
+
+#define IGNORE '2'
+#include "Warray-bounds-71.h"
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-73.c b/gcc/testsuite/gcc.dg/Warray-bounds-73.c
new file mode 100644
index 00000000000..50e20835293
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Warray-bounds-73.c
@@ -0,0 +1,7 @@
+/* Verify that -Warray-bounds suppression via #pragma GCC diagnostic
+ works at any call site in an inlining stack
+ { dg-do compile }
+ { dg-options "-O2 -Wall" } */
+
+#define IGNORE '3'
+#include "Warray-bounds-71.h"
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-74.c b/gcc/testsuite/gcc.dg/Warray-bounds-74.c
new file mode 100644
index 00000000000..c59a876e073
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Warray-bounds-74.c
@@ -0,0 +1,7 @@
+/* Verify that -Warray-bounds suppression via #pragma GCC diagnostic
+ works at any call site in an inlining stack
+ { dg-do compile }
+ { dg-options "-O2 -Wall" } */
+
+#define IGNORE '4'
+#include "Warray-bounds-71.h"
diff --git a/gcc/testsuite/gcc.dg/Warray-bounds-75.c b/gcc/testsuite/gcc.dg/Warray-bounds-75.c
new file mode 100644
index 00000000000..306b1768b0e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Warray-bounds-75.c
@@ -0,0 +1,12 @@
+/* Sanity test for Warray-bounds-7[1-4].c. Also verify the expected
+ inlining stack.
+ { dg-do compile }
+ { dg-options "-O2 -Wall" } */
+
+#include "Warray-bounds-71.h"
+
+// { dg-regexp "In function 'f1'," "In function f1" { target *-*-* } 0 }
+// { dg-regexp "inlined from 'f2' at \[^\\n\\r\]+\[\\n\\r\]" "inlined from f2" { target *-*-* } 0 }
+// { dg-regexp "inlined from 'f3' at \[^\\n\\r\]+\[\\n\\r\]" "inlined from f3" { target *-*-* } 0 }
+// { dg-regexp "inlined from 'f4' at \[^\\n\\r\]+\[\\n\\r\]" "inlined from f4" { target *-*-* } 0 }
+// { dg-message "Warray-bounds-71.h:\\d+:\\d+: warning: array subscript 6 is outside array bounds of 'int\\\[4]'" "warning" { target *-*-* } 0 }
diff --git a/gcc/testsuite/gcc.dg/Wfree-nonheap-object-4.c b/gcc/testsuite/gcc.dg/Wfree-nonheap-object-4.c
index a7d921248c4..fdef9e6b3ea 100644
--- a/gcc/testsuite/gcc.dg/Wfree-nonheap-object-4.c
+++ b/gcc/testsuite/gcc.dg/Wfree-nonheap-object-4.c
@@ -26,7 +26,7 @@ void g2 (struct A *p) { g1 (p); }
#define NOIPA __attribute__ ((noipa))
-extern int array[];
+extern int array[]; // { dg-message "declared here" "note on line 29" }
/* Verify the warning is issued even for calls in a system header inlined
into a function outside the header. */
@@ -39,7 +39,7 @@ NOIPA void warn_g0 (struct A *p)
g0 (p);
}
-// { dg-message "inlined from 'warn_g0'" "" { target *-*-* } 0 }
+// { dg-message "inlined from 'warn_g0'" "note on line 42" { target *-*-* } 0 }
/* Also verify the warning can be suppressed. */
@@ -65,8 +65,8 @@ NOIPA void warn_g1 (struct A *p)
g1 (p);
}
-// { dg-message "inlined from 'g1'" "" { target *-*-* } 0 }
-// { dg-message "inlined from 'warn_g1'" "" { target *-*-* } 0 }
+// { dg-message "inlined from 'g1'" "note on line 68" { target *-*-* } 0 }
+// { dg-message "inlined from 'warn_g1'" "note on line 69" { target *-*-* } 0 }
NOIPA void nowarn_g1 (struct A *p)
@@ -90,8 +90,8 @@ NOIPA void warn_g2 (struct A *p)
g2 (p);
}
-// { dg-message "inlined from 'g2'" "" { target *-*-* } 0 }
-// { dg-message "inlined from 'warn_g2'" "" { target *-*-* } 0 }
+// { dg-message "inlined from 'g2'" "note on line 93" { target *-*-* } 0 }
+// { dg-message "inlined from 'warn_g2'" "note on line 94" { target *-*-* } 0 }
NOIPA void nowarn_g2 (struct A *p)
diff --git a/gcc/testsuite/gcc.dg/Wfree-nonheap-object-5.c b/gcc/testsuite/gcc.dg/Wfree-nonheap-object-5.c
new file mode 100644
index 00000000000..979e1e3d78f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wfree-nonheap-object-5.c
@@ -0,0 +1,45 @@
+/* Similar to Wfree-nonheap-object-4.c but without system headers:
+ verify that warnings for the same call site from distinct callers
+ include the correct function names in the inlining stack.
+ { dg-do compile }
+ { dg-options "-O2 -Wall" } */
+
+struct A
+{
+ void *p;
+};
+
+void f0 (struct A *p)
+{
+ __builtin_free (p->p); // { dg-warning "\\\[-Wfree-nonheap-object" }
+}
+
+// Expect two instances of the text below:
+// { dg-regexp "In function 'f0'," "f0 prefix" { target *-*-* } 0 }
+// { dg-regexp "In function 'f0'," "f0 prefix" { target *-*-* } 0 }
+
+void f1 (struct A *p) { f0 (p); }
+void f2 (struct A *p) { f1 (p); }
+
+extern int array[];
+// Also expect two instances of the note:
+// { dg-regexp "declared here" "note on line 24" { target *-*-* } .-2 }
+// { dg-regexp "declared here" "note on line 24" { target *-*-* } .-3 }
+
+void foo (struct A *p)
+{
+ p->p = array + 1;
+ f0 (p);
+}
+
+// { dg-message "inlined from 'foo'" "note on line 35" { target *-*-* } 0 }
+
+
+void bar (struct A *p)
+{
+ p->p = array + 2;
+ f1 (p);
+}
+
+// { dg-message "inlined from 'f1'" "note on line 44" { target *-*-* } 0 }
+// { dg-message "inlined from 'bar'" "note on line 45" { target *-*-* } 0 }
diff --git a/gcc/testsuite/gcc.dg/Wobjsize-1.c b/gcc/testsuite/gcc.dg/Wobjsize-1.c
index e80c8add3bb..2bd2f93897b 100644
--- a/gcc/testsuite/gcc.dg/Wobjsize-1.c
+++ b/gcc/testsuite/gcc.dg/Wobjsize-1.c
@@ -4,13 +4,17 @@
#include "Wobjsize-1.h"
char buf[6];
-/* { dg-warning "writing" "" { target *-*-* } .-1 } */
int main(int argc, char **argv)
{
- strcpy (buf,"hello ");
+ strcpy (buf,"hello "); /* { dg-warning "\\\[-Wstringop-overflow" } */
return 0;
}
-/* { dg-message "file included" "included" { target *-*-* } 0 } */
-/* { dg-message "inlined from" "inlined" { target *-*-* } 0 } */
+/* { dg-message "file included" "included" { target *-*-* } 0 }
+ { dg-message "inlined from" "inlined" { target *-*-* } 0 }
+
+ The test might emit two warnings, one for the strcpy call and
+ another for the inlined call to __builtin___strcpy_chk() called
+ from strcpy().
+ { dg-prune-output "writing 7 bytes into a region of size 6" } */
diff --git a/gcc/testsuite/gcc.dg/pragma-diag-10.c b/gcc/testsuite/gcc.dg/pragma-diag-10.c
new file mode 100644
index 00000000000..127b299939a
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pragma-diag-10.c
@@ -0,0 +1,20 @@
+/* PR middle-end/98512 - #pragma GCC diagnostic ignored ineffective
+ in conjunction with alias attribute
+ { dg-do compile }
+ { dg-options "-O2 -Wall" } */
+
+void *
+__rawmemchr_ppc (const void *s, int c)
+{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
+#pragma GCC diagnostic ignored "-Wstringop-overread"
+ if (c != 0)
+ return __builtin_memchr (s, c, (unsigned long)-1); // { dg-bogus "specified bound \\d+ exceeds maximum object size" }
+#pragma GCC diagnostic pop
+
+ return (char *)s + __builtin_strlen (s);
+}
+
+extern __typeof (__rawmemchr_ppc) __EI___rawmemchr_ppc
+ __attribute__((alias ("__rawmemchr_ppc")));
diff --git a/gcc/testsuite/gcc.dg/pragma-diag-9.c b/gcc/testsuite/gcc.dg/pragma-diag-9.c
new file mode 100644
index 00000000000..d7eac558128
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pragma-diag-9.c
@@ -0,0 +1,134 @@
+/* Verify that #pragma GCC diagnostic down the inlining stack suppresses
+ a warning that would otherwise be issued for inlined calls higher up
+ the inlining stack.
+ { dg-do compile }
+ { dg-options "-O2 -Wall -Wno-array-bounds" } */
+
+extern void* memset (void*, int, __SIZE_TYPE__);
+
+static void warn0 (int *p)
+{
+ memset (p, __LINE__, 3); // { dg-warning "\\\[-Wstringop-overflow" }
+}
+
+static void warn1 (int *p)
+{
+ warn0 (p + 1);
+}
+
+static void warn2 (int *p)
+{
+ warn1 (p + 1);
+}
+
+int a2[2]; // { dg-message "at offset 12 into destination object 'a2' of size 8" }
+
+void warn3 (void)
+{
+ warn2 (a2 + 1);
+}
+
+
+static void ignore0 (int *p)
+{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
+ memset (p, __LINE__, 3);
+#pragma GCC diagnostic pop
+}
+
+static void nowarn1_ignore0 (int *p)
+{
+ ignore0 (p + 1);
+}
+
+static void nowarn2_ignore0 (int *p)
+{
+ nowarn1_ignore0 (p + 1);
+}
+
+int b2[2];
+
+void nowarn3_ignore0 (void)
+{
+ nowarn2_ignore0 (b2 + 1);
+}
+
+
+static void nowarn0_ignore1 (int *p)
+{
+ memset (p, __LINE__, 3);
+}
+
+static void ignore1 (int *p)
+{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
+ nowarn0_ignore1 (p + 1);
+#pragma GCC diagnostic pop
+}
+
+void nowarn2_ignore1 (int *p)
+{
+ ignore1 (p + 1);
+}
+
+int c2[2];
+
+void nowarn3_ignore1 (void)
+{
+ nowarn2_ignore1 (c2 + 1);
+}
+
+
+static void nowarn0_ignore2 (int *p)
+{
+ memset (p, __LINE__, 3);
+}
+
+static void nowarn1_ignore2 (int *p)
+{
+ nowarn0_ignore2 (p + 1);
+}
+
+static void ignore2 (int *p)
+{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
+ nowarn1_ignore2 (p + 1);
+#pragma GCC diagnostic pop
+}
+
+int d2[2];
+
+void nowarn3_ignore2 (void)
+{
+ ignore2 (c2 + 1);
+}
+
+
+
+static void nowarn0_ignore3 (int *p)
+{
+ memset (p, __LINE__, 3);
+}
+
+static void nowarn1_ignore3 (int *p)
+{
+ nowarn0_ignore3 (p + 1);
+}
+
+static void nowarn2_ignore3 (int *p)
+{
+ nowarn1_ignore3 (p + 1);
+}
+
+int e2[2];
+
+void ignore3 (void)
+{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-overflow"
+ nowarn2_ignore3 (e2 + 1);
+#pragma GCC diagnostic pop
+}
diff --git a/gcc/testsuite/gcc.dg/uninit-suppress_3.c b/gcc/testsuite/gcc.dg/uninit-suppress_3.c
new file mode 100644
index 00000000000..7bbe9edc605
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/uninit-suppress_3.c
@@ -0,0 +1,98 @@
+/* PR middle-end/98871 - Cannot silence -Wmaybe-uninitialized at declaration
+ site
+ { dg-do compile }
+ { dg-options "-O1 -Wall" } */
+
+struct A
+{
+ int x;
+};
+
+// Verify that suppression works at every inlining level.
+
+static int f0 (int *x)
+{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+
+ return ++*x;
+
+#pragma GCC diagnostic pop
+}
+
+static int f1 (int *p, int n)
+{
+ struct A a;
+ for (int i = 0; i < n; ++i) {
+ if (p[i] > 1) {
+ a = (struct A){p[i]};
+ }
+ }
+
+ return f0 (&a.x);
+}
+
+int f2 (void)
+{
+ int a[] = { 1, 2, 3, 4 };
+ return f1 (a, 4);
+}
+
+
+static int g0 (int *x)
+{
+ return ++*x;
+}
+
+static int g1 (int *p, int n)
+{
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+
+ struct A a;
+ for (int i = 0; i < n; ++i) {
+ if (p[i] > 1) {
+ a = (struct A){p[i]};
+ }
+ }
+
+ return g0 (&a.x);
+
+#pragma GCC diagnostic pop
+}
+
+int g2 (void)
+{
+ int a[] = { 1, 2, 3, 4, 5 };
+ return g1 (a, 5);
+}
+
+
+static int h0 (int *x)
+{
+ return ++*x;
+}
+
+static int h1 (int *p, int n)
+{
+ struct A a;
+ for (int i = 0; i < n; ++i) {
+ if (p[i] > 1) {
+ a = (struct A){p[i]};
+ }
+ }
+
+ return h0 (&a.x);
+}
+
+int h2 (void)
+{
+ int a[] = { 1, 2, 3, 4, 5, 6 };
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+
+ return h1 (a, 6);
+
+#pragma GCC diagnostic pop
+}
diff --git a/gcc/trans-mem.c b/gcc/trans-mem.c
index e74bd1f5ec0..c270d039b15 100644
--- a/gcc/trans-mem.c
+++ b/gcc/trans-mem.c
@@ -4413,12 +4413,8 @@ ipa_tm_scan_irr_block (basic_block bb)
is to wrap it in a __tm_waiver block. This is not
yet implemented, so we can't check for it. */
if (is_tm_safe (current_function_decl))
- {
- tree t = build1 (NOP_EXPR, void_type_node, size_zero_node);
- SET_EXPR_LOCATION (t, gimple_location (stmt));
- error ("%K%<asm%> not allowed in %<transaction_safe%> function",
- t);
- }
+ error_at (gimple_location (stmt),
+ "%<asm%> not allowed in %<transaction_safe%> function");
return true;
default:
diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c
index 42585412325..9ce6214d7e2 100644
--- a/gcc/tree-ssa-ccp.c
+++ b/gcc/tree-ssa-ccp.c
@@ -3563,7 +3563,7 @@ pass_post_ipa_warn::execute (function *fun)
if (argno == 0)
{
if (warning_at (loc, OPT_Wnonnull,
- "%G%qs pointer is null", stmt, "this")
+ "%qs pointer is null", "this")
&& fndecl)
inform (DECL_SOURCE_LOCATION (fndecl),
"in a call to non-static member function %qD",
@@ -3572,8 +3572,8 @@ pass_post_ipa_warn::execute (function *fun)
}
if (!warning_at (loc, OPT_Wnonnull,
- "%Gargument %u null where non-null "
- "expected", stmt, argno))
+ "argument %u null where non-null "
+ "expected", argno))
continue;
tree fndecl = gimple_call_fndecl (stmt);
diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c
index 13ea107da17..94257df1067 100644
--- a/gcc/tree-ssa-strlen.c
+++ b/gcc/tree-ssa-strlen.c
@@ -2022,13 +2022,12 @@ maybe_warn_overflow (gimple *stmt, tree len, pointer_query &ptr_qry,
warned = (writefn
? warning_at (loc, OPT_Wstringop_overflow_,
- "%G%qD writing one too many bytes into a region "
+ "%qD writing one too many bytes into a region "
"of a size that depends on %<strlen%>",
- stmt, writefn)
+ writefn)
: warning_at (loc, OPT_Wstringop_overflow_,
- "%Gwriting one too many bytes into a region "
- "of a size that depends on %<strlen%>",
- stmt));
+ "writing one too many bytes into a region "
+ "of a size that depends on %<strlen%>"));
}
else if (lenrng[0] == lenrng[1])
{
@@ -2036,65 +2035,65 @@ maybe_warn_overflow (gimple *stmt, tree len, pointer_query &ptr_qry,
warned = (writefn
? warning_n (loc, OPT_Wstringop_overflow_,
lenrng[0].to_uhwi (),
- "%G%qD writing %wu byte into a region "
+ "%qD writing %wu byte into a region "
"of size %wu",
- "%G%qD writing %wu bytes into a region "
+ "%qD writing %wu bytes into a region "
"of size %wu",
- stmt, writefn, lenrng[0].to_uhwi (),
+ writefn, lenrng[0].to_uhwi (),
spcrng[0].to_uhwi ())
: warning_n (loc, OPT_Wstringop_overflow_,
lenrng[0].to_uhwi (),
- "%Gwriting %wu byte into a region "
+ "writing %wu byte into a region "
"of size %wu",
- "%Gwriting %wu bytes into a region "
+ "writing %wu bytes into a region "
"of size %wu",
- stmt, lenrng[0].to_uhwi (),
+ lenrng[0].to_uhwi (),
spcrng[0].to_uhwi ()));
else
warned = (writefn
? warning_n (loc, OPT_Wstringop_overflow_,
lenrng[0].to_uhwi (),
- "%G%qD writing %wu byte into a region "
+ "%qD writing %wu byte into a region "
"of size between %wu and %wu",
- "%G%qD writing %wu bytes into a region "
+ "%qD writing %wu bytes into a region "
"of size between %wu and %wu",
- stmt, writefn, lenrng[0].to_uhwi (),
+ writefn, lenrng[0].to_uhwi (),
spcrng[0].to_uhwi (), spcrng[1].to_uhwi ())
: warning_n (loc, OPT_Wstringop_overflow_,
lenrng[0].to_uhwi (),
- "%Gwriting %wu byte into a region "
+ "writing %wu byte into a region "
"of size between %wu and %wu",
- "%Gwriting %wu bytes into a region "
+ "writing %wu bytes into a region "
"of size between %wu and %wu",
- stmt, lenrng[0].to_uhwi (),
+ lenrng[0].to_uhwi (),
spcrng[0].to_uhwi (), spcrng[1].to_uhwi ()));
}
else if (spcrng[0] == spcrng[1])
warned = (writefn
? warning_at (loc, OPT_Wstringop_overflow_,
- "%G%qD writing between %wu and %wu bytes "
+ "%qD writing between %wu and %wu bytes "
"into a region of size %wu",
- stmt, writefn, lenrng[0].to_uhwi (),
+ writefn, lenrng[0].to_uhwi (),
lenrng[1].to_uhwi (),
spcrng[0].to_uhwi ())
: warning_at (loc, OPT_Wstringop_overflow_,
- "%Gwriting between %wu and %wu bytes "
+ "writing between %wu and %wu bytes "
"into a region of size %wu",
- stmt, lenrng[0].to_uhwi (),
+ lenrng[0].to_uhwi (),
lenrng[1].to_uhwi (),
spcrng[0].to_uhwi ()));
else
warned = (writefn
? warning_at (loc, OPT_Wstringop_overflow_,
- "%G%qD writing between %wu and %wu bytes "
+ "%qD writing between %wu and %wu bytes "
"into a region of size between %wu and %wu",
- stmt, writefn, lenrng[0].to_uhwi (),
+ writefn, lenrng[0].to_uhwi (),
lenrng[1].to_uhwi (),
spcrng[0].to_uhwi (), spcrng[1].to_uhwi ())
: warning_at (loc, OPT_Wstringop_overflow_,
- "%Gwriting between %wu and %wu bytes "
+ "writing between %wu and %wu bytes "
"into a region of size between %wu and %wu",
- stmt, lenrng[0].to_uhwi (),
+ lenrng[0].to_uhwi (),
lenrng[1].to_uhwi (),
spcrng[0].to_uhwi (), spcrng[1].to_uhwi ()));
@@ -2985,13 +2984,13 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt,
if (lenrange[0] == cntrange[1] && cntrange[0] == cntrange[1])
return warning_n (callloc, OPT_Wstringop_truncation,
cntrange[0].to_uhwi (),
- "%G%qD output truncated before terminating "
+ "%qD output truncated before terminating "
"nul copying %E byte from a string of the "
"same length",
- "%G%qD output truncated before terminating nul "
+ "%qD output truncated before terminating nul "
"copying %E bytes from a string of the same "
"length",
- stmt, func, cnt);
+ func, cnt);
else if (!cat_dstlen_bounded)
{
if (wi::geu_p (lenrange[0], cntrange[1]))
@@ -3001,16 +3000,16 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt,
if (cntrange[0] == cntrange[1])
return warning_n (callloc, OPT_Wstringop_truncation,
cntrange[0].to_uhwi (),
- "%G%qD output truncated copying %E byte "
+ "%qD output truncated copying %E byte "
"from a string of length %wu",
- "%G%qD output truncated copying %E bytes "
+ "%qD output truncated copying %E bytes "
"from a string of length %wu",
- stmt, func, cnt, lenrange[0].to_uhwi ());
+ func, cnt, lenrange[0].to_uhwi ());
return warning_at (callloc, OPT_Wstringop_truncation,
- "%G%qD output truncated copying between %wu "
+ "%qD output truncated copying between %wu "
"and %wu bytes from a string of length %wu",
- stmt, func, cntrange[0].to_uhwi (),
+ func, cntrange[0].to_uhwi (),
cntrange[1].to_uhwi (), lenrange[0].to_uhwi ());
}
else if (wi::geu_p (lenrange[1], cntrange[1]))
@@ -3020,16 +3019,16 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt,
if (cntrange[0] == cntrange[1])
return warning_n (callloc, OPT_Wstringop_truncation,
cntrange[0].to_uhwi (),
- "%G%qD output may be truncated copying %E "
+ "%qD output may be truncated copying %E "
"byte from a string of length %wu",
- "%G%qD output may be truncated copying %E "
+ "%qD output may be truncated copying %E "
"bytes from a string of length %wu",
- stmt, func, cnt, lenrange[1].to_uhwi ());
+ func, cnt, lenrange[1].to_uhwi ());
return warning_at (callloc, OPT_Wstringop_truncation,
- "%G%qD output may be truncated copying between "
+ "%qD output may be truncated copying between "
"%wu and %wu bytes from a string of length %wu",
- stmt, func, cntrange[0].to_uhwi (),
+ func, cntrange[0].to_uhwi (),
cntrange[1].to_uhwi (), lenrange[1].to_uhwi ());
}
}
@@ -3043,9 +3042,9 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt,
the lower bound of the specified count but shorter than the
upper bound the copy may (but need not) be truncated. */
return warning_at (callloc, OPT_Wstringop_truncation,
- "%G%qD output may be truncated copying between "
+ "%qD output may be truncated copying between "
"%wu and %wu bytes from a string of length %wu",
- stmt, func, cntrange[0].to_uhwi (),
+ func, cntrange[0].to_uhwi (),
cntrange[1].to_uhwi (), lenrange[0].to_uhwi ());
}
}
@@ -3072,8 +3071,8 @@ maybe_diag_stxncpy_trunc (gimple_stmt_iterator gsi, tree src, tree cnt,
if (cntrange[0] == cntrange[1])
return warning_at (callloc, OPT_Wstringop_truncation,
- "%G%qD specified bound %E equals destination size",
- stmt, func, cnt);
+ "%qD specified bound %E equals destination size",
+ func, cnt);
}
return false;
@@ -3197,9 +3196,9 @@ handle_builtin_stxncpy_strncat (bool append_p, gimple_stmt_iterator *gsi)
&& sisrc == silen
&& is_strlen_related_p (src, len)
&& warning_at (callloc, OPT_Wstringop_truncation,
- "%G%qD output truncated before terminating nul "
+ "%qD output truncated before terminating nul "
"copying as many bytes from a string as its length",
- stmt, func))
+ func))
warned = true;
else if ((append_p || !dstsize || len == dstlenp1)
&& silen && is_strlen_related_p (src, silen->ptr))
@@ -3210,9 +3209,9 @@ handle_builtin_stxncpy_strncat (bool append_p, gimple_stmt_iterator *gsi)
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 "
+ "%qD specified bound depends on the length "
"of the source argument",
- stmt, func);
+ func);
}
if (warned)
{
@@ -4141,24 +4140,24 @@ maybe_warn_pointless_strcmp (gimple *stmt, HOST_WIDE_INT bound,
if (siz <= minlen && bound == -1)
warned = warning_at (stmt_loc, OPT_Wstring_compare,
(at_least
- ? G_("%G%qD of a string of length %wu or more and "
+ ? G_("%qD of a string of length %wu or more and "
"an array of size %wu evaluates to nonzero")
- : G_("%G%qD of a string of length %wu and an array "
+ : G_("%qD of a string of length %wu and an array "
"of size %wu evaluates to nonzero")),
- stmt, callee, minlen, siz);
+ callee, minlen, siz);
else if (!at_least && siz <= HOST_WIDE_INT_MAX)
{
if (len[0] != HOST_WIDE_INT_MAX && len[1] != HOST_WIDE_INT_MAX)
warned = warning_at (stmt_loc, OPT_Wstring_compare,
- "%G%qD of strings of length %wu and %wu "
+ "%qD of strings of length %wu and %wu "
"and bound of %wu evaluates to nonzero",
- stmt, callee, len[0], len[1], bound);
+ callee, len[0], len[1], bound);
else
warned = warning_at (stmt_loc, OPT_Wstring_compare,
- "%G%qD of a string of length %wu, an array "
+ "%qD of a string of length %wu, an array "
"of size %wu and bound of %wu evaluates to "
"nonzero",
- stmt, callee, minlen, siz, bound);
+ callee, minlen, siz, bound);
}
if (!warned)
diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c
index 99442d7f975..24ac031a693 100644
--- a/gcc/tree-ssa-uninit.c
+++ b/gcc/tree-ssa-uninit.c
@@ -444,7 +444,7 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs, tree rhs,
if (wlims.always_executed)
{
if (warning_at (location, OPT_Wuninitialized,
- "%G%qE is used uninitialized", stmt, rhs))
+ "%qE is used uninitialized", rhs))
{
/* ??? This is only effective for decls as in
gcc.dg/uninit-B-O0.c. Avoid doing this for maybe-uninit
@@ -457,7 +457,7 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs, tree rhs,
}
else if (wlims.wmaybe_uninit)
warned = warning_at (location, OPT_Wmaybe_uninitialized,
- "%G%qE may be used uninitialized", stmt, rhs);
+ "%qE may be used uninitialized", rhs);
return warned ? base : NULL_TREE;
}